diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index 911c5ee3d..585a64ab3 100755 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -36,6 +36,7 @@ public class BeekeepingLogic implements IBeekeepingLogic { private static final int MAX_POLLINATION_ATTEMPTS = 20; private static final int totalBreedingTime = Defaults.APIARY_BREEDING_TIME; + private static final int ticksPerCheckCanWork = 10; private final IBeeHousing housing; private final boolean housingSupportsMultipleErrorStates; @@ -50,8 +51,10 @@ public class BeekeepingLogic implements IBeekeepingLogic { private final Stack spawn = new Stack(); // Cached flowers check - private Boolean hasFlowersCached = false; + private boolean hasFlowersCached = false; private int hasFlowersCooldown = 0; + private boolean canWorkCached = false; + private int canWorkCooldown = 0; public BeekeepingLogic(IBeeHousing housing) { this.housing = housing; @@ -125,6 +128,16 @@ public class BeekeepingLogic implements IBeekeepingLogic { @Override public boolean canWork() { + if (canWorkCooldown > 0) { + canWorkCooldown--; + } else { + canWorkCached = checkCanWork(); + canWorkCooldown = ticksPerCheckCanWork; + } + return canWorkCached; + } + + private boolean checkCanWork() { if (housingSupportsMultipleErrorStates) { Set errorStates = housing.getErrorStates(); for (IErrorState errorState : errorStates) { @@ -132,8 +145,6 @@ public class BeekeepingLogic implements IBeekeepingLogic { } } - this.queen = null; - boolean hasSpace = addPendingProducts(); if (hasBreedablePrincess()) { @@ -168,7 +179,12 @@ public class BeekeepingLogic implements IBeekeepingLogic { private Boolean hasFlowers() { if (hasFlowersCooldown <= 0) { hasFlowersCached = queen.hasFlower(housing); - hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle; + hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle / ticksPerCheckCanWork; + + // check more often if we haven't found flowers + if (!hasFlowersCached) { + hasFlowersCooldown /= 2; + } } else { hasFlowersCooldown--; } @@ -268,24 +284,29 @@ public class BeekeepingLogic implements IBeekeepingLogic { return housingErrorState != EnumErrorCode.NOSPACE; } - + + /** Checks if a queen is alive. Much faster than reading the whole bee nbt */ + private static boolean isQueenAlive(ItemStack queenStack) { + NBTTagCompound nbtTagCompound = queenStack.getTagCompound(); + int health = nbtTagCompound.getInteger("Health"); + return health > 0; + } + private boolean hasHealthyQueen() { boolean hasQueen = true; EnumErrorCode housingErrorState = null; - if (housing.getQueen() == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) { + ItemStack queenStack = housing.getQueen(); + + if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) { housingErrorState = EnumErrorCode.NOQUEEN; hasQueen = false; - } else { - IBee queen = BeeManager.beeRoot.getMember(housing.getQueen()); - // Kill dying queens - if (!queen.isAlive()) { - killQueen(queen); - housingErrorState = EnumErrorCode.OK; - hasQueen = false; - } else { - this.queen = queen; - } + queen = null; + } else if (!isQueenAlive(queenStack)) { + killQueen(queen); + housingErrorState = EnumErrorCode.OK; + hasQueen = false; + queen = null; } if (housingSupportsMultipleErrorStates) { @@ -296,6 +317,10 @@ public class BeekeepingLogic implements IBeekeepingLogic { } } + if (hasQueen && queen == null) { + queen = BeeManager.beeRoot.getMember(queenStack); + } + return hasQueen; } diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 66752c08a..b294c33a8 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -59,19 +59,19 @@ public class GuiHandlerApiculture extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AlvearyGUI: - return new GuiAlveary(player.inventory, getTileForestry(world, x, y, z, TileAlvearyPlain.class)); + return new GuiAlveary(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyPlain.class)); case AlvearySieveGUI: - return new GuiAlvearySieve(player.inventory, getTileForestry(world, x, y, z, TileAlvearySieve.class)); + return new GuiAlvearySieve(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySieve.class)); case AlvearySwarmerGUI: - return new GuiAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, TileAlvearySwarmer.class)); + return new GuiAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySwarmer.class)); case ApiaristChestGUI: return getNaturalistChestGui(BeeHelper.UID, player, world, x, y, z, guiData); case ApiaryGUI: - return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, TileApiary.class)); + return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, player, TileApiary.class)); case BeealyzerGUI: equipped = player.getCurrentEquippedItem(); @@ -82,7 +82,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiBeealyzer(player, new BeealyzerInventory(player, equipped)); case BeehouseGUI: - return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, TileBeehouse.class)); + return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, player, TileBeehouse.class)); case HabitatLocatorGUI: equipped = player.getCurrentEquippedItem(); @@ -93,7 +93,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: - return new GuiAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, TileAlvearyHygroregulator.class)); + return new GuiAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyHygroregulator.class)); case ImprinterGUI: equipped = player.getCurrentEquippedItem(); @@ -122,20 +122,20 @@ public class GuiHandlerApiculture extends GuiHandlerBase { case AlvearyGUI: synchApiaristTracker(world, player); - return new ContainerAlveary(player.inventory, getTileForestry(world, x, y, z, TileAlvearyPlain.class)); + return new ContainerAlveary(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyPlain.class)); case AlvearySieveGUI: - return new ContainerAlvearySieve(player.inventory, getTileForestry(world, x, y, z, TileAlvearySieve.class)); + return new ContainerAlvearySieve(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySieve.class)); case AlvearySwarmerGUI: - return new ContainerAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, TileAlvearySwarmer.class)); + return new ContainerAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySwarmer.class)); case ApiaristChestGUI: return getNaturalistChestContainer(BeeHelper.UID, player, world, x, y, z, guiData); case ApiaryGUI: synchApiaristTracker(world, player); - return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, TileApiary.class), true); + return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, player, TileApiary.class), true); case BeealyzerGUI: equipped = player.getCurrentEquippedItem(); @@ -148,7 +148,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { case BeehouseGUI: synchApiaristTracker(world, player); - return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, TileBeehouse.class), false); + return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, player, TileBeehouse.class), false); case HabitatLocatorGUI: equipped = player.getCurrentEquippedItem(); @@ -159,7 +159,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new ContainerHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: - return new ContainerAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, TileAlvearyHygroregulator.class)); + return new ContainerAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyHygroregulator.class)); case ImprinterGUI: synchApiaristTracker(world, player); diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index ab535addc..6e30a1142 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -18,7 +18,6 @@ import java.util.Set; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -72,11 +71,12 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB protected BiomeGenBase biome; protected float tempChange = 0.0f; protected float humidChange = 0.0f; - private int displayHealthMax = 0; - private int displayHealth = 0; // CLIENT private boolean active; + private int displayHealthMax = 0; + private int displayHealth = 0; + private IBee displayQueen; public TileAlvearyPlain() { super(0); @@ -194,33 +194,20 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB @Override protected void updateClientSide() { + if (isMaster() && active && (displayQueen != null) && updateOnInterval(2)) { + displayQueen.doFX(beekeepingLogic.getEffectData(), this); - if (!isMaster()) { - return; - } + if (updateOnInterval(50)) { + float fxX = xCoord + 0.5F; + float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F; + float fxZ = zCoord + 0.5F; + float f3 = 1.6F; + float f4 = worldObj.rand.nextFloat() * f3 - 0.5F; - if (!active) { - return; - } - - if (updateOnInterval(2)) { - ItemStack queenStack = getStackInSlot(SLOT_QUEEN); - if (BeeManager.beeRoot.isMated(queenStack)) { - IBee displayQueen = BeeManager.beeRoot.getMember(queenStack); - displayQueen.doFX(beekeepingLogic.getEffectData(), this); - - if (updateOnInterval(50)) { - float fxX = xCoord + 0.5F; - float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F; - float fxZ = zCoord + 0.5F; - float f3 = 1.6F; - float f4 = worldObj.rand.nextFloat() * f3 - 0.5F; - - Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F); - } + Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F); } } } @@ -249,32 +236,26 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB /* STATE INFORMATION */ private int getHealthDisplay() { - IInventory inventory = getStructureInventory(); - if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) { + if (displayQueen == null) { return 0; } - if (BeeManager.beeRoot.isMated(inventory.getStackInSlot(SLOT_QUEEN))) { - return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth(); - } else if (!BeeManager.beeRoot.isDrone(inventory.getStackInSlot(SLOT_QUEEN))) { - return displayHealth; + if (displayQueen.getMate() != null) { + return displayQueen.getHealth(); } else { - return 0; + return displayHealth; } } private int getMaxHealthDisplay() { - IInventory inventory = getStructureInventory(); - if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) { + if (displayQueen == null) { return 0; } - if (BeeManager.beeRoot.isMated(inventory.getStackInSlot(SLOT_QUEEN))) { - return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth(); - } else if (!BeeManager.beeRoot.isDrone(inventory.getStackInSlot(SLOT_QUEEN))) { - return displayHealthMax; + if (displayQueen.getMate() != null) { + return displayQueen.getMaxHealth(); } else { - return 0; + return displayHealthMax; } } @@ -374,6 +355,30 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB setInventorySlotContents(SLOT_QUEEN, itemstack); } + @Override + public ItemStack decrStackSize(int slotIndex, int amount) { + ItemStack itemStack = super.decrStackSize(slotIndex, amount); + if (isMaster() && slotIndex == SLOT_QUEEN) { + handleQueenChange(); + } + return itemStack; + } + + @Override + public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { + super.setInventorySlotContents(slotIndex, itemStack); + if (isMaster() && slotIndex == SLOT_QUEEN) { + handleQueenChange(); + } + } + + private void handleQueenChange() { + if (!Proxies.common.isSimulating(worldObj)) { + ItemStack itemStack = getStackInSlot(SLOT_QUEEN); + displayQueen = BeeManager.beeRoot.getMember(itemStack); + } + } + @Override public void setDrone(ItemStack itemstack) { setInventorySlotContents(SLOT_DRONE, itemstack); diff --git a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java index 2db5ab86d..7c57b1182 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java @@ -39,17 +39,13 @@ import forestry.api.genetics.IIndividual; import forestry.apiculture.network.PacketActiveUpdate; import forestry.core.EnumErrorCode; import forestry.core.config.Config; -import forestry.core.config.ForestryItem; import forestry.core.gadgets.TileBase; import forestry.core.interfaces.IActivatable; import forestry.core.interfaces.IClimatised; -import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InvTools; import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.network.PacketHelper; -import forestry.core.network.PacketId; -import forestry.core.network.PacketInventoryStack; import forestry.core.proxy.Proxies; import forestry.core.utils.GuiUtil; @@ -61,13 +57,15 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, public static final int SLOT_PRODUCT_COUNT = 7; public static final int SLOT_FRAMES_1 = 9; public static final int SLOT_FRAMES_COUNT = 3; + private final IBeekeepingLogic logic; private BiomeGenBase biome; - private int displayHealthMax = 0; - private int displayHealth = 0; // CLIENT private boolean active; + private int displayHealthMax = 0; + private int displayHealth = 0; + private IBee displayQueen; public TileBeehouse() { setHints(Config.hints.get("apiary")); @@ -98,7 +96,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, int biomeId = nbttagcompound.getInteger("BiomeId"); biome = BiomeGenBase.getBiome(biomeId); logic.readFromNBT(nbttagcompound); - } @Override @@ -181,24 +178,20 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, /* UPDATING */ @Override public void updateClientSide() { - if (isActive() && updateOnInterval(2)) { - ItemStack queenStack = getStackInSlot(SLOT_QUEEN); - if (BeeManager.beeRoot.isMated(queenStack)) { - IBee displayQueen = BeeManager.beeRoot.getMember(queenStack); - displayQueen.doFX(logic.getEffectData(), this); + if (isActive() && (displayQueen != null) && updateOnInterval(4)) { + displayQueen.doFX(logic.getEffectData(), this); - if (updateOnInterval(50)) { - float fxX = xCoord + 0.5F; - float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F; - float fxZ = zCoord + 0.5F; - float f3 = 0.6F; - float f4 = worldObj.rand.nextFloat() * f3 - 0.5F; + if (updateOnInterval(50)) { + float fxX = xCoord + 0.5F; + float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F; + float fxZ = zCoord + 0.5F; + float f3 = 0.6F; + float f4 = worldObj.rand.nextFloat() * f3 - 0.5F; - Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F); - } + Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F); + Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F); } } } @@ -225,42 +218,30 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, /* NETWORK SYNCH */ @Override public void onQueenChange(ItemStack queenStack) { - if (!Proxies.common.isSimulating(worldObj)) { - return; - } - - PacketInventoryStack packet = new PacketInventoryStack(PacketId.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack); - Proxies.net.sendNetworkPacket(packet); } /* STATE INFORMATION */ private int getHealthDisplay() { - IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_QUEEN) == null) { + if (displayQueen == null) { return 0; } - if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) { - return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth(); - } else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) { - return displayHealth; + if (displayQueen.getMate() != null) { + return displayQueen.getHealth(); } else { - return 0; + return displayHealth; } } private int getMaxHealthDisplay() { - IInventoryAdapter inventory = getInternalInventory(); - if (inventory.getStackInSlot(SLOT_QUEEN) == null) { + if (displayQueen == null) { return 0; } - if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) { - return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth(); - } else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) { - return displayHealthMax; + if (displayQueen.getMate() != null) { + return displayQueen.getMaxHealth(); } else { - return 0; + return displayHealthMax; } } @@ -347,6 +328,30 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, setInventorySlotContents(SLOT_QUEEN, itemstack); } + @Override + public ItemStack decrStackSize(int slotIndex, int amount) { + ItemStack itemStack = super.decrStackSize(slotIndex, amount); + if (slotIndex == SLOT_QUEEN) { + handleQueenChange(); + } + return itemStack; + } + + @Override + public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { + super.setInventorySlotContents(slotIndex, itemStack); + if (slotIndex == SLOT_QUEEN) { + handleQueenChange(); + } + } + + private void handleQueenChange() { + if (!Proxies.common.isSimulating(worldObj)) { + ItemStack itemStack = getStackInSlot(SLOT_QUEEN); + displayQueen = BeeManager.beeRoot.getMember(itemStack); + } + } + @Override public void setDrone(ItemStack itemstack) { setInventorySlotContents(SLOT_DRONE, itemstack); diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index 25260f9b7..88fa4e56b 100755 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import com.google.common.collect.ImmutableSet; - import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; @@ -246,7 +245,7 @@ public class Bee extends IndividualLiving implements IBee { World world = housing.getWorld(); BiomeGenBase biome = housing.getBiome(); - ImmutableSet.Builder errorStates = ImmutableSet.builder(); + Set errorStates = new HashSet(); // / Rain needs tolerant flyers if (world.isRaining() && !genome.getTolerantFlyer() && BiomeHelper.canRainOrSnow(biome) && !housing.isSealed()) { @@ -281,7 +280,7 @@ public class Bee extends IndividualLiving implements IBee { errorStates.add(EnumErrorCode.INVALIDBIOME); } - return errorStates.build(); + return errorStates; } @Override diff --git a/src/main/java/forestry/apiculture/genetics/BeeGenome.java b/src/main/java/forestry/apiculture/genetics/BeeGenome.java index b0ab98f36..c4b61e455 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeGenome.java +++ b/src/main/java/forestry/apiculture/genetics/BeeGenome.java @@ -12,19 +12,24 @@ package forestry.apiculture.genetics; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.IAlleleBeeEffect; import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBeeGenome; +import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; +import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleFlowers; import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.ISpeciesRoot; +import forestry.core.genetics.Chromosome; import forestry.core.genetics.Genome; import forestry.core.genetics.alleles.AlleleArea; import forestry.core.genetics.alleles.AlleleBoolean; @@ -72,6 +77,11 @@ public class BeeGenome extends Genome implements IBeeGenome { // NBT RETRIEVAL public static IAlleleBeeSpecies getSpecies(ItemStack itemStack) { + IAlleleSpecies species = getSpeciesDirectly(itemStack); + if (species instanceof IAlleleBeeSpecies) { + return (IAlleleBeeSpecies) species; + } + return (IAlleleBeeSpecies) getActiveAllele(itemStack, EnumBeeChromosome.SPECIES, BeeManager.beeRoot); } diff --git a/src/main/java/forestry/apiculture/genetics/BeeHelper.java b/src/main/java/forestry/apiculture/genetics/BeeHelper.java index 3db802983..43ca7cdd7 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeHelper.java +++ b/src/main/java/forestry/apiculture/genetics/BeeHelper.java @@ -157,8 +157,8 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { return false; } - IBee bee = getMember(stack); - return bee.getMate() != null; + NBTTagCompound nbt = stack.getTagCompound(); + return nbt != null && nbt.hasKey("Mate"); } @Override diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java index bbf4e6a2e..6f35b3a98 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java @@ -23,8 +23,6 @@ public class ContainerAlveary extends ContainerTile { public ContainerAlveary(InventoryPlayer player, TileAlvearyPlain tile) { super(tile, player, 8, 108); - tile.sendNetworkUpdate(); - // Queen/Princess this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyPlain.SLOT_QUEEN, 29, 39)); diff --git a/src/main/java/forestry/apiculture/gui/ContainerApiary.java b/src/main/java/forestry/apiculture/gui/ContainerApiary.java index 8c0cdcb31..637b37293 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerApiary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerApiary.java @@ -23,8 +23,6 @@ public class ContainerApiary extends ContainerTile { public ContainerApiary(InventoryPlayer player, TileBeehouse tile, boolean hasFrames) { super(tile, player, 8, 108); - tile.sendNetworkUpdate(); - // Queen/Princess this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_QUEEN, 29, 39)); diff --git a/src/main/java/forestry/apiculture/items/ItemBeeGE.java b/src/main/java/forestry/apiculture/items/ItemBeeGE.java index 34a73c9b8..152b58843 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeeGE.java +++ b/src/main/java/forestry/apiculture/items/ItemBeeGE.java @@ -150,7 +150,7 @@ public class ItemBeeGE extends ItemGE { @Override public int getColourFromSpecies(IAlleleSpecies species, int renderPass) { - if (species != null && species instanceof IAlleleBeeSpecies) { + if (species instanceof IAlleleBeeSpecies) { return species.getIconColour(renderPass); } else { return 0xffffff; diff --git a/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java b/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java index 9c6cacff4..5fda06750 100755 --- a/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java +++ b/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java @@ -22,9 +22,9 @@ import forestry.apiculture.render.BeeItemRenderer; import forestry.apiculture.render.EntityBeeFX; import forestry.apiculture.render.ParticleRenderer; import forestry.apiculture.render.RenderBee; -import forestry.core.config.Config; import forestry.core.config.ForestryItem; import forestry.core.interfaces.IBlockRenderer; +import forestry.core.proxy.ClientProxyRender; import forestry.core.render.RenderAnalyzer; import forestry.core.render.TextureManager; import forestry.plugins.PluginApiculture; @@ -44,7 +44,7 @@ public class ClientProxyApiculture extends ProxyApiculture { @Override public void addBeeHiveFX(String icon, World world, double xCoord, double yCoord, double zCoord, int color, int areaX, int areaY, int areaZ) { - if (!Config.enableParticleFX) { + if (!ClientProxyRender.shouldSpawnParticle(world)) { return; } @@ -66,7 +66,7 @@ public class ClientProxyApiculture extends ProxyApiculture { @Override public void addBeeSwarmFX(String icon, World world, double xCoord, double yCoord, double zCoord, int color) { - if (!Config.enableParticleFX) { + if (!ClientProxyRender.shouldSpawnParticle(world)) { return; } diff --git a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java index 5201239a5..0ad9f99d2 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java @@ -27,6 +27,7 @@ import forestry.api.arboriculture.IGrowthProvider; import forestry.api.arboriculture.ITreeGenome; import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.ISpeciesRoot; import forestry.core.genetics.Genome; @@ -45,6 +46,11 @@ public class TreeGenome extends Genome implements ITreeGenome { // NBT RETRIEVAL public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) { + IAlleleSpecies species = getSpeciesDirectly(itemStack); + if (species instanceof IAlleleTreeSpecies) { + return (IAlleleTreeSpecies) species; + } + return (IAlleleTreeSpecies) getActiveAllele(itemStack, EnumTreeChromosome.SPECIES, PluginArboriculture.treeInterface); } diff --git a/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java b/src/main/java/forestry/arboriculture/network/PacketHandlerArboriculture.java old mode 100755 new mode 100644 similarity index 94% rename from src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java rename to src/main/java/forestry/arboriculture/network/PacketHandlerArboriculture.java index c0d7b83e8..e96ee0636 --- a/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java +++ b/src/main/java/forestry/arboriculture/network/PacketHandlerArboriculture.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.arboriculture; +package forestry.arboriculture.network; import java.io.DataInputStream; import java.io.IOException; @@ -17,7 +17,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import forestry.arboriculture.gadgets.TileLeaves; -import forestry.arboriculture.network.PacketRipeningUpdate; import forestry.core.network.IPacketHandler; import forestry.core.network.PacketId; import forestry.core.proxy.Proxies; diff --git a/src/main/java/forestry/core/GuiHandler.java b/src/main/java/forestry/core/GuiHandler.java index c901c6d81..9f9a013a5 100755 --- a/src/main/java/forestry/core/GuiHandler.java +++ b/src/main/java/forestry/core/GuiHandler.java @@ -38,10 +38,10 @@ public class GuiHandler extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AnalyzerGUI: - return new GuiAnalyzer(player.inventory, getTileForestry(world, x, y, z, TileAnalyzer.class)); + return new GuiAnalyzer(player.inventory, getTileForestry(world, x, y, z, player, TileAnalyzer.class)); case NaturalistBenchGUI: - return new GuiEscritoire(player, getTileForestry(world, x, y, z, TileEscritoire.class)); + return new GuiEscritoire(player, getTileForestry(world, x, y, z, player, TileEscritoire.class)); case SolderingIronGUI: ItemStack equipped = player.getCurrentEquippedItem(); @@ -73,10 +73,10 @@ public class GuiHandler extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case AnalyzerGUI: - return new ContainerAnalyzer(player.inventory, getTileForestry(world, x, y, z, TileAnalyzer.class)); + return new ContainerAnalyzer(player.inventory, getTileForestry(world, x, y, z, player, TileAnalyzer.class)); case NaturalistBenchGUI: - return new ContainerEscritoire(player, getTileForestry(world, x, y, z, TileEscritoire.class)); + return new ContainerEscritoire(player, getTileForestry(world, x, y, z, player, TileEscritoire.class)); case SolderingIronGUI: ItemStack equipped = player.getCurrentEquippedItem(); diff --git a/src/main/java/forestry/core/GuiHandlerBase.java b/src/main/java/forestry/core/GuiHandlerBase.java index 9ee1fe891..cfe196bd9 100755 --- a/src/main/java/forestry/core/GuiHandlerBase.java +++ b/src/main/java/forestry/core/GuiHandlerBase.java @@ -26,7 +26,7 @@ import forestry.core.proxy.Proxies; public abstract class GuiHandlerBase implements IGuiHandler { - public T getTileForestry(World world, int x, int y, int z, Class tileClass) { + public T getTileForestry(World world, int x, int y, int z, EntityPlayer player, Class tileClass) { T tileForestry = null; try { tileForestry = tileClass.cast(world.getTileEntity(x, y, z)); @@ -35,14 +35,14 @@ public abstract class GuiHandlerBase implements IGuiHandler { } if (tileForestry != null && !world.isRemote) { - Proxies.net.sendNetworkPacket(new PacketTileGuiOpened(tileForestry)); + tileForestry.sendGuiUpdate(player); } return tileForestry; } public GuiNaturalistInventory getNaturalistChestGui(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) { - TileNaturalistChest tile = getTileForestry(world, x, y, z, TileNaturalistChest.class); + TileNaturalistChest tile = getTileForestry(world, x, y, z, player, TileNaturalistChest.class); ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID); return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistInventory(player.inventory, tile, page, 25), tile, page, 5); } @@ -50,7 +50,7 @@ public abstract class GuiHandlerBase implements IGuiHandler { public ContainerNaturalistInventory getNaturalistChestContainer(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) { ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID); speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); - return new ContainerNaturalistInventory(player.inventory, getTileForestry(world, x, y, z, TileNaturalistChest.class), page, 25); + return new ContainerNaturalistInventory(player.inventory, getTileForestry(world, x, y, z, player, TileNaturalistChest.class), page, 25); } public static int encodeGuiData(int guiId, int data) { diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index c7cbc6576..48495fdf5 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -51,6 +51,7 @@ import forestry.core.interfaces.IRestrictedAccess; import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.IStreamable; +import forestry.core.network.PacketTileGuiOpened; import forestry.core.network.PacketTileStream; import forestry.core.proxy.Proxies; import forestry.core.utils.AdjacentTileCache; @@ -242,6 +243,11 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR } } + public final void sendGuiUpdate(EntityPlayer player) { + PacketTileGuiOpened packet = new PacketTileGuiOpened(this); + Proxies.net.sendToPlayer(packet, player); + } + public final void writeGuiData(DataOutputStream data) throws IOException { writeErrorData(data); @@ -296,7 +302,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR return; } this.orientation = orientation; - this.sendNetworkUpdate(); + this.setNeedsNetworkUpdate(); } protected final void setNeedsNetworkUpdate() { @@ -400,14 +406,14 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR int ordinal = (access.ordinal() + 1) % EnumAccess.values().length; access = EnumAccess.values()[ordinal]; if (!this.worldObj.isRemote) { - sendNetworkUpdate(); - } + sendGuiUpdate(player); - boolean canPipesConnect = allowsPipeConnections(); - if (couldPipesConnect != canPipesConnect) { - // pipes connected to this need to update - worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType); - markDirty(); + boolean canPipesConnect = allowsPipeConnections(); + if (couldPipesConnect != canPipesConnect) { + // pipes connected to this need to update + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType); + markDirty(); + } } return true; @@ -447,7 +453,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR } @Override - public final ItemStack decrStackSize(int slotIndex, int amount) { + public ItemStack decrStackSize(int slotIndex, int amount) { return getInternalInventory().decrStackSize(slotIndex, amount); } @@ -457,7 +463,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR } @Override - public final void setInventorySlotContents(int slotIndex, ItemStack itemstack) { + public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { getInternalInventory().setInventorySlotContents(slotIndex, itemstack); } diff --git a/src/main/java/forestry/core/genetics/Genome.java b/src/main/java/forestry/core/genetics/Genome.java index 6886cea56..11c81fc51 100755 --- a/src/main/java/forestry/core/genetics/Genome.java +++ b/src/main/java/forestry/core/genetics/Genome.java @@ -51,6 +51,37 @@ public abstract class Genome implements IGenome { } // NBT RETRIEVAL + /** + * Quickly gets the species without loading the whole genome. + * We need this because the client uses the species for rendering. + */ + protected static IAlleleSpecies getSpeciesDirectly(ItemStack itemStack) { + NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); + if (nbtTagCompound == null) { + return null; + } + + NBTTagCompound genomeNBT = nbtTagCompound.getCompoundTag("Genome"); + if (genomeNBT == null) { + return null; + } + + NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10); + if (chromosomesNBT == null) { + return null; + } + + NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(0); + Chromosome chromosome = Chromosome.loadChromosomeFromNBT(chromosomeNBT); + + IAllele activeAllele = chromosome.getActiveAllele(); + if (!(activeAllele instanceof IAlleleSpecies)) { + return null; + } + + return (IAlleleSpecies) activeAllele; + } + public static IChromosome getChromosome(ItemStack itemStack, IChromosomeType chromosomeType, ISpeciesRoot speciesRoot) { NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); if (nbtTagCompound == null) { diff --git a/src/main/java/forestry/core/gui/ContainerTile.java b/src/main/java/forestry/core/gui/ContainerTile.java index 2243ec400..5f23173fc 100644 --- a/src/main/java/forestry/core/gui/ContainerTile.java +++ b/src/main/java/forestry/core/gui/ContainerTile.java @@ -48,7 +48,7 @@ public class ContainerTile extends ContainerForestry { ImmutableSet errorStates = tile.getErrorStates(); - if (!errorStates.equals(previousErrorStates)) { + if ((previousErrorStates != null) && !errorStates.equals(previousErrorStates)) { PacketErrorUpdate packet = new PacketErrorUpdate(tile); for (Object crafter : crafters) { if (crafter instanceof EntityPlayer) { diff --git a/src/main/java/forestry/core/network/PacketId.java b/src/main/java/forestry/core/network/PacketId.java index 7381160ab..64aec70b8 100644 --- a/src/main/java/forestry/core/network/PacketId.java +++ b/src/main/java/forestry/core/network/PacketId.java @@ -20,14 +20,16 @@ public enum PacketId { IINVENTORY_STACK, FX_SIGNAL, + WORKTABLE_MEMORY_UPDATE, + HABITAT_BIOME_POINTER, CANDLE, GUI_SELECTION_CHANGE, IMPRINT_SELECTION_GET, GUI_SELECTION_SET, - GUI_LAYOUT_SELECT, + GUI_INTEGER, PIPETTE_CLICK, @@ -49,8 +51,6 @@ public enum PacketId { RIPENING_UPDATE, - GUI_INTEGER, - // Propolis pipe PROP_SEND_FILTER_SET, PROP_REQUEST_FILTER_SET, diff --git a/src/main/java/forestry/core/proxy/ClientProxyCommon.java b/src/main/java/forestry/core/proxy/ClientProxyCommon.java index 275a9e30b..4fa83e7a5 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ClientProxyCommon.java @@ -33,7 +33,6 @@ import forestry.apiculture.render.TextureHabitatLocator; import forestry.core.ForestryClient; import forestry.core.TickHandlerCoreClient; import forestry.core.WorldGenerator; -import forestry.core.config.Config; import forestry.core.render.EntityHoneydustFX; import forestry.core.render.SpriteSheet; @@ -163,7 +162,7 @@ public class ClientProxyCommon extends ProxyCommon { // FIXME: This is causing crashes. @Override public void addEntityBiodustFX(World world, double d1, double d2, double d3, float f1, float f2, float f3) { - if (!Config.enableParticleFX) { + if (!ClientProxyRender.shouldSpawnParticle(world)) { return; } @@ -172,7 +171,7 @@ public class ClientProxyCommon extends ProxyCommon { @Override public void addEntitySwarmFX(World world, double d1, double d2, double d3, float f1, float f2, float f3) { - if (!Config.enableParticleFX) { + if (!ClientProxyRender.shouldSpawnParticle(world)) { return; } @@ -181,7 +180,7 @@ public class ClientProxyCommon extends ProxyCommon { @Override public void addEntityExplodeFX(World world, double d1, double d2, double d3, float f1, float f2, float f3) { - if (!Config.enableParticleFX) { + if (!ClientProxyRender.shouldSpawnParticle(world)) { return; } diff --git a/src/main/java/forestry/core/proxy/ClientProxyRender.java b/src/main/java/forestry/core/proxy/ClientProxyRender.java index d13a46372..0f6001b20 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyRender.java +++ b/src/main/java/forestry/core/proxy/ClientProxyRender.java @@ -75,27 +75,31 @@ public class ClientProxyRender extends ProxyRender { return new RenderEscritoire(); } - private boolean shouldSpawnParticle(World world, boolean canDisable) { - if (canDisable && !Config.enableParticleFX) { + public static boolean shouldSpawnParticle(World world) { + if (!Config.enableParticleFX) { return false; } + Minecraft mc = FMLClientHandler.instance().getClient(); int particleSetting = mc.gameSettings.particleSetting; - if (!canDisable && particleSetting > 1) { - particleSetting = 1; + + // minimal + if (particleSetting == 2) { + return world.rand.nextInt(10) == 0; } - if (particleSetting == 1 && world.rand.nextInt(3) == 0) { - particleSetting = 2; - } - if (particleSetting > 1) { - return false; + + // decreased + if (particleSetting == 1) { + return world.rand.nextInt(3) != 0; } + + // all return true; } @Override public void addSnowFX(World world, double xCoord, double yCoord, double zCoord, int color, int areaX, int areaY, int areaZ) { - if (!shouldSpawnParticle(world, true)) { + if (!shouldSpawnParticle(world)) { return; } diff --git a/src/main/java/forestry/energy/GuiHandlerEnergy.java b/src/main/java/forestry/energy/GuiHandlerEnergy.java index e7540110e..f73ddbc6e 100755 --- a/src/main/java/forestry/energy/GuiHandlerEnergy.java +++ b/src/main/java/forestry/energy/GuiHandlerEnergy.java @@ -43,16 +43,16 @@ public class GuiHandlerEnergy extends GuiHandlerBase { switch (GuiId.values()[id]) { case EngineBronzeGUI: - return new GuiEngineBronze(player.inventory, getTileForestry(world, x, y, z, EngineBronze.class)); + return new GuiEngineBronze(player.inventory, getTileForestry(world, x, y, z, player, EngineBronze.class)); case EngineCopperGUI: - return new GuiEngineCopper(player.inventory, getTileForestry(world, x, y, z, EngineCopper.class)); + return new GuiEngineCopper(player.inventory, getTileForestry(world, x, y, z, player, EngineCopper.class)); case EngineTinGUI: - return new GuiEngineTin(player.inventory, getTileForestry(world, x, y, z, EngineTin.class)); + return new GuiEngineTin(player.inventory, getTileForestry(world, x, y, z, player, EngineTin.class)); case GeneratorGUI: - return new GuiGenerator(player.inventory, getTileForestry(world, x, y, z, MachineGenerator.class)); + return new GuiGenerator(player.inventory, getTileForestry(world, x, y, z, player, MachineGenerator.class)); default: return null; @@ -69,18 +69,18 @@ public class GuiHandlerEnergy extends GuiHandlerBase { switch (GuiId.values()[id]) { case EngineBronzeGUI: - return new ContainerEngineBronze(player.inventory, getTileForestry(world, x, y, z, EngineBronze.class)); + return new ContainerEngineBronze(player.inventory, getTileForestry(world, x, y, z, player, EngineBronze.class)); case EngineCopperGUI: - return new ContainerEngineCopper(player.inventory, getTileForestry(world, x, y, z, EngineCopper.class)); + return new ContainerEngineCopper(player.inventory, getTileForestry(world, x, y, z, player, EngineCopper.class)); case EngineTinGUI: - EngineTin tile = getTileForestry(world, x, y, z, EngineTin.class); + EngineTin tile = getTileForestry(world, x, y, z, player, EngineTin.class); Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile), player); return new ContainerEngineTin(player.inventory, tile); case GeneratorGUI: - return new ContainerGenerator(player.inventory, getTileForestry(world, x, y, z, MachineGenerator.class)); + return new ContainerGenerator(player.inventory, getTileForestry(world, x, y, z, player, MachineGenerator.class)); default: return null; diff --git a/src/main/java/forestry/energy/gadgets/EngineClockwork.java b/src/main/java/forestry/energy/gadgets/EngineClockwork.java index c887f5ffc..f371e6d81 100755 --- a/src/main/java/forestry/energy/gadgets/EngineClockwork.java +++ b/src/main/java/forestry/energy/gadgets/EngineClockwork.java @@ -68,7 +68,7 @@ public class EngineClockwork extends Engine { } tension = tension > ENGINE_CLOCKWORK_WIND_MAX + WIND_TENSION_BASE ? ENGINE_CLOCKWORK_WIND_MAX + WIND_TENSION_BASE : tension; delay = WIND_DELAY; - sendNetworkUpdate(); + setNeedsNetworkUpdate(); } /* LOADING & SAVING */ diff --git a/src/main/java/forestry/energy/gui/GuiEngine.java b/src/main/java/forestry/energy/gui/GuiEngine.java index 665d92958..77243a01d 100755 --- a/src/main/java/forestry/energy/gui/GuiEngine.java +++ b/src/main/java/forestry/energy/gui/GuiEngine.java @@ -8,9 +8,6 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -/** - * - */ package forestry.energy.gui; import net.minecraft.inventory.Container; diff --git a/src/main/java/forestry/factory/GuiHandlerFactory.java b/src/main/java/forestry/factory/GuiHandlerFactory.java index 9327c814b..cc1c4e851 100755 --- a/src/main/java/forestry/factory/GuiHandlerFactory.java +++ b/src/main/java/forestry/factory/GuiHandlerFactory.java @@ -58,34 +58,34 @@ public class GuiHandlerFactory extends GuiHandlerBase { switch (GuiId.values()[id]) { case BottlerGUI: - return new GuiBottler(player.inventory, getTileForestry(world, x, y, z, MachineBottler.class)); + return new GuiBottler(player.inventory, getTileForestry(world, x, y, z, player, MachineBottler.class)); case CarpenterGUI: - return new GuiCarpenter(player.inventory, getTileForestry(world, x, y, z, MachineCarpenter.class)); + return new GuiCarpenter(player.inventory, getTileForestry(world, x, y, z, player, MachineCarpenter.class)); case CentrifugeGUI: - return new GuiCentrifuge(player.inventory, getTileForestry(world, x, y, z, MachineCentrifuge.class)); + return new GuiCentrifuge(player.inventory, getTileForestry(world, x, y, z, player, MachineCentrifuge.class)); case FabricatorGUI: - return new GuiFabricator(player.inventory, getTileForestry(world, x, y, z, MachineFabricator.class)); + return new GuiFabricator(player.inventory, getTileForestry(world, x, y, z, player, MachineFabricator.class)); case FermenterGUI: - return new GuiFermenter(player.inventory, getTileForestry(world, x, y, z, MachineFermenter.class)); + return new GuiFermenter(player.inventory, getTileForestry(world, x, y, z, player, MachineFermenter.class)); case MoistenerGUI: - return new GuiMoistener(player.inventory, getTileForestry(world, x, y, z, MachineMoistener.class)); + return new GuiMoistener(player.inventory, getTileForestry(world, x, y, z, player, MachineMoistener.class)); case RaintankGUI: - return new GuiRaintank(player.inventory, getTileForestry(world, x, y, z, MachineRaintank.class)); + return new GuiRaintank(player.inventory, getTileForestry(world, x, y, z, player, MachineRaintank.class)); case SqueezerGUI: - return new GuiSqueezer(player.inventory, getTileForestry(world, x, y, z, MachineSqueezer.class)); + return new GuiSqueezer(player.inventory, getTileForestry(world, x, y, z, player, MachineSqueezer.class)); case StillGUI: - return new GuiStill(player.inventory, getTileForestry(world, x, y, z, MachineStill.class)); + return new GuiStill(player.inventory, getTileForestry(world, x, y, z, player, MachineStill.class)); case WorktableGUI: - return new GuiWorktable(player, getTileForestry(world, x, y, z, TileWorktable.class)); + return new GuiWorktable(player, getTileForestry(world, x, y, z, player, TileWorktable.class)); default: return null; @@ -103,34 +103,34 @@ public class GuiHandlerFactory extends GuiHandlerBase { switch (GuiId.values()[id]) { case BottlerGUI: - return new ContainerBottler(player.inventory, getTileForestry(world, x, y, z, MachineBottler.class)); + return new ContainerBottler(player.inventory, getTileForestry(world, x, y, z, player, MachineBottler.class)); case CarpenterGUI: - return new ContainerCarpenter(player.inventory, getTileForestry(world, x, y, z, MachineCarpenter.class)); + return new ContainerCarpenter(player.inventory, getTileForestry(world, x, y, z, player, MachineCarpenter.class)); case CentrifugeGUI: - return new ContainerCentrifuge(player.inventory, getTileForestry(world, x, y, z, MachineCentrifuge.class)); + return new ContainerCentrifuge(player.inventory, getTileForestry(world, x, y, z, player, MachineCentrifuge.class)); case FabricatorGUI: - return new ContainerFabricator(player.inventory, getTileForestry(world, x, y, z, MachineFabricator.class)); + return new ContainerFabricator(player.inventory, getTileForestry(world, x, y, z, player, MachineFabricator.class)); case FermenterGUI: - return new ContainerFermenter(player.inventory, getTileForestry(world, x, y, z, MachineFermenter.class)); + return new ContainerFermenter(player.inventory, getTileForestry(world, x, y, z, player, MachineFermenter.class)); case MoistenerGUI: - return new ContainerMoistener(player.inventory, getTileForestry(world, x, y, z, MachineMoistener.class)); + return new ContainerMoistener(player.inventory, getTileForestry(world, x, y, z, player, MachineMoistener.class)); case RaintankGUI: - return new ContainerRaintank(player.inventory, getTileForestry(world, x, y, z, MachineRaintank.class)); + return new ContainerRaintank(player.inventory, getTileForestry(world, x, y, z, player, MachineRaintank.class)); case SqueezerGUI: - return new ContainerSqueezer(player.inventory, getTileForestry(world, x, y, z, MachineSqueezer.class)); + return new ContainerSqueezer(player.inventory, getTileForestry(world, x, y, z, player, MachineSqueezer.class)); case StillGUI: - return new ContainerStill(player.inventory, getTileForestry(world, x, y, z, MachineStill.class)); + return new ContainerStill(player.inventory, getTileForestry(world, x, y, z, player, MachineStill.class)); case WorktableGUI: - return new ContainerWorktable(player, getTileForestry(world, x, y, z, TileWorktable.class)); + return new ContainerWorktable(player, getTileForestry(world, x, y, z, player, TileWorktable.class)); default: return null; diff --git a/src/main/java/forestry/factory/gadgets/TileWorktable.java b/src/main/java/forestry/factory/gadgets/TileWorktable.java index 18fe92d4d..b0612f9c8 100755 --- a/src/main/java/forestry/factory/gadgets/TileWorktable.java +++ b/src/main/java/forestry/factory/gadgets/TileWorktable.java @@ -95,10 +95,6 @@ public class TileWorktable extends TileBase implements ICrafter { memorized.readData(data); } - public void sendAll(EntityPlayer player) { - Proxies.net.sendToPlayer(new PacketTileStream(this), player); - } - @Override public void validate() { super.validate(); diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/factory/gui/ContainerWorktable.java index 77e8440d9..deba2a264 100755 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/factory/gui/ContainerWorktable.java @@ -23,13 +23,14 @@ import forestry.core.gui.slots.SlotCrafter; import forestry.core.interfaces.IContainerCrafting; import forestry.core.network.PacketGuiSelect; import forestry.core.network.PacketId; +import forestry.core.network.PacketTileStream; import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; import forestry.factory.gadgets.TileWorktable; +import forestry.factory.network.PacketWorktableMemoryUpdate; public class ContainerWorktable extends ContainerTile implements IContainerCrafting, IGuiSelectable { - private final EntityPlayer player; private final InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); private long lastUpdate; @@ -59,9 +60,6 @@ public class ContainerWorktable extends ContainerTile implements // Update crafting matrix with current contents of tileentity. updateMatrix(); updateRecipe(); - - this.player = player; - tile.sendAll(player); } @Override @@ -72,7 +70,13 @@ public class ContainerWorktable extends ContainerTile implements } lastUpdate = tile.getMemory().getLastUpdate(); - tile.sendAll(player); + + PacketWorktableMemoryUpdate packet = new PacketWorktableMemoryUpdate(tile); + for (Object crafter : crafters) { + if (crafter instanceof EntityPlayer) { + Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter); + } + } } @Override diff --git a/src/main/java/forestry/factory/network/PacketHandlerFactory.java b/src/main/java/forestry/factory/network/PacketHandlerFactory.java new file mode 100644 index 000000000..5aa5889ec --- /dev/null +++ b/src/main/java/forestry/factory/network/PacketHandlerFactory.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.factory.network; + +import java.io.DataInputStream; +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.network.IPacketHandler; +import forestry.core.network.PacketId; + +public class PacketHandlerFactory implements IPacketHandler { + + @Override + public boolean onPacketData(PacketId packetID, DataInputStream data, EntityPlayer player) throws IOException { + + switch (packetID) { + case WORKTABLE_MEMORY_UPDATE: { + PacketWorktableMemoryUpdate.onPacketData(data); + return true; + } + } + + return false; + } +} diff --git a/src/main/java/forestry/factory/network/PacketWorktableMemoryUpdate.java b/src/main/java/forestry/factory/network/PacketWorktableMemoryUpdate.java new file mode 100644 index 000000000..7559b7016 --- /dev/null +++ b/src/main/java/forestry/factory/network/PacketWorktableMemoryUpdate.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.factory.network; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import net.minecraft.tileentity.TileEntity; + +import forestry.core.network.PacketCoordinates; +import forestry.core.network.PacketId; +import forestry.core.proxy.Proxies; +import forestry.factory.gadgets.TileWorktable; +import forestry.factory.recipes.RecipeMemory; + +public class PacketWorktableMemoryUpdate extends PacketCoordinates { + + private RecipeMemory recipeMemory; + + public static void onPacketData(DataInputStream data) throws IOException { + new PacketWorktableMemoryUpdate(data); + } + + private PacketWorktableMemoryUpdate(DataInputStream data) throws IOException { + super(data); + } + + public PacketWorktableMemoryUpdate(TileWorktable worktable) { + super(PacketId.WORKTABLE_MEMORY_UPDATE, worktable); + this.recipeMemory = worktable.getMemory(); + } + + @Override + protected void writeData(DataOutputStream data) throws IOException { + super.writeData(data); + recipeMemory.writeData(data); + } + + @Override + protected void readData(DataInputStream data) throws IOException { + super.readData(data); + + TileEntity tile = getTarget(Proxies.common.getRenderWorld()); + if (tile instanceof TileWorktable) { + ((TileWorktable) tile).getMemory().readData(data); + } + } +} diff --git a/src/main/java/forestry/farming/GuiHandlerFarming.java b/src/main/java/forestry/farming/GuiHandlerFarming.java index 5df1b59ae..206e12e36 100755 --- a/src/main/java/forestry/farming/GuiHandlerFarming.java +++ b/src/main/java/forestry/farming/GuiHandlerFarming.java @@ -33,7 +33,7 @@ public class GuiHandlerFarming extends GuiHandlerBase { switch (GuiId.values()[id]) { case MultiFarmGUI: - TileFarmPlain tile = getTileForestry(world, x, y, z, TileFarmPlain.class); + TileFarmPlain tile = getTileForestry(world, x, y, z, player, TileFarmPlain.class); Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile), player); return new ContainerFarm(player.inventory, tile); default: @@ -50,7 +50,7 @@ public class GuiHandlerFarming extends GuiHandlerBase { switch (GuiId.values()[id]) { case MultiFarmGUI: - return new GuiFarm(player, getTileForestry(world, x, y, z, TileFarmPlain.class)); + return new GuiFarm(player, getTileForestry(world, x, y, z, player, TileFarmPlain.class)); default: return null; diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java index 962109daf..5a7981543 100755 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java @@ -17,6 +17,7 @@ import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleFlowers; import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.ISpeciesRoot; @@ -42,6 +43,11 @@ public class ButterflyGenome extends Genome implements IButterflyGenome { // NBT RETRIEVAL public static IAlleleButterflySpecies getSpecies(ItemStack itemStack) { + IAlleleSpecies species = getSpeciesDirectly(itemStack); + if (species instanceof IAlleleButterflySpecies) { + return (IAlleleButterflySpecies) species; + } + return (IAlleleButterflySpecies) getActiveAllele(itemStack, EnumButterflyChromosome.SPECIES, PluginLepidopterology.butterflyInterface); } diff --git a/src/main/java/forestry/mail/GuiHandlerMail.java b/src/main/java/forestry/mail/GuiHandlerMail.java index 9a043a6b4..65f519ca5 100755 --- a/src/main/java/forestry/mail/GuiHandlerMail.java +++ b/src/main/java/forestry/mail/GuiHandlerMail.java @@ -70,13 +70,13 @@ public class GuiHandlerMail extends GuiHandlerBase { } case MailboxGUI: - return new GuiMailbox(player.inventory, getTileForestry(world, x, y, z, MachineMailbox.class)); + return new GuiMailbox(player.inventory, getTileForestry(world, x, y, z, player, MachineMailbox.class)); case PhilatelistGUI: - return new GuiPhilatelist(player.inventory, getTileForestry(world, x, y, z, MachinePhilatelist.class)); + return new GuiPhilatelist(player.inventory, getTileForestry(world, x, y, z, player, MachinePhilatelist.class)); case TraderGUI: - return new GuiTrader(player.inventory, getTileForestry(world, x, y, z, MachineTrader.class)); + return new GuiTrader(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class)); case TraderNameGUI: - return new GuiTradeName(player.inventory, getTileForestry(world, x, y, z, MachineTrader.class)); + return new GuiTradeName(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class)); default: return null; @@ -116,13 +116,13 @@ public class GuiHandlerMail extends GuiHandlerBase { } case MailboxGUI: - return new ContainerMailbox(player.inventory, getTileForestry(world, x, y, z, MachineMailbox.class)); + return new ContainerMailbox(player.inventory, getTileForestry(world, x, y, z, player, MachineMailbox.class)); case PhilatelistGUI: - return new ContainerPhilatelist(player.inventory, getTileForestry(world, x, y, z, MachinePhilatelist.class)); + return new ContainerPhilatelist(player.inventory, getTileForestry(world, x, y, z, player, MachinePhilatelist.class)); case TraderGUI: - return new ContainerTrader(player.inventory, getTileForestry(world, x, y, z, MachineTrader.class)); + return new ContainerTrader(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class)); case TraderNameGUI: - return new ContainerTradeName(player.inventory, getTileForestry(world, x, y, z, MachineTrader.class)); + return new ContainerTradeName(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class)); default: return null; diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index d0c4c3324..7c7d0c080 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -56,7 +56,7 @@ import forestry.arboriculture.FruitProviderPod.EnumPodType; import forestry.arboriculture.FruitProviderRandom; import forestry.arboriculture.FruitProviderRipening; import forestry.arboriculture.GuiHandlerArboriculture; -import forestry.arboriculture.PacketHandlerArboriculture; +import forestry.arboriculture.network.PacketHandlerArboriculture; import forestry.arboriculture.VillageHandlerArboriculture; import forestry.arboriculture.WoodType; import forestry.arboriculture.commands.CommandTree; diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java index d11c6c465..f60e56574 100644 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -32,6 +32,7 @@ import forestry.core.gadgets.MachineDefinition; import forestry.core.gadgets.MachineNBTDefinition; import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemNBTTile; +import forestry.core.network.IPacketHandler; import forestry.core.proxy.Proxies; import forestry.core.utils.RecipeUtil; import forestry.core.utils.ShapedRecipeCustom; @@ -48,6 +49,7 @@ import forestry.factory.gadgets.MachineSqueezer; import forestry.factory.gadgets.MachineStill; import forestry.factory.gadgets.MillRainmaker; import forestry.factory.gadgets.TileWorktable; +import forestry.factory.network.PacketHandlerFactory; import forestry.factory.recipes.CraftGuideIntegration; import forestry.factory.triggers.FactoryTriggers; @@ -82,6 +84,11 @@ public class PluginFactory extends ForestryPlugin { ); } + @Override + public IPacketHandler getPacketHandler() { + return new PacketHandlerFactory(); + } + @Override protected void disabledSetupAPI() { super.disabledSetupAPI();