Fix #701 Improve BeekeepingLogic and network performance.

Improve rendering performance of saplings and butterflies too
This commit is contained in:
mezz committed 2015-06-06 23:15:25 -07:00
1 parent d61096e1a9
commit 1249ccf983
34 files changed
+404 -217

No files matched your search

@@ -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<ItemStack> spawn = new Stack<ItemStack>();
// 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<IErrorState> 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;
}
@@ -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);
@@ -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);
@@ -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);
@@ -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<IErrorState> errorStates = ImmutableSet.builder();
Set<IErrorState> errorStates = new HashSet<IErrorState>();
// / 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
@@ -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);
}
@@ -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
@@ -23,8 +23,6 @@ public class ContainerAlveary extends ContainerTile<TileAlvearyPlain> {
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));
@@ -23,8 +23,6 @@ public class ContainerApiary extends ContainerTile<TileBeehouse> {
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));
@@ -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;
@@ -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;
}
@@ -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);
}
@@ -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;
+4 -4
View File
@@ -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();
@@ -26,7 +26,7 @@ import forestry.core.proxy.Proxies;
public abstract class GuiHandlerBase implements IGuiHandler {
public <T extends TileForestry> T getTileForestry(World world, int x, int y, int z, Class<T> tileClass) {
public <T extends TileForestry> T getTileForestry(World world, int x, int y, int z, EntityPlayer player, Class<T> 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) {
@@ -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);
}
@@ -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) {
@@ -48,7 +48,7 @@ public class ContainerTile<T extends TileForestry> extends ContainerForestry {
ImmutableSet<IErrorState> 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) {
@@ -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,
@@ -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;
}
@@ -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;
}
@@ -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;
@@ -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 */
@@ -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;
@@ -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;
@@ -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();
@@ -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<TileWorktable> 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<TileWorktable> 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<TileWorktable> 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
@@ -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;
}
}
@@ -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);
}
}
}
@@ -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;
@@ -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);
}
@@ -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;
@@ -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;
@@ -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();