diff --git a/bin/minecraft/mods/mekanism/render/PressurizedTube.png b/bin/minecraft/mods/mekanism/render/PressurizedTube.png index 011001f2e..f0aebe3a2 100644 Binary files a/bin/minecraft/mods/mekanism/render/PressurizedTube.png and b/bin/minecraft/mods/mekanism/render/PressurizedTube.png differ diff --git a/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.png b/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.png new file mode 100644 index 000000000..cc8dfe6b0 Binary files /dev/null and b/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.png differ diff --git a/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.txt b/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.txt new file mode 100644 index 000000000..0af6f629f --- /dev/null +++ b/bin/minecraft/mods/mekanism/textures/items/LiquidHydrogen.txt @@ -0,0 +1,32 @@ +0*2 +1*2 +2*2 +3*2 +4*2 +5*2 +6*2 +7*2 +8*2 +9*2 +10*2 +11*2 +12*2 +13*2 +14*2 +15*2 +16*2 +17*2 +18*2 +19*2 +20*2 +21*2 +22*2 +23*2 +24*2 +25*2 +26*2 +27*2 +28*2 +29*2 +30*2 +31*2 \ No newline at end of file diff --git a/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.png b/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.png new file mode 100644 index 000000000..8ace07917 Binary files /dev/null and b/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.png differ diff --git a/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.txt b/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.txt new file mode 100644 index 000000000..0af6f629f --- /dev/null +++ b/bin/minecraft/mods/mekanism/textures/items/LiquidOxygen.txt @@ -0,0 +1,32 @@ +0*2 +1*2 +2*2 +3*2 +4*2 +5*2 +6*2 +7*2 +8*2 +9*2 +10*2 +11*2 +12*2 +13*2 +14*2 +15*2 +16*2 +17*2 +18*2 +19*2 +20*2 +21*2 +22*2 +23*2 +24*2 +25*2 +26*2 +27*2 +28*2 +29*2 +30*2 +31*2 \ No newline at end of file diff --git a/src/minecraft/mekanism/api/EnumGas.java b/src/minecraft/mekanism/api/EnumGas.java index b43edfb30..aa133036a 100644 --- a/src/minecraft/mekanism/api/EnumGas.java +++ b/src/minecraft/mekanism/api/EnumGas.java @@ -1,5 +1,7 @@ package mekanism.api; +import net.minecraft.item.Item; + /** * The gasses currently available in Mekanism. * @author AidanBrady @@ -7,11 +9,13 @@ package mekanism.api; */ public enum EnumGas { - NONE("None"), - OXYGEN("Oxygen"), - HYDROGEN("Hydrogen"); + NONE("None", null, null), + OXYGEN("Oxygen", null, null), + HYDROGEN("Hydrogen", null, null); public String name; + public Item gasItem; + public String texturePath; public static EnumGas getFromName(String gasName) { @@ -27,8 +31,15 @@ public enum EnumGas return NONE; } - private EnumGas(String s) + public boolean hasTexture() + { + return gasItem != null && texturePath != null; + } + + private EnumGas(String s, Item item, String path) { name = s; + gasItem = item; + texturePath = path; } } diff --git a/src/minecraft/mekanism/api/GasTransferProtocol.java b/src/minecraft/mekanism/api/GasTransferProtocol.java index 82444b94e..4c39f3ee2 100644 --- a/src/minecraft/mekanism/api/GasTransferProtocol.java +++ b/src/minecraft/mekanism/api/GasTransferProtocol.java @@ -4,6 +4,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import cpw.mods.fml.common.FMLCommonHandler; + +import mekanism.common.PacketHandler; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; @@ -70,7 +73,10 @@ public class GasTransferProtocol } } - iteratedTubes.add(tile); + if(!iteratedTubes.contains(tile)) + { + iteratedTubes.add(tile); + } TileEntity[] tubes = GasTransmission.getConnectedTubes(tile); @@ -86,6 +92,22 @@ public class GasTransferProtocol } } + /** + * Updates the client-side tubes for rendering. + */ + public void clientUpdate() + { + loopThrough(pointer); + + for(TileEntity tileEntity : iteratedTubes) + { + if(tileEntity instanceof IPressurizedTube) + { + ((IPressurizedTube)tileEntity).onTransfer(transferType); + } + } + } + /** * Runs the protocol and distributes the gas. * @return rejected gas @@ -96,6 +118,8 @@ public class GasTransferProtocol Collections.shuffle(availableAcceptors); + int prevSending = gasToSend; + if(!availableAcceptors.isEmpty()) { int divider = availableAcceptors.size(); @@ -116,6 +140,11 @@ public class GasTransferProtocol } } + if(prevSending > gasToSend && FMLCommonHandler.instance().getEffectiveSide().isServer()) + { + PacketHandler.sendGasTransferUpdate(pointer, transferType); + } + return gasToSend; } } diff --git a/src/minecraft/mekanism/api/IPressurizedTube.java b/src/minecraft/mekanism/api/IPressurizedTube.java index eebb07cb7..8d603993f 100644 --- a/src/minecraft/mekanism/api/IPressurizedTube.java +++ b/src/minecraft/mekanism/api/IPressurizedTube.java @@ -9,4 +9,10 @@ public interface IPressurizedTube * @return if the tube can transfer gas */ public boolean canTransferGas(TileEntity fromTile); + + /** + * Called when a gas is transferred through this tube. + * @param type - the type of gas transferred + */ + public void onTransfer(EnumGas type); } diff --git a/src/minecraft/mekanism/client/RenderPressurizedTube.java b/src/minecraft/mekanism/client/RenderPressurizedTube.java index d985ed0ec..d22eeee6d 100644 --- a/src/minecraft/mekanism/client/RenderPressurizedTube.java +++ b/src/minecraft/mekanism/client/RenderPressurizedTube.java @@ -1,25 +1,36 @@ package mekanism.client; import java.util.Arrays; +import java.util.HashMap; + +import mekanism.api.EnumGas; +import mekanism.api.GasTransmission; +import mekanism.api.ITubeConnection; +import mekanism.client.ObjectRenderer.Object3D; +import mekanism.common.TileEntityPressurizedTube; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraftforge.common.ForgeDirection; - -import mekanism.api.GasTransmission; -import mekanism.api.ITubeConnection; -import mekanism.common.TileEntityPressurizedTube; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; - @SideOnly(Side.CLIENT) public class RenderPressurizedTube extends TileEntitySpecialRenderer { private ModelTransmitter model = new ModelTransmitter(); + private HashMap> cachedGasses = new HashMap>(); + + private static final int stages = 40; + + private static final double offset = 0.015; + @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) { @@ -33,6 +44,8 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glScalef(1.0F, -1F, -1F); + boolean[] connectable = new boolean[] {false, false, false, false, false, false}; + ITubeConnection[] connections = GasTransmission.getConnections(tileEntity); for(ITubeConnection connection : connections) @@ -43,12 +56,220 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer if(connection.canTubeConnect(ForgeDirection.getOrientation(side).getOpposite())) { - model.renderSide(ForgeDirection.getOrientation(side)); + connectable[side] = true; } } } + for(int i = 0; i < 6; i++) + { + if(connectable[i]) + { + model.renderSide(ForgeDirection.getOrientation(i)); + } + } + model.Center.render(0.0625F); GL11.glPopMatrix(); + + if(tileEntity.gasScale > 0 && tileEntity.refGas != null && tileEntity.refGas.hasTexture()) + { + GL11.glPushMatrix(); + GL11.glDisable(2896); + bindTextureByName(tileEntity.refGas.texturePath); + GL11.glTranslatef((float)x, (float)y, (float)z); + + for(int i = 0; i < 6; i++) + { + if(connectable[i]) + { + int[] displayList = getListAndRender(ForgeDirection.getOrientation(i), tileEntity.refGas, tileEntity.worldObj); + GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.gasScale*(stages-1)))]); + } + } + + int[] displayList = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refGas, tileEntity.worldObj); + GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.gasScale*(stages-1)))]); + + GL11.glEnable(2896); + GL11.glPopMatrix(); + } + } + + private int[] getListAndRender(ForgeDirection side, EnumGas type, World world) + { + if(cachedGasses.containsKey(side) && cachedGasses.get(side).containsKey(type)) + { + return cachedGasses.get(side).get(type); + } + + Object3D toReturn = new Object3D(); + toReturn.baseBlock = Block.waterStill; + toReturn.texture = type.gasItem.getIconFromDamage(0); + + int[] displays = new int[stages]; + + if(cachedGasses.containsKey(side)) + { + cachedGasses.get(side).put(type, displays); + } + else { + HashMap map = new HashMap(); + map.put(type, displays); + cachedGasses.put(side, map); + } + + switch(side) + { + case UNKNOWN: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.3 + offset; + toReturn.minY = 0.3 + offset; + toReturn.minZ = 0.3 + offset; + + toReturn.maxX = 0.7 - offset; + toReturn.maxY = 0.3 - offset + ((float)i / (float)100); + toReturn.maxZ = 0.7 - offset; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case DOWN: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.5 + offset - ((float)i / (float)100)/2; + toReturn.minY = 0.0; + toReturn.minZ = 0.5 + offset - ((float)i / (float)100)/2; + + toReturn.maxX = 0.5 - offset + ((float)i / (float)100)/2; + toReturn.maxY = 0.3 + offset; + toReturn.maxZ = 0.5 - offset + ((float)i / (float)100)/2; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case UP: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.5 + offset - ((float)i / (float)100)/2; + toReturn.minY = 0.3 - offset + ((float)i / (float)100); + toReturn.minZ = 0.5 + offset - ((float)i / (float)100)/2; + + toReturn.maxX = 0.5 - offset + ((float)i / (float)100)/2; + toReturn.maxY = 1.0; + toReturn.maxZ = 0.5 - offset + ((float)i / (float)100)/2; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case NORTH: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.3 + offset; + toReturn.minY = 0.3 + offset; + toReturn.minZ = 0.0; + + toReturn.maxX = 0.7 - offset; + toReturn.maxY = 0.3 - offset + ((float)i / (float)100); + toReturn.maxZ = 0.3 + offset; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case SOUTH: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.3 + offset; + toReturn.minY = 0.3 + offset; + toReturn.minZ = 0.7 - offset; + + toReturn.maxX = 0.7 - offset; + toReturn.maxY = 0.3 - offset + ((float)i / (float)100); + toReturn.maxZ = 1.0; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case WEST: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.0; + toReturn.minY = 0.3 + offset; + toReturn.minZ = 0.3 + offset; + + toReturn.maxX = 0.3 + offset; + toReturn.maxY = 0.3 - offset + ((float)i / (float)100); + toReturn.maxZ = 0.7 - offset; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + case EAST: + { + for(int i = 0; i < stages; i++) + { + displays[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displays[i], 4864); + + toReturn.minX = 0.7 - offset; + toReturn.minY = 0.3 + offset; + toReturn.minZ = 0.3 + offset; + + toReturn.maxX = 1.0; + toReturn.maxY = 0.3 - offset + ((float)i / (float)100); + toReturn.maxZ = 0.7 - offset; + + ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true); + GL11.glEndList(); + } + + return displays; + } + } + + return null; } } diff --git a/src/minecraft/mekanism/client/RenderUniversalCable.java b/src/minecraft/mekanism/client/RenderUniversalCable.java index 89e0c0ba9..ad4a0e4cb 100644 --- a/src/minecraft/mekanism/client/RenderUniversalCable.java +++ b/src/minecraft/mekanism/client/RenderUniversalCable.java @@ -92,7 +92,7 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer model.Center.render(0.0625F); GL11.glPopMatrix(); - if(tileEntity.liquidScale > 0) + if(tileEntity.energyScale > 0) { GL11.glPushMatrix(); GL11.glDisable(2896); @@ -104,12 +104,12 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer if(connectable[i]) { int[] displayList = getListAndRender(ForgeDirection.getOrientation(i), tileEntity.worldObj); - GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.liquidScale*(stages-1)))]); + GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.energyScale*(stages-1)))]); } } int[] displayList = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.worldObj); - GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.liquidScale*(stages-1)))]); + GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.energyScale*(stages-1)))]); GL11.glEnable(2896); GL11.glPopMatrix(); diff --git a/src/minecraft/mekanism/common/BlockTransmitter.java b/src/minecraft/mekanism/common/BlockTransmitter.java index 4ad89b23c..39ab649e9 100644 --- a/src/minecraft/mekanism/common/BlockTransmitter.java +++ b/src/minecraft/mekanism/common/BlockTransmitter.java @@ -66,7 +66,7 @@ public class BlockTransmitter extends Block } else if(tileEntity instanceof TileEntityUniversalCable) { - return (int)(((TileEntityUniversalCable)tileEntity).liquidScale*15F); + return (int)(((TileEntityUniversalCable)tileEntity).energyScale*15F); } return 0; diff --git a/src/minecraft/mekanism/common/EnergyTransferProtocol.java b/src/minecraft/mekanism/common/EnergyTransferProtocol.java index a29e0508d..2c82f0c88 100644 --- a/src/minecraft/mekanism/common/EnergyTransferProtocol.java +++ b/src/minecraft/mekanism/common/EnergyTransferProtocol.java @@ -162,7 +162,6 @@ public class EnergyTransferProtocol Collections.shuffle(availableAcceptors); - double prevNeeded = neededEnergy(); double prevSending = energyToSend; if(!availableAcceptors.isEmpty()) @@ -202,7 +201,7 @@ public class EnergyTransferProtocol } } - if(prevNeeded > 0 && prevSending > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) + if(prevSending > energyToSend && FMLCommonHandler.instance().getEffectiveSide().isServer()) { PacketHandler.sendEnergyTransferUpdate(pointer); } diff --git a/src/minecraft/mekanism/common/EnumPacketType.java b/src/minecraft/mekanism/common/EnumPacketType.java index df5d081f4..d370f7351 100644 --- a/src/minecraft/mekanism/common/EnumPacketType.java +++ b/src/minecraft/mekanism/common/EnumPacketType.java @@ -60,8 +60,11 @@ public enum EnumPacketType /** Used to send an energy transfer update packet to all clients. */ ENERGY_TRANSFER_UPDATE(16), + /** Used to send a gas transfer update packet to all clients. */ + GAS_TRANSFER_UPDATE(17), + /** Used to send an electrolytic separator particle to all clients. */ - ELECTROLYTIC_SEPARATOR_PARTICLE(17), + ELECTROLYTIC_SEPARATOR_PARTICLE(18), /** 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 525679d4a..90cdd90fe 100644 --- a/src/minecraft/mekanism/common/LiquidTransferProtocol.java +++ b/src/minecraft/mekanism/common/LiquidTransferProtocol.java @@ -126,7 +126,10 @@ public class LiquidTransferProtocol } } - iteratedPipes.add(tile); + if(!iteratedPipes.contains(tile)) + { + iteratedPipes.add(tile); + } TileEntity[] pipes = PipeUtils.getConnectedPipes(tile); @@ -146,7 +149,7 @@ public class LiquidTransferProtocol * Updates the client-side pipes for rendering. * @param transferred - the LiquidStack of server-side transferred liquid */ - public void clientUpdate(LiquidStack transferred) + public void clientUpdate() { loopThrough(pointer); @@ -154,7 +157,7 @@ public class LiquidTransferProtocol { if(tileEntity instanceof IMechanicalPipe) { - ((IMechanicalPipe)tileEntity).onTransfer(transferred); + ((IMechanicalPipe)tileEntity).onTransfer(liquidToSend); } } } diff --git a/src/minecraft/mekanism/common/Mekanism.java b/src/minecraft/mekanism/common/Mekanism.java index 3d6a4923d..4505d2f90 100644 --- a/src/minecraft/mekanism/common/Mekanism.java +++ b/src/minecraft/mekanism/common/Mekanism.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.logging.Logger; +import mekanism.api.EnumGas; import mekanism.api.InfuseObject; import mekanism.api.InfusionInput; import mekanism.api.InfusionType; @@ -127,6 +128,8 @@ public class Mekanism public static Item TeleportationCore; public static Item Configurator; public static Item LiquidEnergy; + public static Item LiquidHydrogen; + public static Item LiquidOxygen; //Blocks public static Block BasicBlock; @@ -431,6 +434,8 @@ public class Mekanism LanguageRegistry.addName(TeleportationCore, "Teleportation Core"); LanguageRegistry.addName(Configurator, "Configurator"); LanguageRegistry.addName(LiquidEnergy, "Liquid Energy"); + LanguageRegistry.addName(LiquidHydrogen, "Liquid Hydrogen"); + LanguageRegistry.addName(LiquidOxygen, "Liquid Oxygen"); //Localization for BasicBlock LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.OsmiumBlock.name", "Osmium Block"); @@ -545,6 +550,8 @@ public class Mekanism Clump = new ItemClump(configuration.getItem("Clump", 11219).getInt()-256); DirtyDust = new ItemDirtyDust(configuration.getItem("DirtyDust", 11220).getInt()-256); Configurator = new ItemConfigurator(configuration.getItem("Configurator", 11221).getInt()).setUnlocalizedName("Configurator"); + LiquidHydrogen = new ItemMekanism(configuration.getItem("LiquidHydrogen", 11222).getInt()).setUnlocalizedName("LiquidHydrogen").setCreativeTab(null); + LiquidOxygen = new ItemMekanism(configuration.getItem("LiquidOxygen", 11223).getInt()).setUnlocalizedName("LiquidOxygen").setCreativeTab(null); configuration.save(); //Registrations @@ -574,6 +581,8 @@ public class Mekanism GameRegistry.registerItem(Clump, "Clump"); GameRegistry.registerItem(DirtyDust, "DirtyDust"); GameRegistry.registerItem(Configurator, "Configurator"); + GameRegistry.registerItem(LiquidHydrogen, "LiquidHydrogen"); + GameRegistry.registerItem(LiquidOxygen, "LiquidOxygen"); } /** @@ -1001,6 +1010,18 @@ public class Mekanism hooks.hook(); addIntegratedItems(); + if(!EnumGas.HYDROGEN.hasTexture()) + { + EnumGas.HYDROGEN.gasItem = LiquidHydrogen; + EnumGas.HYDROGEN.texturePath = "/mods/mekanism/textures/items/LiquidHydrogen.png"; + } + + if(!EnumGas.OXYGEN.hasTexture()) + { + EnumGas.OXYGEN.gasItem = LiquidOxygen; + EnumGas.OXYGEN.texturePath = "/mods/mekanism/textures/items/LiquidOxygen.png"; + } + System.out.println("[Mekanism] Hooking complete."); proxy.loadSoundHandler(); diff --git a/src/minecraft/mekanism/common/PacketHandler.java b/src/minecraft/mekanism/common/PacketHandler.java index fa45bede5..3b78a1628 100644 --- a/src/minecraft/mekanism/common/PacketHandler.java +++ b/src/minecraft/mekanism/common/PacketHandler.java @@ -9,6 +9,8 @@ import java.util.Random; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.item.IItemElectric; +import mekanism.api.EnumGas; +import mekanism.api.GasTransferProtocol; import mekanism.generators.common.TileEntityElectrolyticSeparator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -403,7 +405,7 @@ public class PacketHandler implements IPacketHandler if(tileEntity != null) { - new LiquidTransferProtocol(tileEntity, null, liquidStack).clientUpdate(liquidStack); + new LiquidTransferProtocol(tileEntity, null, liquidStack).clientUpdate(); } } catch(Exception e) { System.err.println("[Mekanism] Error while handling liquid transfer update packet."); @@ -428,6 +430,26 @@ public class PacketHandler implements IPacketHandler e.printStackTrace(); } } + else if(packetType == EnumPacketType.GAS_TRANSFER_UPDATE.id) + { + try { + int x = dataStream.readInt(); + int y = dataStream.readInt(); + int z = dataStream.readInt(); + + EnumGas type = EnumGas.getFromName(dataStream.readUTF()); + + TileEntity tileEntity = entityplayer.worldObj.getBlockTileEntity(x, y, z); + + if(tileEntity != null) + { + new GasTransferProtocol(tileEntity, null, type, 0).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 { @@ -916,7 +938,7 @@ public class PacketHandler implements IPacketHandler packet.length = packet.data.length; PacketDispatcher.sendPacketToAllPlayers(packet); } catch (IOException e) { - System.err.println("[Mekanism] Error while writing tile entity packet."); + System.err.println("[Mekanism] Error while writing liquid transfer update packet."); e.printStackTrace(); } } @@ -943,7 +965,36 @@ public class PacketHandler implements IPacketHandler packet.length = packet.data.length; PacketDispatcher.sendPacketToAllPlayers(packet); } catch (IOException e) { - System.err.println("[Mekanism] Error while writing tile entity packet."); + System.err.println("[Mekanism] Error while writing energy transfer update packet."); + e.printStackTrace(); + } + } + + /** + * Sends a packet to the client-side with a GasTransferProtocol's information. Used for render updates. + * @param head - head TileEntity of the calculation + */ + public static void sendGasTransferUpdate(TileEntity head, EnumGas type) + { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(bytes); + + try { + output.writeInt(EnumPacketType.GAS_TRANSFER_UPDATE.id); + + output.writeInt(head.xCoord); + output.writeInt(head.yCoord); + output.writeInt(head.zCoord); + + output.writeUTF(type.name); + + 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 gas transfer update packet."); e.printStackTrace(); } } diff --git a/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java b/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java index 1834fc0e2..8859a36bb 100644 --- a/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java +++ b/src/minecraft/mekanism/common/TileEntityMechanicalPipe.java @@ -23,14 +23,19 @@ import cpw.mods.fml.relauncher.SideOnly; public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalPipe, ITankContainer, ITileNetwork { + /** The fake tank used for liquid transfer calculations. */ public LiquidTank dummyTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME); + /** The LiquidStack displayed on this pipe. */ public LiquidStack refLiquid = null; + /** This pipe's active state. */ public boolean isActive = false; + /** The scale (0F -> 1F) of this pipe's liquid level. */ public float liquidScale; + /** Previous scale for this pipe's liquid level. */ public float prevScale; @Override @@ -44,12 +49,12 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP { if(liquidStack.isLiquidEqual(refLiquid)) { - liquidScale = Math.min(1, liquidScale+((float)liquidStack.amount/(float)3000)); + liquidScale = Math.min(1, liquidScale+((float)liquidStack.amount/50F)); } else if(refLiquid == null) { refLiquid = liquidStack.copy(); - liquidScale += Math.min(1, (float)liquidStack.amount/(float)3000); + liquidScale += Math.min(1, ((float)liquidStack.amount/50F)); } } diff --git a/src/minecraft/mekanism/common/TileEntityPressurizedTube.java b/src/minecraft/mekanism/common/TileEntityPressurizedTube.java index 109d23cd4..d905a2ab4 100644 --- a/src/minecraft/mekanism/common/TileEntityPressurizedTube.java +++ b/src/minecraft/mekanism/common/TileEntityPressurizedTube.java @@ -2,6 +2,7 @@ package mekanism.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import mekanism.api.EnumGas; import mekanism.api.IPressurizedTube; import mekanism.api.ITubeConnection; import net.minecraft.tileentity.TileEntity; @@ -10,12 +11,47 @@ import net.minecraftforge.common.ForgeDirection; public class TileEntityPressurizedTube extends TileEntity implements IPressurizedTube, ITubeConnection { + /** The gas currently displayed in this tube. */ + public EnumGas refGas = null; + + /** The scale of the gas (0F -> 1F) currently inside this tube. */ + public float gasScale; + + @Override + public void updateEntity() + { + if(worldObj.isRemote) + { + if(gasScale > 0) + { + gasScale -= .01; + } + else { + refGas = null; + } + } + } + @Override public boolean canTransferGas(TileEntity fromTile) { return worldObj.getBlockPowerInput(xCoord, yCoord, zCoord) == 0; } + @Override + public void onTransfer(EnumGas type) + { + if(type == refGas) + { + gasScale = Math.min(1, gasScale+.02F); + } + else if(refGas == null) + { + refGas = type; + gasScale += Math.min(1, gasScale+.02F); + } + } + @Override public boolean canTubeConnect(ForgeDirection side) { @@ -25,7 +61,7 @@ public class TileEntityPressurizedTube extends TileEntity implements IPressurize @Override public boolean canUpdate() { - return false; + return true; } @Override diff --git a/src/minecraft/mekanism/common/TileEntityUniversalCable.java b/src/minecraft/mekanism/common/TileEntityUniversalCable.java index 8ae9ca925..9e5fb6a7f 100644 --- a/src/minecraft/mekanism/common/TileEntityUniversalCable.java +++ b/src/minecraft/mekanism/common/TileEntityUniversalCable.java @@ -17,10 +17,13 @@ import cpw.mods.fml.relauncher.SideOnly; public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor { + /** A fake power provider used to initiate energy transfer calculations. */ public CablePowerProvider powerProvider; - public float liquidScale; + /** The scale of the energy (0F -> 1F) currently inside this cable. */ + public float energyScale; + /** This cable's previous energy scale state. */ public float prevScale; public TileEntityUniversalCable() @@ -37,16 +40,16 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa { if(worldObj.isRemote) { - if(liquidScale != prevScale) + if(energyScale != prevScale) { worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); } - prevScale = liquidScale; + prevScale = energyScale; - if(liquidScale > 0) + if(energyScale > 0) { - liquidScale -= .01; + energyScale -= .01; } } } @@ -60,7 +63,7 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa @Override public void onTransfer() { - liquidScale = Math.min(1, liquidScale+.02F); + energyScale = Math.min(1, energyScale+.02F); } @Override diff --git a/src/minecraft/mekanism/nei/NEIMekanismConfig.java b/src/minecraft/mekanism/nei/NEIMekanismConfig.java index c4816428b..1aae614dc 100644 --- a/src/minecraft/mekanism/nei/NEIMekanismConfig.java +++ b/src/minecraft/mekanism/nei/NEIMekanismConfig.java @@ -39,6 +39,8 @@ public class NEIMekanismConfig implements IConfigureNEI API.hideItem(Mekanism.boundingBlockID); API.hideItem(Mekanism.LiquidEnergy.itemID); + API.hideItem(Mekanism.LiquidHydrogen.itemID); + API.hideItem(Mekanism.LiquidOxygen.itemID); } @Override