From c686e325b98c45808b205217330f2277fd2523c0 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Aug 2013 00:24:12 -0400 Subject: [PATCH] Fixed packet and made Tesla colors work --- src/resonantinduction/PacketHandler.java | 2 + src/resonantinduction/fx/FXElectricBolt.java | 7 ++- .../tesla/TileEntityTesla.java | 51 +++++++++++++------ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/resonantinduction/PacketHandler.java b/src/resonantinduction/PacketHandler.java index b87c6cbda..3b022b190 100644 --- a/src/resonantinduction/PacketHandler.java +++ b/src/resonantinduction/PacketHandler.java @@ -55,6 +55,7 @@ public class PacketHandler implements IPacketHandler } catch (Exception e) { + e.printStackTrace(); } } } @@ -113,6 +114,7 @@ public class PacketHandler implements IPacketHandler try { + data.writeInt(PacketType.TILE.ordinal()); data.writeInt(tileEntity.xCoord); data.writeInt(tileEntity.yCoord); data.writeInt(tileEntity.zCoord); diff --git a/src/resonantinduction/fx/FXElectricBolt.java b/src/resonantinduction/fx/FXElectricBolt.java index b88a5a6c1..2aa688c9c 100644 --- a/src/resonantinduction/fx/FXElectricBolt.java +++ b/src/resonantinduction/fx/FXElectricBolt.java @@ -61,7 +61,6 @@ public class FXElectricBolt extends EntityFX this.end = new BoltPoint(targetVec); /** By default, we do an electrical color */ - this.setColor(0.5f + (this.rand.nextFloat() * 0.1f), 0.6f + (this.rand.nextFloat() * 0.1f), 1); this.segmentCount = 1; this.particleAge = (3 + this.rand.nextInt(3) - 1); this.particleMaxAge = (3 + this.rand.nextInt(3) - 1); @@ -105,9 +104,9 @@ public class FXElectricBolt extends EntityFX public FXElectricBolt setColor(float r, float g, float b) { - this.particleRed = r; - this.particleGreen = g; - this.particleBlue = b; + this.particleRed = r + (this.rand.nextFloat() * 0.1f) - 0.1f; + this.particleGreen = g + (this.rand.nextFloat() * 0.1f) - 0.1f; + this.particleBlue = b + (this.rand.nextFloat() * 0.1f) - 0.1f; return this; } diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 5944fee64..4f2466977 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -13,19 +13,24 @@ import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import resonantinduction.ITesla; +import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; +import resonantinduction.base.IPacketReceiver; import resonantinduction.base.TileEntityBase; import resonantinduction.base.Vector3; +import com.google.common.io.ByteArrayDataInput; + /** * @author Calclavia * */ -public class TileEntityTesla extends TileEntityBase implements ITesla +public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketReceiver { - public static final Vector3[] dyeColors = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0.5, 0.5, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 0.3, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(0.8, 0.1, 0.2), new Vector3(0.1, 0.8, 0.2), new Vector3(0, 0.8, 0.8), new Vector3(0.1, 0.1, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) }; - private int dyeID = -1; + public static final Vector3[] dyeColors = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0.5, 0.5, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 0.3, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(0.7, 0.2, 0.2), new Vector3(0.1, 0.872, 0.884), new Vector3(0, 0.8, 0.8), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) }; + + private int dyeID = 12; private float energy = 0; private boolean doTransfer = false; @@ -42,10 +47,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla { super.updateEntity(); + boolean doPacketUpdate = this.getEnergyStored() > 0; + /** * Only transfer if it is the bottom controlling Tesla tower. */ - if (this.ticks % 2 == 0 && this.isController() && this.getEnergyStored() > 0 && this.doTransfer && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) + if (this.ticks % 2 == 0 && this.isController() && this.getEnergyStored() > 0 && (this.doTransfer || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) { Set transferTeslaCoils = new HashSet(); @@ -81,15 +88,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla teslaVector = new Vector3(((TileEntityTesla) tesla).getControllingTelsa()); } - if (this.dyeID != -1) - { - ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this.getTopTelsa()).translate(new Vector3(0.5)), teslaVector.translate(new Vector3(0.5)), (float) dyeColors[this.dyeID].x, (float) dyeColors[this.dyeID].y, (float) dyeColors[this.dyeID].z); - } - else - { - ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this.getTopTelsa()).translate(new Vector3(0.5)), teslaVector.translate(new Vector3(0.5))); - } - + ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this.getTopTelsa()).translate(new Vector3(0.5)), teslaVector.translate(new Vector3(0.5)), (float) dyeColors[this.dyeID].x, (float) dyeColors[this.dyeID].y, (float) dyeColors[this.dyeID].z); } } } @@ -150,8 +149,8 @@ public class TileEntityTesla extends TileEntityBase implements ITesla */ boolean doBlockStateUpdate = furnaceTile.furnaceBurnTime > 0; - furnaceTile.furnaceBurnTime++; - this.transfer(-ResonantInduction.POWER_PER_COAL / 22); + furnaceTile.furnaceBurnTime += 2; + this.transfer(-ResonantInduction.POWER_PER_COAL / 20); if (doBlockStateUpdate != furnaceTile.furnaceBurnTime > 0) { @@ -159,12 +158,31 @@ public class TileEntityTesla extends TileEntityBase implements ITesla } } } + + if (this.getEnergyStored() > 0 != doPacketUpdate) + { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } } @Override public Packet getDescriptionPacket() { - return null; + return PacketHandler.getTileEntityPacket(this, this.getEnergyStored(), this.dyeID); + } + + @Override + public void handle(ByteArrayDataInput input) + { + try + { + this.energy = input.readFloat(); + this.dyeID = input.readInt(); + } + catch (Exception e) + { + e.printStackTrace(); + } } private boolean isController() @@ -314,6 +332,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla public void setDye(int id) { this.dyeID = id; + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } /**