From d81d5594e29c62a10f4c7ff603adf6ed53818581 Mon Sep 17 00:00:00 2001 From: pahimar Date: Sun, 12 Jan 2014 13:52:52 -0500 Subject: [PATCH] Fixing a sided error, but also discovering a dust stack colour bug in SMP --- .../ee3/client/helper/ColourUtils.java | 10 ++---- .../TileEntityCalcinatorRenderer.java | 10 +++++- .../java/com/pahimar/ee3/lib/Colours.java | 1 + .../ee3/tileentity/TileCalcinator.java | 34 ++++++++++++++----- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java b/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java index 060c968e..dcd42c2a 100644 --- a/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java +++ b/src/main/java/com/pahimar/ee3/client/helper/ColourUtils.java @@ -1,11 +1,7 @@ package com.pahimar.ee3.client.helper; -import java.util.regex.Pattern; - public class ColourUtils { - private static final Pattern HEX_COLOUR_PATTERN = Pattern.compile("[0-9a-fA-F]{6}"); - public static byte[] convertIntColourToByteArray(int intColour) { byte[] colourByteArray = new byte[3]; @@ -21,9 +17,9 @@ public class ColourUtils { float[] colourFloatArray = new float[3]; - colourFloatArray[0] = (float) (intColour >> 16 & 255) / 255F; - colourFloatArray[1] = (float) (intColour >> 8 & 255) / 255F; - colourFloatArray[2] = (float) (intColour & 255) / 255F; + colourFloatArray[0] = ((intColour >> 16 & 0xFF) / 255F); + colourFloatArray[1] = ((intColour >> 8 & 0xFF) / 255F); + colourFloatArray[2] = ((intColour & 0xFF) / 255F); return colourFloatArray; } 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 41f1b5cb..2cd720ff 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 @@ -66,6 +66,7 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer GL11.glRotatef(-45F, 0F, 1F, 0F); float[] dustColour = getBlendedDustColour(tileCalcinator.leftStackSize, tileCalcinator.leftStackColour, tileCalcinator.rightStackSize, tileCalcinator.rightStackColour); + GL11.glColor4f(dustColour[0], dustColour[1], dustColour[2], 1F); if (dustStackSize <= 32) @@ -103,7 +104,14 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer float[][] blendedColours = ColourUtils.getFloatBlendedColours(leftStackColour, rightStackColour, 2 * stackSizeStepRange - 1); - return blendedColours[stackSizeStepRange + (factoredLeftStackSize - factoredRightStackSize)]; + if (blendedColours != null) + { + return blendedColours[stackSizeStepRange + (factoredLeftStackSize - factoredRightStackSize)]; + } + else + { + return new float[]{1F, 1F, 1F}; + } } else if (leftStackSize > 0) { diff --git a/src/main/java/com/pahimar/ee3/lib/Colours.java b/src/main/java/com/pahimar/ee3/lib/Colours.java index ec66bae2..7935083b 100644 --- a/src/main/java/com/pahimar/ee3/lib/Colours.java +++ b/src/main/java/com/pahimar/ee3/lib/Colours.java @@ -16,6 +16,7 @@ public class Colours public static final String DUST_VERDANT = "45CC39"; public static final String DUST_AZURE = "35A6DE"; public static final String DUST_MINIUM = "FF4545"; + public static final String[] DUST_COLOURS = new String[]{DUST_ASH, DUST_VERDANT, DUST_AZURE, DUST_MINIUM}; // Infused Planks public static final String INFUSED_PLANKS_VERDANT = "3D822A"; diff --git a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java index 647b737a..c69abf94 100644 --- a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java +++ b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java @@ -1,5 +1,6 @@ package com.pahimar.ee3.tileentity; +import com.pahimar.ee3.item.ItemAlchemicalDust; import com.pahimar.ee3.lib.Colours; import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.network.PacketTypeHandler; @@ -13,6 +14,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.util.MathHelper; /** * Equivalent-Exchange-3 @@ -61,6 +63,7 @@ public class TileCalcinator extends TileEE implements IInventory @Override public ItemStack getStackInSlot(int slotIndex) { + sendDustPileData(); return inventory[slotIndex]; } @@ -289,10 +292,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); - this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 2, getLeftStackSize()); - this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 3, getLeftStackColour()); - this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 4, getRightStackSize()); - this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 5, getRightStackColour()); + sendDustPileData(); this.worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID); } } @@ -420,10 +420,15 @@ public class TileCalcinator extends TileEE implements IInventory { if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) { - return this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(this.inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1); + ItemStack itemStack = this.inventory[OUTPUT_LEFT_INVENTORY_INDEX]; + + if (itemStack.getItem() instanceof ItemAlchemicalDust) + { + return Integer.parseInt(Colours.DUST_COLOURS[MathHelper.clamp_int(itemStack.getItemDamage(), 0, Colours.DUST_COLOURS.length - 1)], 16); + } } - return Integer.parseInt(Colours.PURE_WHITE, 16); + return 16777215; } private int getRightStackSize() @@ -440,9 +445,22 @@ public class TileCalcinator extends TileEE implements IInventory { if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) { - return this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1); + ItemStack itemStack = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX]; + + if (itemStack.getItem() instanceof ItemAlchemicalDust) + { + return Integer.parseInt(Colours.DUST_COLOURS[MathHelper.clamp_int(itemStack.getItemDamage(), 0, Colours.DUST_COLOURS.length - 1)], 16); + } } - return Integer.parseInt(Colours.PURE_WHITE, 16); + return 16777215; + } + + private void sendDustPileData() + { + this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 2, getLeftStackSize()); + this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 3, getLeftStackColour()); + this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 4, getRightStackSize()); + this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 5, getRightStackColour()); } }