diff --git a/src/main/java/com/pahimar/ee3/helper/ColourUtils.java b/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java similarity index 53% rename from src/main/java/com/pahimar/ee3/helper/ColourUtils.java rename to src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java index aa7e0f1b..060c968e 100644 --- a/src/main/java/com/pahimar/ee3/helper/ColourUtils.java +++ b/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java @@ -1,4 +1,4 @@ -package com.pahimar.ee3.helper; +package com.pahimar.ee3.client.helper; import java.util.regex.Pattern; @@ -6,23 +6,6 @@ public class ColourUtils { private static final Pattern HEX_COLOUR_PATTERN = Pattern.compile("[0-9a-fA-F]{6}"); - @SuppressWarnings("unused") - public static byte[] convertHexColorToByteArray(String hexColor) - { - if (HEX_COLOUR_PATTERN.matcher(hexColor).matches()) - { - byte[] colourByteArray = new byte[3]; - - colourByteArray[0] = (byte) Integer.parseInt(hexColor.substring(0, 2), 16); - colourByteArray[1] = (byte) Integer.parseInt(hexColor.substring(2, 4), 16); - colourByteArray[2] = (byte) Integer.parseInt(hexColor.substring(4, 6), 16); - - return colourByteArray; - } - - return null; - } - public static byte[] convertIntColourToByteArray(int intColour) { byte[] colourByteArray = new byte[3]; @@ -45,63 +28,6 @@ public class ColourUtils return colourFloatArray; } - public static float[] convertByteArrayToFloatArray(byte[] byteArray) - { - float[] colourFloatArray = new float[3]; - - colourFloatArray[0] = (float) byteArray[0] / 255F; - colourFloatArray[1] = (float) byteArray[1] / 255F; - colourFloatArray[2] = (float) byteArray[2] / 255F; - - return colourFloatArray; - } - - @SuppressWarnings("unused") - public static byte[] getBlendedColours(String firstColour, String secondColour) - { - byte[] firstColourByteArray = convertHexColorToByteArray(firstColour); - byte[] secondColourByteArray = convertHexColorToByteArray(secondColour); - - if (firstColourByteArray != null && secondColourByteArray != null) - { - return getBlendedColours(firstColourByteArray, secondColourByteArray); - } - else - { - return null; - } - } - - @SuppressWarnings("unused") - public static byte[] getBlendedColours(byte[] firstColour, byte[] secondColour) - { - byte[][] blendedColours = getByteBlendedColours(firstColour, secondColour, 3); - - if (blendedColours.length == 3) - { - return blendedColours[1]; - } - else - { - return null; - } - } - - public static byte[][] getByteBlendedColours(String firstColour, String secondColour, int steps) - { - byte[] firstColourByteArray = convertHexColorToByteArray(firstColour); - byte[] secondColourByteArray = convertHexColorToByteArray(secondColour); - - if (firstColourByteArray != null && secondColourByteArray != null) - { - return getByteBlendedColours(firstColourByteArray, secondColourByteArray, steps); - } - else - { - return null; - } - } - public static byte[][] getByteBlendedColours(byte[] firstColour, byte[] secondColour, int steps) { if (firstColour.length == 3 && secondColour.length == 3 && steps > 0) @@ -150,21 +76,6 @@ public class ColourUtils } } - public static float[][] getFloatBlendedColours(String firstColour, String secondColour, int steps) - { - byte[] firstColourByteArray = convertHexColorToByteArray(firstColour); - byte[] secondColourByteArray = convertHexColorToByteArray(secondColour); - - if (firstColourByteArray != null && secondColourByteArray != null) - { - return getFloatBlendedColours(firstColourByteArray, secondColourByteArray, steps); - } - else - { - return null; - } - } - public static float[][] getFloatBlendedColours(int firstColour, int secondColour, int steps) { byte[] firstColourByteArray = convertIntColourToByteArray(firstColour); diff --git a/src/main/java/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java b/src/main/java/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java index c684c144..41f1b5cb 100644 --- a/src/main/java/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java +++ b/src/main/java/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java @@ -1,7 +1,7 @@ package com.pahimar.ee3.client.renderer.tileentity; +import com.pahimar.ee3.client.helper.ColourUtils; import com.pahimar.ee3.client.model.ModelCalcinator; -import com.pahimar.ee3.helper.ColourUtils; import com.pahimar.ee3.lib.Textures; import com.pahimar.ee3.tileentity.TileCalcinator; import cpw.mods.fml.client.FMLClientHandler; @@ -55,7 +55,9 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer // Render modelCalcinator.renderPart("Calcinator"); - if (tileCalcinator.dustStackSize > 0) + int dustStackSize = tileCalcinator.leftStackSize + tileCalcinator.rightStackSize; + + if (dustStackSize > 0) { GL11.glPushMatrix(); @@ -63,15 +65,15 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer GL11.glRotatef(90F, 1F, 0F, 0F); GL11.glRotatef(-45F, 0F, 1F, 0F); - float[] dustColour = ColourUtils.convertByteArrayToFloatArray(new byte[]{tileCalcinator.dustColourRedChannel, tileCalcinator.dustColourGreenChannel, tileCalcinator.dustColourBlueChannel}); + float[] dustColour = getBlendedDustColour(tileCalcinator.leftStackSize, tileCalcinator.leftStackColour, tileCalcinator.rightStackSize, tileCalcinator.rightStackColour); GL11.glColor4f(dustColour[0], dustColour[1], dustColour[2], 1F); - if (tileCalcinator.dustStackSize <= 32) + if (dustStackSize <= 32) { GL11.glScalef(0.25F, 0.25F, 0.25F); GL11.glTranslatef(0.0F, 2.20F, -2.1125F); } - else if (tileCalcinator.dustStackSize <= 64) + else if (dustStackSize <= 64) { GL11.glScalef(0.5F, 0.5F, 0.5F); GL11.glTranslatef(-0.0125F, 0.75F, -0.7125F); @@ -90,4 +92,30 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer GL11.glPopMatrix(); } } + + private static float[] getBlendedDustColour(int leftStackSize, int leftStackColour, int rightStackSize, int rightStackColour) + { + if (leftStackSize > 0 && rightStackSize > 0) + { + int stackSizeStepRange = 8; + int factoredLeftStackSize = leftStackSize / stackSizeStepRange; + int factoredRightStackSize = rightStackSize / stackSizeStepRange; + + float[][] blendedColours = ColourUtils.getFloatBlendedColours(leftStackColour, rightStackColour, 2 * stackSizeStepRange - 1); + + return blendedColours[stackSizeStepRange + (factoredLeftStackSize - factoredRightStackSize)]; + } + else if (leftStackSize > 0) + { + return ColourUtils.convertIntColourToFloatArray(leftStackColour); + } + else if (rightStackSize > 0) + { + return ColourUtils.convertIntColourToFloatArray(rightStackColour); + } + else + { + return new float[]{1F, 1F, 1F}; + } + } } diff --git a/src/main/java/com/pahimar/ee3/network/packet/PacketTileCalcinator.java b/src/main/java/com/pahimar/ee3/network/packet/PacketTileCalcinator.java index bedc8182..0faaea41 100644 --- a/src/main/java/com/pahimar/ee3/network/packet/PacketTileCalcinator.java +++ b/src/main/java/com/pahimar/ee3/network/packet/PacketTileCalcinator.java @@ -16,15 +16,15 @@ public class PacketTileCalcinator extends PacketEE public byte orientation; public byte state; public String customName; - public int dustStackSize; - public byte redChannel, greenChannel, blueChannel; + public int leftStackSize, leftStackColour; + public int rightStackSize, rightStackColour; public PacketTileCalcinator() { super(PacketTypeHandler.TILE_CALCINATOR, true); } - public PacketTileCalcinator(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel) + public PacketTileCalcinator(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int leftStackSize, int leftStackColour, int rightStackSize, int rightStackColour) { super(PacketTypeHandler.TILE_CALCINATOR, true); this.x = x; @@ -33,10 +33,10 @@ public class PacketTileCalcinator extends PacketEE this.orientation = (byte) orientation.ordinal(); this.state = state; this.customName = customName; - this.dustStackSize = dustStackSize; - this.redChannel = redChannel; - this.greenChannel = greenChannel; - this.blueChannel = blueChannel; + this.leftStackSize = leftStackSize; + this.leftStackColour = leftStackColour; + this.rightStackSize = rightStackSize; + this.rightStackColour = rightStackColour; } @Override @@ -48,10 +48,10 @@ public class PacketTileCalcinator extends PacketEE data.writeByte(orientation); data.writeByte(state); data.writeUTF(customName); - data.writeInt(dustStackSize); - data.writeByte(redChannel); - data.writeByte(greenChannel); - data.writeByte(blueChannel); + data.writeInt(leftStackSize); + data.writeInt(leftStackColour); + data.writeInt(rightStackSize); + data.writeInt(rightStackColour); } @Override @@ -63,15 +63,15 @@ public class PacketTileCalcinator extends PacketEE orientation = data.readByte(); state = data.readByte(); customName = data.readUTF(); - dustStackSize = data.readInt(); - redChannel = data.readByte(); - greenChannel = data.readByte(); - blueChannel = data.readByte(); + leftStackSize = data.readInt(); + leftStackColour = data.readInt(); + rightStackSize = data.readInt(); + rightStackColour = data.readInt(); } @Override public void execute(INetworkManager manager, Player player) { - EquivalentExchange3.proxy.handleTileCalcinatorPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName, dustStackSize, redChannel, greenChannel, blueChannel); + EquivalentExchange3.proxy.handleTileCalcinatorPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName, leftStackSize, leftStackColour, rightStackSize, rightStackColour); } } diff --git a/src/main/java/com/pahimar/ee3/proxy/ClientProxy.java b/src/main/java/com/pahimar/ee3/proxy/ClientProxy.java index a1fef9a3..dc458c09 100644 --- a/src/main/java/com/pahimar/ee3/proxy/ClientProxy.java +++ b/src/main/java/com/pahimar/ee3/proxy/ClientProxy.java @@ -159,7 +159,7 @@ public class ClientProxy extends CommonProxy } @Override - public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel) + public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int leftStackSize, int leftStackColour, int rightStackSize, int rightStackColour) { World world = FMLClientHandler.instance().getClient().theWorld; TileEntity tileEntity = world.getBlockTileEntity(x, y, z); @@ -168,10 +168,10 @@ public class ClientProxy extends CommonProxy if (tileEntity instanceof TileCalcinator) { - ((TileCalcinator) tileEntity).dustStackSize = dustStackSize; - ((TileCalcinator) tileEntity).dustColourRedChannel = redChannel; - ((TileCalcinator) tileEntity).dustColourGreenChannel = greenChannel; - ((TileCalcinator) tileEntity).dustColourBlueChannel = blueChannel; + ((TileCalcinator) tileEntity).leftStackSize = leftStackSize; + ((TileCalcinator) tileEntity).leftStackColour = leftStackColour; + ((TileCalcinator) tileEntity).rightStackSize = rightStackSize; + ((TileCalcinator) tileEntity).rightStackColour = rightStackColour; world.updateAllLightTypes(x, y, z); } } diff --git a/src/main/java/com/pahimar/ee3/proxy/IProxy.java b/src/main/java/com/pahimar/ee3/proxy/IProxy.java index 1f7b7402..efa9e3c7 100644 --- a/src/main/java/com/pahimar/ee3/proxy/IProxy.java +++ b/src/main/java/com/pahimar/ee3/proxy/IProxy.java @@ -29,7 +29,7 @@ public interface IProxy public abstract void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color); - public abstract void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel); + public abstract void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int leftStackSize, int leftStackColour, int rightStackSize, int rightStackColour); public abstract void transmuteBlock(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int sideHit); } diff --git a/src/main/java/com/pahimar/ee3/proxy/ServerProxy.java b/src/main/java/com/pahimar/ee3/proxy/ServerProxy.java index 988a60de..7a1e74b3 100644 --- a/src/main/java/com/pahimar/ee3/proxy/ServerProxy.java +++ b/src/main/java/com/pahimar/ee3/proxy/ServerProxy.java @@ -70,7 +70,7 @@ public class ServerProxy extends CommonProxy // NOOP } - public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel) + public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int leftStackSize, int leftStackColour, int rightStackSize, int rightStackColour) { // NOOP } diff --git a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java index a20071a6..09b99e39 100644 --- a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java +++ b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java @@ -1,6 +1,6 @@ package com.pahimar.ee3.tileentity; -import com.pahimar.ee3.helper.ColourUtils; +import com.pahimar.ee3.lib.Colours; import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.network.PacketTypeHandler; import com.pahimar.ee3.network.packet.PacketTileCalcinator; @@ -39,8 +39,8 @@ public class TileCalcinator extends TileEE implements IInventory public int fuelBurnTime; // The fuel value for the currently burning fuel public int itemCookTime; // How long the current item has been "cooking" - public int dustStackSize; - public byte dustColourRedChannel, dustColourGreenChannel, dustColourBlueChannel; + public int leftStackSize, leftStackColour; + public int rightStackSize, rightStackColour; public TileCalcinator() { @@ -215,7 +215,6 @@ public class TileCalcinator extends TileEE implements IInventory // Start "cooking" a new item, if we can if (this.deviceCookTime == 0 && this.canCalcinate()) { - // TODO Effect burn speed by fuel quality this.fuelBurnTime = this.deviceCookTime = TileEntityFurnace.getItemBurnTime(this.inventory[FUEL_INVENTORY_INDEX]); if (this.deviceCookTime > 0) @@ -263,6 +262,7 @@ public class TileCalcinator extends TileEE implements IInventory this.onInventoryChanged(); this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 1, this.state); + // TODO Send stack sizes and colours on update } } @@ -369,56 +369,25 @@ public class TileCalcinator extends TileEE implements IInventory } } - public int getCombinedOutputSize() - { - int result = 0; - - if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) - { - result += this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize; - } - - if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) - { - result += this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize; - } - - return result; - } - - @SideOnly(Side.CLIENT) - public byte[] getBlendedDustColour() - { - if (inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null && inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) - { - int leftStackColour = inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1); - int rightStackColour = inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1); - - int stackSizeStepRange = 8; - int leftStackSize = inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize / stackSizeStepRange; - int rightStackSize = inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize / stackSizeStepRange; - byte[][] blendedByteColours = ColourUtils.getByteBlendedColours(ColourUtils.convertIntColourToByteArray(leftStackColour), ColourUtils.convertIntColourToByteArray(rightStackColour), 2 * stackSizeStepRange - 1); - - return blendedByteColours[stackSizeStepRange + (leftStackSize - rightStackSize)]; - } - else if (inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) - { - return ColourUtils.convertIntColourToByteArray(inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1)); - } - else if (inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) - { - return ColourUtils.convertIntColourToByteArray(inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1)); - } - else - { - return new byte[]{(byte) 255, (byte) 255, (byte) 255}; - } - } - @Override public Packet getDescriptionPacket() { - byte[] colourChannels = getBlendedDustColour(); - return PacketTypeHandler.populatePacket(new PacketTileCalcinator(xCoord, yCoord, zCoord, orientation, state, customName, getCombinedOutputSize(), colourChannels[0], colourChannels[1], colourChannels[2])); + int leftStackSize = 0; + int leftStackColour = Integer.parseInt(Colours.PURE_WHITE, 16); + if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) + { + leftStackSize = this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize; + leftStackColour = this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(this.inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1); + } + + int rightStackSize = 0; + int rightStackColour = Integer.parseInt(Colours.PURE_WHITE, 16); + if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) + { + rightStackSize = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize; + rightStackColour = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1); + } + + return PacketTypeHandler.populatePacket(new PacketTileCalcinator(xCoord, yCoord, zCoord, orientation, state, customName, leftStackSize, leftStackColour, rightStackSize, rightStackColour)); } }