From c6baca7116215bafaf6aa3fdacacc932004ba37b Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 31 May 2015 03:12:28 -0700 Subject: [PATCH] #561 Fix bee particle effects networking --- .../apiculture/gadgets/TileAlvearyPlain.java | 60 +++++-------- .../apiculture/gadgets/TileBeehouse.java | 90 ++++++++++++++----- .../core/proxy/ClientProxyCommon.java | 4 +- .../core/render/EntityHoneydustFX.java | 14 +-- 4 files changed, 97 insertions(+), 71 deletions(-) diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index f87f05664..ab535addc 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -53,6 +53,7 @@ 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; @@ -129,12 +130,20 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB public void writeData(DataOutputStream data) throws IOException { super.writeData(data); data.writeBoolean(active); + if (active) { + ItemStack queen = getStackInSlot(SLOT_QUEEN); + PacketHelper.writeItemStack(queen, data); + } } @Override public void readData(DataInputStream data) throws IOException { super.readData(data); active = data.readBoolean(); + if (active) { + ItemStack queen = PacketHelper.readItemStack(data); + setInventorySlotContents(SLOT_QUEEN, queen); + } } @Override @@ -181,36 +190,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB // Equalize humidity and temperature equalizeTemperature(); equalizeHumidity(); - - IBee queen = beekeepingLogic.getQueen(); - if (queen == null) { - return; - } - - // Add swarm effects - if (updateOnInterval(200)) { - ISidedInventory inventory = getStructureInventory(); - if (inventory != null) { - onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); - } - } - - if (!hasErrorState()) { - queen.doFX(beekeepingLogic.getEffectData(), this); - - if (updateOnInterval(50)) { - float f = xCoord + 0.5F; - float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F; - float f2 = zCoord + 0.5F; - float f3 = 0.52F; - float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F; - - Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F); - Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F); - } - } } @Override @@ -225,16 +204,23 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB } if (updateOnInterval(2)) { - ISidedInventory inventory = getStructureInventory(); - if (inventory == null) { - return; - } - - // / Multiplayer FX - ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN); + 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); + } } } } diff --git a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java index 33c23e29e..2db5ab86d 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java @@ -10,6 +10,9 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; import java.util.Set; import net.minecraft.entity.player.EntityPlayer; @@ -33,22 +36,24 @@ import forestry.api.core.EnumTemperature; import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorState; 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.network.PacketTileStream; import forestry.core.proxy.Proxies; import forestry.core.utils.GuiUtil; -public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { +public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, IActivatable { // CONSTANTS public static final int SLOT_QUEEN = 0; public static final int SLOT_DRONE = 1; @@ -61,6 +66,9 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { private int displayHealthMax = 0; private int displayHealth = 0; + // CLIENT + private boolean active; + public TileBeehouse() { setHints(Config.hints.get("apiary")); logic = BeeManager.beeRoot.createBeekeepingLogic(this); @@ -93,6 +101,26 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { } + @Override + public void writeData(DataOutputStream data) throws IOException { + super.writeData(data); + data.writeBoolean(active); + if (active) { + ItemStack queen = getStackInSlot(SLOT_QUEEN); + PacketHelper.writeItemStack(queen, data); + } + } + + @Override + public void readData(DataInputStream data) throws IOException { + super.readData(data); + active = data.readBoolean(); + if (active) { + ItemStack queen = PacketHelper.readItemStack(data); + setInventorySlotContents(SLOT_QUEEN, queen); + } + } + @Override public void initialize() { super.initialize(); @@ -153,31 +181,34 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { /* UPDATING */ @Override public void updateClientSide() { - - // / Multiplayer FX - if (BeeManager.beeRoot.isMated(getInternalInventory().getStackInSlot(SLOT_QUEEN))) { - if (!hasErrorState() && updateOnInterval(2)) { - IBee displayQueen = BeeManager.beeRoot.getMember(getInternalInventory().getStackInSlot(SLOT_QUEEN)); + 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 (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); + } } } - } @Override public void updateServerSide() { - - if (logic.canWork()) + boolean canWork = logic.canWork(); + setActive(canWork); + if (canWork) { logic.doWork(); - - IBee queen = logic.getQueen(); - if (queen == null) { - return; - } - - // Add swarm effects - if (updateOnInterval(200)) { - onQueenChange(getInternalInventory().getStackInSlot(SLOT_QUEEN)); } } @@ -198,8 +229,8 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { return; } - Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketId.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack)); - Proxies.net.sendNetworkPacket(new PacketTileStream(this)); + PacketInventoryStack packet = new PacketInventoryStack(PacketId.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack); + Proxies.net.sendNetworkPacket(packet); } /* STATE INFORMATION */ @@ -409,6 +440,23 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { return this.getOwner(); } + @Override + public boolean isActive() { + return active; + } + + @Override + public void setActive(boolean active) { + if (this.active == active) { + return; + } + this.active = active; + + if (!worldObj.isRemote) { + Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this)); + } + } + protected static class BeehouseInventoryAdapter extends TileInventoryAdapter { public BeehouseInventoryAdapter(TileBeehouse tile, int size, String name) { super(tile, size, name); diff --git a/src/main/java/forestry/core/proxy/ClientProxyCommon.java b/src/main/java/forestry/core/proxy/ClientProxyCommon.java index a85f241f2..275a9e30b 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ClientProxyCommon.java @@ -34,6 +34,7 @@ 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; public class ClientProxyCommon extends ProxyCommon { @@ -169,14 +170,13 @@ public class ClientProxyCommon extends ProxyCommon { // ModLoader.getMinecraftInstance().effectRenderer.addEffect(new EntityBiodustFX(world, d1, d2, d3, f1, f2, f3)); } - // FIXME: This is causing crashes. @Override public void addEntitySwarmFX(World world, double d1, double d2, double d3, float f1, float f2, float f3) { if (!Config.enableParticleFX) { return; } - // ModLoader.getMinecraftInstance().effectRenderer.addEffect(new EntityHoneydustFX(world, d1, d2, d3, f1, f2, f3)); + getClientInstance().effectRenderer.addEffect(new EntityHoneydustFX(world, d1, d2, d3, f1, f2, f3)); } @Override diff --git a/src/main/java/forestry/core/render/EntityHoneydustFX.java b/src/main/java/forestry/core/render/EntityHoneydustFX.java index 1ae5520f8..18500ead9 100755 --- a/src/main/java/forestry/core/render/EntityHoneydustFX.java +++ b/src/main/java/forestry/core/render/EntityHoneydustFX.java @@ -21,16 +21,8 @@ public class EntityHoneydustFX extends EntityReddustFX { public EntityHoneydustFX(World world, double d, double d1, double d2, float f, float f1, float f2, float f3) { super(world, d, d1, d2, f, f1, f2, f3); - // float f4 = (float)Math.random() * 0.4F + 0.6F; - // particleRed = ((float)(Math.random() * 0.20000000298023224D) + 0.95F) - // * f1 * f4; - // particleGreen = ((float)(Math.random() * 0.20000000298023224D) + - // 0.75F) * f2 * f4; - // particleBlue = ((float)(Math.random() * 0.20000000298023224D) + 0.1F) - // * f3 * f4; - particleRed = 0.9F; - particleGreen = 0.75F; - particleBlue = 0F; + particleRed = 0.9F + (world.rand.nextFloat() * 0.2F); + particleGreen = 0.75F + (world.rand.nextFloat() * 0.2F); + particleBlue = 0F + (world.rand.nextFloat() * 0.2F); } - }