diff --git a/src/main/java/magicbees/tileentity/TileEntityEffectJar.java b/src/main/java/magicbees/tileentity/TileEntityEffectJar.java index 0eb7c1a..041a3ac 100644 --- a/src/main/java/magicbees/tileentity/TileEntityEffectJar.java +++ b/src/main/java/magicbees/tileentity/TileEntityEffectJar.java @@ -14,12 +14,10 @@ import forestry.api.apiculture.IBee; import forestry.api.genetics.IEffectData; -public class TileEntityEffectJar extends TileEntity implements IInventory -{ +public class TileEntityEffectJar extends TileEntity implements IInventory { public static final String tileEntityName = CommonProxy.DOMAIN + ".effectJar"; private GameProfile ownerName; - private EffectJarHousing housingLogic; private static final int SLOT_COUNT = 2; public static final int DRONE_SLOT = 0; @@ -32,120 +30,123 @@ public class TileEntityEffectJar extends TileEntity implements IInventory public int currentBeeHealth; public int currentBeeColour; - public TileEntityEffectJar() - { + public TileEntityEffectJar() { super(); this.beeSlots = new ItemStack[SLOT_COUNT]; } - public void setOwner(EntityPlayer player) - { + public void setOwner(EntityPlayer player) { this.ownerName = player.getGameProfile(); } @Override - public boolean shouldRenderInPass(int pass) - { + public boolean shouldRenderInPass(int pass) { return pass == 1; } - public GameProfile getOwner() - { + public GameProfile getOwner() { return this.ownerName; } @Override - public int getSizeInventory() - { + public int getSizeInventory() { // Last slot reserved for "queen" return this.beeSlots.length - 1; } @Override - public ItemStack getStackInSlot(int slot) - { + public ItemStack getStackInSlot(int slot) { return beeSlots[slot]; } @Override - public void updateEntity() - { - if (this.beeSlots[QUEEN_SLOT] != null) - { - IBee queen = magicbees.bees.BeeManager.beeRoot.getMember(this.beeSlots[QUEEN_SLOT]); - - currentBeeHealth = (queen.getHealth() * 100) / queen.getMaxHealth(); - currentBeeColour = ((IAlleleBeeSpecies)queen.getGenome().getPrimary()).getIconColour(0); - - EffectJarHousing housingLogic = EffectJarHousing.getFor(this); - this.effectData = queen.doEffect(this.effectData, housingLogic); - if (this.worldObj.getWorldTime() % 5 == 0) - { - this.effectData = queen.doFX(this.effectData, housingLogic); - } - - // run the queen - if (throttle > 550) - { - throttle = 0; - queen.age(this.worldObj, 0.26f); - - if (queen.getHealth() == 0) - { - this.beeSlots[QUEEN_SLOT] = null; - currentBeeHealth = 0; - currentBeeColour = 0x0ffffff; - } - else - { - queen.writeToNBT(this.beeSlots[QUEEN_SLOT].stackTagCompound); - } - this.markDirty(); - } - else - { - throttle++; - } + public void updateEntity() { + if (hasQueen()) { + tickQueen(); } - else if (this.beeSlots[DRONE_SLOT] != null) - { - // make a queen - ItemStack droneStack = this.beeSlots[DRONE_SLOT]; - if (magicbees.bees.BeeManager.beeRoot.isDrone(droneStack)) - { - IBee bee = magicbees.bees.BeeManager.beeRoot.getMember(droneStack); - if (droneStack.stackSize == 1) - { - this.beeSlots[DRONE_SLOT] = null; - } - else - { - droneStack.stackSize--; - } - - this.beeSlots[QUEEN_SLOT] = droneStack.copy(); - this.beeSlots[QUEEN_SLOT].stackSize = 1; - - int current = bee.getHealth(); - int max = bee.getMaxHealth(); - currentBeeHealth = (current * 100) / max; - currentBeeColour = ((IAlleleBeeSpecies)bee.getGenome().getPrimary()).getIconColour(0); - } - this.markDirty(); + else if (hasDrone()) { + createQueenFromDrone(); } } - @Override - public ItemStack decrStackSize(int slot, int count) - { - ItemStack value = null; - if (this.beeSlots[slot] != null) + private void createQueenFromDrone() { + ItemStack droneStack = this.beeSlots[DRONE_SLOT]; + if (magicbees.bees.BeeManager.beeRoot.isDrone(droneStack)) { + IBee bee = magicbees.bees.BeeManager.beeRoot.getMember(droneStack); + if (droneStack.stackSize == 1) + { + this.beeSlots[DRONE_SLOT] = null; + } + else + { + droneStack.stackSize--; + } + + this.beeSlots[QUEEN_SLOT] = droneStack.copy(); + this.beeSlots[QUEEN_SLOT].stackSize = 1; + + int current = bee.getHealth(); + int max = bee.getMaxHealth(); + currentBeeHealth = (current * 100) / max; + currentBeeColour = ((IAlleleBeeSpecies)bee.getGenome().getPrimary()).getIconColour(0); + } + this.markDirty(); + } + + private boolean hasDrone() { + return this.beeSlots[DRONE_SLOT] != null; + } + + private void tickQueen() { + IBee queen = magicbees.bees.BeeManager.beeRoot.getMember(this.beeSlots[QUEEN_SLOT]); + + currentBeeHealth = (queen.getHealth() * 100) / queen.getMaxHealth(); + currentBeeColour = ((IAlleleBeeSpecies)queen.getGenome().getPrimary()).getIconColour(0); + + EffectJarHousing housingLogic = EffectJarHousing.getFor(this); + this.effectData = queen.doEffect(this.effectData, housingLogic); + if (this.worldObj.getWorldTime() % 5 == 0) + { + this.effectData = queen.doFX(this.effectData, housingLogic); + } + + // run the queen + if (throttle > 550) + { + throttle = 0; + queen.age(this.worldObj, 0.26f); + + if (queen.getHealth() == 0) + { + this.beeSlots[QUEEN_SLOT] = null; + currentBeeHealth = 0; + currentBeeColour = 0x0ffffff; + } + else + { + queen.writeToNBT(this.beeSlots[QUEEN_SLOT].stackTagCompound); + } + this.markDirty(); + } + else + { + throttle++; + } + } + + private boolean hasQueen() { + return this.beeSlots[QUEEN_SLOT] != null; + } + + @Override + public ItemStack decrStackSize(int slot, int count) { + ItemStack value = null; + if (this.beeSlots[slot] != null) { value = this.beeSlots[slot].copy(); value.stackSize = Math.min(count, this.beeSlots[slot].stackSize); this.beeSlots[slot].stackSize -= value.stackSize; - if (this.beeSlots[slot].stackSize == 0) - { + if (this.beeSlots[slot].stackSize == 0) { this.beeSlots[slot] = null; } } @@ -154,11 +155,9 @@ public class TileEntityEffectJar extends TileEntity implements IInventory } @Override - public ItemStack getStackInSlotOnClosing(int slot) - { + public ItemStack getStackInSlotOnClosing(int slot) { ItemStack value = null; - if (this.beeSlots[slot] != null) - { + if (this.beeSlots[slot] != null) { value = this.beeSlots[slot]; this.beeSlots[slot] = null; } @@ -167,20 +166,17 @@ public class TileEntityEffectJar extends TileEntity implements IInventory } @Override - public void readFromNBT(NBTTagCompound tagRoot) - { + public void readFromNBT(NBTTagCompound tagRoot) { super.readFromNBT(tagRoot); NBTTagList nbttaglist = tagRoot.getTagList("Items", Constants.NBT.TAG_COMPOUND); this.beeSlots = new ItemStack[SLOT_COUNT]; - for (int i = 0; i < nbttaglist.tagCount(); ++i) - { + for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte b0 = nbttagcompound1.getByte("Slot"); - if (b0 >= 0 && b0 < this.beeSlots.length) - { + if (b0 >= 0 && b0 < this.beeSlots.length) { this.beeSlots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } @@ -189,15 +185,12 @@ public class TileEntityEffectJar extends TileEntity implements IInventory } @Override - public void writeToNBT(NBTTagCompound tagRoot) - { + public void writeToNBT(NBTTagCompound tagRoot) { super.writeToNBT(tagRoot); NBTTagList inventory = new NBTTagList(); - for (int i = 0; i < this.beeSlots.length; ++i) - { - if (this.beeSlots[i] != null) - { + for (int i = 0; i < this.beeSlots.length; ++i) { + if (this.beeSlots[i] != null) { NBTTagCompound itemTag = new NBTTagCompound(); itemTag.setByte("Slot", (byte)i); this.beeSlots[i].writeToNBT(itemTag); @@ -210,11 +203,9 @@ public class TileEntityEffectJar extends TileEntity implements IInventory } @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { + public void setInventorySlotContents(int slot, ItemStack itemStack) { this.beeSlots[slot] = itemStack; - if (this.beeSlots[slot] != null) - { + if (this.beeSlots[slot] != null) { this.beeSlots[slot].stackSize = Math.min(this.beeSlots[slot].stackSize, this.beeSlots[slot].getItem().getItemStackLimit(this.beeSlots[slot])); } @@ -222,42 +213,35 @@ public class TileEntityEffectJar extends TileEntity implements IInventory } @Override - public String getInventoryName() - { + public String getInventoryName() { return "container.effectJar"; } @Override - public boolean hasCustomInventoryName() - { + public boolean hasCustomInventoryName() { return false; } @Override - public int getInventoryStackLimit() - { + public int getInventoryStackLimit() { return 64; } @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { + public boolean isUseableByPlayer(EntityPlayer entityplayer) { return true; } @Override - public boolean isItemValidForSlot(int i, ItemStack itemStack) - { + public boolean isItemValidForSlot(int i, ItemStack itemStack) { return true; } @Override - public void openInventory() - { + public void openInventory() { } @Override - public void closeInventory() - { + public void closeInventory() { } }