#561 Fix bee particle effects networking

This commit is contained in:
mezz committed 2015-05-31 03:13:23 -07:00
1 parent 68315ee614
commit c6baca7116
4 files changed
+97 -71

No files matched your search

@@ -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);
}
}
}
}
@@ -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<TileBeehouse> {
public BeehouseInventoryAdapter(TileBeehouse tile, int size, String name) {
super(tile, size, name);
@@ -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
@@ -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);
}
}