diff --git a/src/minecraft/mekanism/common/BlockTransmitter.java b/src/minecraft/mekanism/common/BlockTransmitter.java index 316a5cd24..4ad89b23c 100644 --- a/src/minecraft/mekanism/common/BlockTransmitter.java +++ b/src/minecraft/mekanism/common/BlockTransmitter.java @@ -60,13 +60,13 @@ public class BlockTransmitter extends Block { if(mechanicalPipe.refLiquid.itemID == Block.lavaStill.blockID) { - return (int)(mechanicalPipe.liquidScale*16F); + return (int)(mechanicalPipe.liquidScale*15F); } } } else if(tileEntity instanceof TileEntityUniversalCable) { - return (int)(((TileEntityUniversalCable)tileEntity).liquidScale*16F); + return (int)(((TileEntityUniversalCable)tileEntity).liquidScale*15F); } return 0; diff --git a/src/minecraft/mekanism/common/EnergyTransferProtocol.java b/src/minecraft/mekanism/common/EnergyTransferProtocol.java index 88409efd8..a29e0508d 100644 --- a/src/minecraft/mekanism/common/EnergyTransferProtocol.java +++ b/src/minecraft/mekanism/common/EnergyTransferProtocol.java @@ -10,6 +10,7 @@ import java.util.Map; import cpw.mods.fml.common.FMLCommonHandler; +import mekanism.api.IMechanicalPipe; import mekanism.api.IStrictEnergyAcceptor; import mekanism.api.IUniversalCable; import net.minecraft.tileentity.TileEntity; @@ -135,6 +136,22 @@ public class EnergyTransferProtocol } } + /** + * Updates the client-side cables for rendering. + */ + public void clientUpdate() + { + loopThrough(pointer); + + for(TileEntity tileEntity : iteratedCables) + { + if(tileEntity instanceof IUniversalCable) + { + ((IUniversalCable)tileEntity).onTransfer(); + } + } + } + /** * Runs the protocol and distributes the energy. * @return rejected energy @@ -185,15 +202,9 @@ public class EnergyTransferProtocol } } - if(prevNeeded > 0 && prevSending > 0) + if(prevNeeded > 0 && prevSending > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) { - for(TileEntity tileEntity : iteratedCables) - { - if(tileEntity instanceof IUniversalCable) - { - ((IUniversalCable)tileEntity).onTransfer(); - } - } + PacketHandler.sendEnergyTransferUpdate(pointer); } return energyToSend; diff --git a/src/minecraft/mekanism/common/EnumPacketType.java b/src/minecraft/mekanism/common/EnumPacketType.java index 067116d2b..df5d081f4 100644 --- a/src/minecraft/mekanism/common/EnumPacketType.java +++ b/src/minecraft/mekanism/common/EnumPacketType.java @@ -11,34 +11,58 @@ public enum EnumPacketType { /** Used for sending a time update to the server. Send this along with an int between 0 and 24. */ TIME(0), + /** Used for sending a weather update to the server. Send this along with an EnumWeatherType. */ WEATHER(1), + /** Used for sending a tile entity update to all clients. Send this along with x, y, and z coordinates of the block. */ TILE_ENTITY(2), + /** Used for sending a control panel GUI request to the server. */ CONTROL_PANEL(3), + /** Used to send a portal FX packet to all clients. */ PORTAL_FX(4), + /** Used to send a teleport packet from an ItemStack to the server. */ PORTABLE_TELEPORT(5), + /** Used to send a digit update packet from a portable teleporter to the server. */ DIGIT_UPDATE(6), + /** Used to send a status update packet from a portable teleporter to the client. */ STATUS_UPDATE(7), + /** Used to request data from the server by tile entities. */ DATA_REQUEST(8), + /** Used to change a Configurator's state on the server side. */ CONFIGURATOR_STATE(9), + /** Used to change an Electric Bow's state on the server side. */ ELECTRIC_BOW_STATE(10), + /** Used to open an Electric Chest's GUI on the server side. */ ELECTRIC_CHEST_SERVER_OPEN(11), + /** Used to open an Electric Chest's GUI on the client side. */ ELECTRIC_CHEST_CLIENT_OPEN(12), + /** Used to send a password update packet to the server. */ ELECTRIC_CHEST_PASSWORD(13), + /** Used to send a lock update packet to the server. */ ELECTRIC_CHEST_LOCK(14), + + /** Used to send a liquid transfer update packet to all clients. */ + LIQUID_TRANSFER_UPDATE(15), + + /** Used to send an energy transfer update packet to all clients. */ + ENERGY_TRANSFER_UPDATE(16), + + /** Used to send an electrolytic separator particle to all clients. */ + ELECTROLYTIC_SEPARATOR_PARTICLE(17), + /** A custom packet type. Handled in PacketHandler. */ CUSTOM(-1); diff --git a/src/minecraft/mekanism/common/LiquidTransferProtocol.java b/src/minecraft/mekanism/common/LiquidTransferProtocol.java index 2d97e1c57..525679d4a 100644 --- a/src/minecraft/mekanism/common/LiquidTransferProtocol.java +++ b/src/minecraft/mekanism/common/LiquidTransferProtocol.java @@ -142,6 +142,23 @@ public class LiquidTransferProtocol } } + /** + * Updates the client-side pipes for rendering. + * @param transferred - the LiquidStack of server-side transferred liquid + */ + public void clientUpdate(LiquidStack transferred) + { + loopThrough(pointer); + + for(TileEntity tileEntity : iteratedPipes) + { + if(tileEntity instanceof IMechanicalPipe) + { + ((IMechanicalPipe)tileEntity).onTransfer(transferred); + } + } + } + /** * Runs the protocol and distributes the liquid. * @return liquid transferred @@ -200,17 +217,11 @@ public class LiquidTransferProtocol } } - if(liquidSent > 0) + if(liquidSent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) { - for(TileEntity tileEntity : iteratedPipes) - { - if(tileEntity instanceof IMechanicalPipe) - { - LiquidStack sendStack = liquidToSend.copy(); - sendStack.amount = liquidSent; - ((IMechanicalPipe)tileEntity).onTransfer(sendStack); - } - } + LiquidStack sendStack = liquidToSend.copy(); + sendStack.amount = liquidSent; + PacketHandler.sendLiquidTransferUpdate(pointer, sendStack); } return liquidSent; diff --git a/src/minecraft/mekanism/common/Mekanism.java b/src/minecraft/mekanism/common/Mekanism.java index 6ec4d1467..3d6a4923d 100644 --- a/src/minecraft/mekanism/common/Mekanism.java +++ b/src/minecraft/mekanism/common/Mekanism.java @@ -49,7 +49,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; /** - * Mekanism mod -- adds in Tools, Armor, Weapons, Machines, and Magic. Universal source. + * Mekanism - the mod in which no true definition fits. * @author AidanBrady * */ diff --git a/src/minecraft/mekanism/common/PacketHandler.java b/src/minecraft/mekanism/common/PacketHandler.java index e670ef652..fa45bede5 100644 --- a/src/minecraft/mekanism/common/PacketHandler.java +++ b/src/minecraft/mekanism/common/PacketHandler.java @@ -9,6 +9,7 @@ import java.util.Random; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.item.IItemElectric; +import mekanism.generators.common.TileEntityElectrolyticSeparator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -16,6 +17,8 @@ import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.liquids.LiquidStack; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; @@ -388,6 +391,61 @@ public class PacketHandler implements IPacketHandler e.printStackTrace(); } } + else if(packetType == EnumPacketType.LIQUID_TRANSFER_UPDATE.id) + { + try { + int x = dataStream.readInt(); + int y = dataStream.readInt(); + int z = dataStream.readInt(); + + TileEntity tileEntity = entityplayer.worldObj.getBlockTileEntity(x, y, z); + LiquidStack liquidStack = new LiquidStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt()); + + if(tileEntity != null) + { + new LiquidTransferProtocol(tileEntity, null, liquidStack).clientUpdate(liquidStack); + } + } catch(Exception e) { + System.err.println("[Mekanism] Error while handling liquid transfer update packet."); + e.printStackTrace(); + } + } + else if(packetType == EnumPacketType.ENERGY_TRANSFER_UPDATE.id) + { + try { + int x = dataStream.readInt(); + int y = dataStream.readInt(); + int z = dataStream.readInt(); + + TileEntity tileEntity = entityplayer.worldObj.getBlockTileEntity(x, y, z); + + if(tileEntity != null) + { + new EnergyTransferProtocol(tileEntity, null, new ArrayList()).clientUpdate(); + } + } catch(Exception e) { + System.err.println("[Mekanism] Error while handling energy transfer update packet."); + e.printStackTrace(); + } + } + else if(packetType == EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE.id) + { + try { + int x = dataStream.readInt(); + int y = dataStream.readInt(); + int z = dataStream.readInt(); + + TileEntityElectrolyticSeparator tileEntity = (TileEntityElectrolyticSeparator)entityplayer.worldObj.getBlockTileEntity(x, y, z); + + if(tileEntity != null) + { + tileEntity.spawnParticle(); + } + } catch(Exception e) { + System.err.println("[Mekanism] Error while handling energy transfer update packet."); + e.printStackTrace(); + } + } } catch(Exception e) { System.err.println("[Mekanism] Error while handling packet."); e.printStackTrace(); @@ -520,8 +578,13 @@ public class PacketHandler implements IPacketHandler packet.data = bytes.toByteArray(); packet.length = packet.data.length; - if(distance == 0) PacketDispatcher.sendPacketToAllPlayers(packet); - else PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet); + if(distance == 0) + { + PacketDispatcher.sendPacketToAllPlayers(packet); + } + else { + PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet); + } } catch (IOException e) { System.err.println("[Mekanism] Error while writing tile entity packet."); e.printStackTrace(); @@ -826,6 +889,92 @@ public class PacketHandler implements IPacketHandler } } + /** + * Sends a packet to the client-side with a LiquidTransferProtocol's information. Used for render updates. + * @param head - head TileEntity of the calculation + * @param resource - the LiquidStack transferred by the server + */ + public static void sendLiquidTransferUpdate(TileEntity head, LiquidStack resource) + { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(bytes); + + try { + output.writeInt(EnumPacketType.LIQUID_TRANSFER_UPDATE.id); + + output.writeInt(head.xCoord); + output.writeInt(head.yCoord); + output.writeInt(head.zCoord); + + output.writeInt(resource.itemID); + output.writeInt(resource.amount); + output.writeInt(resource.itemMeta); + + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.channel = "Mekanism"; + packet.data = bytes.toByteArray(); + packet.length = packet.data.length; + PacketDispatcher.sendPacketToAllPlayers(packet); + } catch (IOException e) { + System.err.println("[Mekanism] Error while writing tile entity packet."); + e.printStackTrace(); + } + } + + /** + * Sends a packet to the client-side with an EnergyTransferProtocol's information. Used for render updates. + * @param head - head TileEntity of the calculation + */ + public static void sendEnergyTransferUpdate(TileEntity head) + { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(bytes); + + try { + output.writeInt(EnumPacketType.ENERGY_TRANSFER_UPDATE.id); + + output.writeInt(head.xCoord); + output.writeInt(head.yCoord); + output.writeInt(head.zCoord); + + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.channel = "Mekanism"; + packet.data = bytes.toByteArray(); + packet.length = packet.data.length; + PacketDispatcher.sendPacketToAllPlayers(packet); + } catch (IOException e) { + System.err.println("[Mekanism] Error while writing tile entity packet."); + e.printStackTrace(); + } + } + + /** + * Sends a request to clients near an Electrolytic Separator to emit a gas dump particle. + * @param tileEntity - TileEntity who is emitting the particle + */ + public static void sendElectrolyticSeparatorParticle(TileEntityElectrolyticSeparator tileEntity) + { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(bytes); + + try { + output.writeInt(EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE.id); + + output.writeInt(tileEntity.xCoord); + output.writeInt(tileEntity.yCoord); + output.writeInt(tileEntity.zCoord); + + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.channel = "Mekanism"; + packet.data = bytes.toByteArray(); + packet.length = packet.data.length; + PacketDispatcher.sendPacketToAllAround(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 40, tileEntity.worldObj.provider.dimensionId, packet); + } catch (IOException e) { + System.err.println("[Mekanism] Error while writing tile entity packet."); + e.printStackTrace(); + } + } + /** * Sends the server the defined packet data int. * @param type - packet type diff --git a/src/minecraft/mekanism/common/TileEntityElectricPump.java b/src/minecraft/mekanism/common/TileEntityElectricPump.java index 1a247ed61..b64687cd4 100644 --- a/src/minecraft/mekanism/common/TileEntityElectricPump.java +++ b/src/minecraft/mekanism/common/TileEntityElectricPump.java @@ -47,11 +47,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I /** The nodes that have already been sucked up, but are held on to in order to remove dead blocks */ public Set cleaningNodes = new HashSet(); - /** Random for this pump */ - public Random random = new Random(); - - public boolean prevEmpty; - public TileEntityElectricPump() { super("Electric Pump", 10000); @@ -121,16 +116,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I super.onUpdate(); - if(!worldObj.isRemote) - { - if(prevEmpty != (liquidTank.getLiquid() == null || liquidTank.getLiquid().amount == 0)) - { - PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList())); - } - - prevEmpty = liquidTank.getLiquid() == null; - } - if(liquidTank.getLiquid() != null) { for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) diff --git a/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java b/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java index 9fb600da4..1834fc0e2 100644 --- a/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java +++ b/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java @@ -25,8 +25,6 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP { public LiquidTank dummyTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME); - public LiquidStack prevLiquid; - public LiquidStack refLiquid = null; public boolean isActive = false; @@ -58,16 +56,14 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP @Override public void updateEntity() { - if(!worldObj.isRemote) + if(worldObj.isRemote) { - if(liquidScale != prevScale || refLiquid != prevLiquid) + if(liquidScale != prevScale) { worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); - PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList())); } prevScale = liquidScale; - prevLiquid = refLiquid; if(liquidScale > 0) { @@ -76,7 +72,8 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP else { refLiquid = null; } - + } + else { if(isActive) { ITankContainer[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this); diff --git a/src/minecraft/mekanism/common/TileEntityUniversalCable.java b/src/minecraft/mekanism/common/TileEntityUniversalCable.java index f2fd1c21d..8ae9ca925 100644 --- a/src/minecraft/mekanism/common/TileEntityUniversalCable.java +++ b/src/minecraft/mekanism/common/TileEntityUniversalCable.java @@ -2,25 +2,20 @@ package mekanism.common; import java.util.ArrayList; -import com.google.common.io.ByteArrayDataInput; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - +import mekanism.api.IUniversalCable; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerProvider; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.LiquidContainerRegistry; -import net.minecraftforge.liquids.LiquidStack; -import mekanism.api.IUniversalCable; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor, ITileNetwork +public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor { public CablePowerProvider powerProvider; @@ -40,12 +35,11 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa @Override public void updateEntity() { - if(!worldObj.isRemote) + if(worldObj.isRemote) { if(liquidScale != prevScale) { worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); - PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList())); } prevScale = liquidScale; @@ -57,30 +51,6 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa } } - @Override - public void validate() - { - super.validate(); - - if(worldObj.isRemote) - { - PacketHandler.sendDataRequest(this); - } - } - - @Override - public void handlePacketData(ByteArrayDataInput dataStream) - { - liquidScale = dataStream.readFloat(); - } - - @Override - public ArrayList getNetworkedData(ArrayList data) - { - data.add(liquidScale); - return data; - } - @Override public boolean canTransferEnergy(TileEntity fromTile) { diff --git a/src/minecraft/mekanism/generators/common/TileEntityElectrolyticSeparator.java b/src/minecraft/mekanism/generators/common/TileEntityElectrolyticSeparator.java index 71c2d509e..091c27522 100644 --- a/src/minecraft/mekanism/generators/common/TileEntityElectrolyticSeparator.java +++ b/src/minecraft/mekanism/generators/common/TileEntityElectrolyticSeparator.java @@ -6,6 +6,7 @@ import ic2.api.IElectricItem; import ic2.api.energy.tile.IEnergySink; import java.util.ArrayList; +import java.util.Random; import mekanism.api.EnumGas; import mekanism.api.GasTransmission; @@ -65,12 +66,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp /** Type type of gas this block is dumping. */ public EnumGas dumpType; - - /** Previous tank full state. */ - public boolean prevTankFull; - - /** Previous tank empty state. */ - public boolean prevTankEmpty; public TileEntityElectrolyticSeparator() { @@ -209,23 +204,15 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp } } - if(prevTankFull != (waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity()) || prevTankEmpty != (waterTank.getLiquid() == null || waterTank.getLiquid().amount == 0)) - { - PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList())); - } - - prevTankFull = waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity(); - prevTankEmpty = waterTank.getLiquid() == null; - } - - if(dumpType != EnumGas.NONE && getGas(dumpType) > 0) - { - if(!worldObj.isRemote) + if(dumpType != EnumGas.NONE && getGas(dumpType) > 0) { setGas(dumpType, (getGas(dumpType) - 8)); + + if(new Random().nextInt(3) == 2) + { + PacketHandler.sendElectrolyticSeparatorParticle(this); + } } - - spawnParticle(); } } diff --git a/src/minecraft/mekanism/generators/common/TileEntityHeatGenerator.java b/src/minecraft/mekanism/generators/common/TileEntityHeatGenerator.java index 89710fd24..16713b784 100644 --- a/src/minecraft/mekanism/generators/common/TileEntityHeatGenerator.java +++ b/src/minecraft/mekanism/generators/common/TileEntityHeatGenerator.java @@ -37,12 +37,6 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan /** The amount of electricity this machine can produce with a unit of fuel. */ public final int GENERATION = 80; - /** Previous tank full state. */ - public boolean prevTankFull; - - /** Previous tank empty state. */ - public boolean prevTankEmpty; - public TileEntityHeatGenerator() { super("Heat Generator", 160000, 160); @@ -113,14 +107,6 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan else { setActive(false); } - - if(prevTankFull != (lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity()) || prevTankEmpty != (lavaTank.getLiquid() == null || lavaTank.getLiquid().amount == 0)) - { - PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList())); - } - - prevTankFull = lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity(); - prevTankEmpty = lavaTank.getLiquid() == null; } }