Files
MagicBees/src/main/java/magicbees/tileentity/TileEntityPhialingCabinet.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

245 lines
7.6 KiB
Java
Raw Normal View History

2023-12-08 11:36:56 +01:00
package magicbees.tileentity;
2023-12-08 23:15:21 +01:00
import java.util.Objects;
2023-12-08 11:36:56 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.api.apiculture.IBee;
2023-12-08 23:15:21 +01:00
import forestry.api.apiculture.IBeeHousing;
2023-12-08 11:36:56 +01:00
import magicbees.bees.BeeManager;
2023-12-08 23:15:21 +01:00
import magicbees.bees.BeeSpecies;
2023-12-08 23:23:30 +01:00
import magicbees.main.Config;
2023-12-08 11:36:56 +01:00
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IAspectContainer;
import thaumcraft.api.aspects.IEssentiaTransport;
public class TileEntityPhialingCabinet extends TileEntity implements IAspectContainer, IEssentiaTransport {
public static final String tileEntityName = "Phialing Cabinet";
// added directly from the crucible of souls
public AspectList myAspects = new AspectList();
public Aspect aspect;
public int amount = 0;
2023-12-08 23:31:35 +01:00
public int maxAmount = Config.thaumcraftEssentiaBeePhialingCabinetCapacity;
private int increment = 0;
2023-12-08 11:36:56 +01:00
@Override
public void updateEntity() {
// If there's no stored aspect we shouldn't even check for the above block.
if (aspect == null) return;
2023-12-08 23:22:19 +01:00
if (increment % Config.thaumcraftEssentiaBeePhialingCabinetTimeBetween == 0) {
2023-12-08 11:36:56 +01:00
try {
TileEntity above = worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
2023-12-08 15:09:44 +01:00
if (IBeeHousing.class.isAssignableFrom(above.getClass())) {
IBeeHousing heeHousing = (IBeeHousing) above;
ItemStack queenStack = heeHousing.getBeeInventory().getQueen();
2023-12-08 11:36:56 +01:00
// If the bee isn't a queen then what are we even doing?
if (!BeeManager.beeRoot.isMated(queenStack)) return;
IBee queen = BeeManager.beeRoot.getMember(queenStack);
String queenUID = queen.getGenome().getPrimary().getUID();
2023-12-08 23:22:19 +01:00
if (Objects.equals(queenUID, BeeSpecies.TC_ESSENTIA.getSpecies().getUID())) {
2023-12-08 23:31:35 +01:00
addToContainer(aspect, Config.thaumcraftEssentiaBeePhialingCabinetAmount);
2023-12-08 23:22:19 +01:00
increment = 0;
}
2023-12-08 11:36:56 +01:00
}
} catch (Exception ignored) {}
}
2023-12-08 23:22:19 +01:00
2023-12-08 11:36:56 +01:00
increment++;
}
// added directly from the crucible of souls
@Override
public AspectList getAspects() {
// TODO Auto-generated method stub
return this.myAspects;
}
// added directly from the crucible of souls
@Override
public void setAspects(AspectList aspects) {
this.myAspects = aspects;
}
// added directly from the crucible of souls
@Override
public boolean doesContainerAccept(Aspect tag) {
return false;
}
// added directly from the crucible of souls
@Override
public int addToContainer(Aspect tag, int am) {
2023-12-08 23:31:35 +01:00
if (am != 0) {
2023-12-08 11:36:56 +01:00
if (this.amount < this.maxAmount && tag == this.aspect || this.amount == 0) {
this.aspect = tag;
int added = Math.min(am, this.maxAmount - this.amount);
this.amount += added;
am -= added;
}
}
2023-12-08 23:31:35 +01:00
return am;
2023-12-08 11:36:56 +01:00
}
// added directly from the crucible of souls
@Override
public boolean takeFromContainer(Aspect tag, int amount) {
if (!this.worldObj.isRemote) {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
if (this.myAspects.getAmount(tag) >= amount) {
this.myAspects.reduce(tag, amount);
return true;
} else {
return false;
}
}
// added directly from the crucible of souls
@Override
public boolean takeFromContainer(AspectList ot) {
// TODO Auto-generated method stub
boolean hasIt = true;
if (!this.worldObj.isRemote) {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
for (Aspect next : ot.aspects.keySet()) {
if (this.myAspects.getAmount(next) < ot.getAmount(next)) hasIt = false;
}
if (hasIt) {
for (Aspect next : ot.aspects.keySet()) {
myAspects.reduce(next, ot.getAmount(next));
}
return true;
} else {
return false;
}
}
// added directly from the crucible of souls
@Override
public boolean doesContainerContainAmount(Aspect tag, int amount) {
// TODO Auto-generated method stub
return (this.myAspects.getAmount(tag) > amount);
}
// added directly from the crucible of souls
@Override
public boolean doesContainerContain(AspectList ot) {
boolean hasIt = true;
for (Aspect next : ot.aspects.keySet()) {
if (this.myAspects.getAmount(next) < ot.getAmount(next)) hasIt = false;
}
return hasIt;
}
// added directly from the crucible of souls
@Override
public int containerContains(Aspect tag) {
return this.myAspects.getAmount(tag);
}
// added directly from the crucible of souls
@Override
public boolean isConnectable(ForgeDirection face) {
return (face != ForgeDirection.UP);
}
// added directly from the crucible of souls
@Override
public boolean canInputFrom(ForgeDirection face) {
return false;
}
// added directly from the crucible of souls
@Override
public boolean canOutputTo(ForgeDirection face) {
return (face != ForgeDirection.UP);
}
// added directly from the crucible of souls
@Override
public void setSuction(Aspect aspect, int amount) {
// TODO Auto-generated method stub
}
// added directly from the crucible of souls
@Override
2023-12-08 23:31:35 +01:00
public int takeEssentia(Aspect aspect, int amount, ForgeDirection face) {
if (face != ForgeDirection.UP) {
2023-12-08 11:36:56 +01:00
if (!this.worldObj.isRemote) {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
if (amount > this.myAspects.getAmount(aspect)) {
int total = this.myAspects.getAmount(aspect);
this.myAspects.reduce(aspect, total);
return total;
} else {
this.myAspects.reduce(aspect, amount);
return amount;
}
} else {
return 0;
}
}
// added directly from the crucible of souls
@Override
public int getMinimumSuction() {
// TODO Auto-generated method stub
return 0;
}
// added directly from the crucible of souls
@Override
public boolean renderExtendedTube() {
// TODO Auto-generated method stub
return false;
// NEW AFTER THIS LINE
}
// added directly from the crucible of souls
@Override
public Aspect getSuctionType(ForgeDirection face) {
return null;
}
// added directly from the crucible of souls
@Override
public int getSuctionAmount(ForgeDirection face) {
return 0;
}
// added directly from the crucible of souls
@Override
public Aspect getEssentiaType(ForgeDirection face) {
return this.myAspects.size() > 0
? this.myAspects.getAspects()[this.worldObj.rand.nextInt(this.myAspects.getAspects().length)]
: null;
}
// added directly from the crucible of souls
@Override
public int getEssentiaAmount(ForgeDirection face) {
return this.myAspects.visSize();
}
// added directly from the crucible of souls
@Override
2023-12-08 23:31:35 +01:00
public int addEssentia(Aspect aspect, int amount, ForgeDirection arg2) {
2023-12-08 11:36:56 +01:00
// TODO Auto-generated method stub
return 0;
}
}