diff --git a/changelog b/changelog index d23e7d596..2ae8aa9c2 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,3 @@ -## Fixed -* Fixed battery connection priority being broken, all battery blocks present during the previous updates will now have their priority default to LOW -* Fixed batteries sometimes ending up transferring themselves, wasting their entire receiving and sending speed on doing effectively nothing - * Energy tracking is still a bit flakey so there could be issues that remain with buffer mode batteries, however the transfer caps should mitigate most potential issues \ No newline at end of file +## Changed +* All pylons and electrical connectors are now dyeable, using any dye (even modded ones, based on ore dict) to change the color of the cable + * Colors are based on the connecting pylon, not the cables themselves, meaning that using one dye will change all wires connected to that pylon right up to the half way point \ No newline at end of file diff --git a/src/main/java/com/hbm/blocks/network/PylonBase.java b/src/main/java/com/hbm/blocks/network/PylonBase.java index f2bf0c675..bf35c9fbe 100644 --- a/src/main/java/com/hbm/blocks/network/PylonBase.java +++ b/src/main/java/com/hbm/blocks/network/PylonBase.java @@ -6,6 +6,7 @@ import com.hbm.tileentity.network.TileEntityPylonBase; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -41,4 +42,16 @@ public abstract class PylonBase extends BlockContainer implements ITooltipProvid public boolean renderAsNormalBlock() { return false; } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) { + return true; + } else if(!player.isSneaking()) { + TileEntityPylonBase te = (TileEntityPylonBase) world.getTileEntity(x, y, z); + return te.setColor(player.getHeldItem()); + } else { + return false; + } + } } diff --git a/src/main/java/com/hbm/blocks/network/PylonLarge.java b/src/main/java/com/hbm/blocks/network/PylonLarge.java index 395b27dd1..6333a6e28 100644 --- a/src/main/java/com/hbm/blocks/network/PylonLarge.java +++ b/src/main/java/com/hbm/blocks/network/PylonLarge.java @@ -82,4 +82,17 @@ public class PylonLarge extends BlockDummyable implements ITooltipProvider { return dir.ordinal() + offset; } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) { + return true; + } else if(!player.isSneaking()) { + int[] pos = this.findCore(world, x, y, z); + TileEntityPylonBase te = (TileEntityPylonBase) world.getTileEntity(pos[0], pos[1], pos[2]); + return te.setColor(player.getHeldItem()); + } else { + return false; + } + } } diff --git a/src/main/java/com/hbm/blocks/network/PylonMedium.java b/src/main/java/com/hbm/blocks/network/PylonMedium.java index d36921a67..7a29f4614 100644 --- a/src/main/java/com/hbm/blocks/network/PylonMedium.java +++ b/src/main/java/com/hbm/blocks/network/PylonMedium.java @@ -50,4 +50,17 @@ public class PylonMedium extends BlockDummyable implements ITooltipProvider { if(te instanceof TileEntityPylonBase) ((TileEntityPylonBase)te).disconnectAll(); super.breakBlock(world, x, y, z, b, m); } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) { + return true; + } else if(!player.isSneaking()) { + int[] pos = this.findCore(world, x, y, z); + TileEntityPylonBase te = (TileEntityPylonBase) world.getTileEntity(pos[0], pos[1], pos[2]); + return te.setColor(player.getHeldItem()); + } else { + return false; + } + } } diff --git a/src/main/java/com/hbm/blocks/network/Substation.java b/src/main/java/com/hbm/blocks/network/Substation.java index 7499992fd..6c8e3cb34 100644 --- a/src/main/java/com/hbm/blocks/network/Substation.java +++ b/src/main/java/com/hbm/blocks/network/Substation.java @@ -72,4 +72,17 @@ public class Substation extends BlockDummyable implements ITooltipProvider { this.makeExtra(world, x + dir.offsetX * o - 1, y, z + dir.offsetZ * o + 1); this.makeExtra(world, x + dir.offsetX * o - 1, y, z + dir.offsetZ * o - 1); } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) { + return true; + } else if(!player.isSneaking()) { + int[] pos = this.findCore(world, x, y, z); + TileEntityPylonBase te = (TileEntityPylonBase) world.getTileEntity(pos[0], pos[1], pos[2]); + return te.setColor(player.getHeldItem()); + } else { + return false; + } + } } diff --git a/src/main/java/com/hbm/main/ResourceManager.java b/src/main/java/com/hbm/main/ResourceManager.java index 08ba66b2d..2e4d78e50 100644 --- a/src/main/java/com/hbm/main/ResourceManager.java +++ b/src/main/java/com/hbm/main/ResourceManager.java @@ -788,6 +788,7 @@ public class ResourceManager { public static final ResourceLocation pylon_large_tex = new ResourceLocation(RefStrings.MODID, "textures/models/network/pylon_large.png"); public static final ResourceLocation substation_tex = new ResourceLocation(RefStrings.MODID, "textures/models/network/substation.png"); public static final ResourceLocation wire_tex = new ResourceLocation(RefStrings.MODID, "textures/models/network/wire.png"); + public static final ResourceLocation wire_greyscale_tex = new ResourceLocation(RefStrings.MODID, "textures/models/network/wire_greyscale.png"); //Radiolysis public static final ResourceLocation radiolysis_tex = new ResourceLocation(RefStrings.MODID, "textures/models/radiolysis.png"); diff --git a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java index dca78271c..1d69ca2ba 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java @@ -24,7 +24,7 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { */ public void renderLinesGeneric(TileEntityPylonBase pyl, double x, double y, double z) { - this.bindTexture(ResourceManager.wire_tex); + this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex); for(int i = 0; i < pyl.connected.size(); i++) { @@ -127,6 +127,8 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { int brightness = world.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ix), MathHelper.floor_double(iy), MathHelper.floor_double(iz), 0); tess.setBrightness(brightness); + tess.setColorOpaque_I(pyl.color == 0 ? 0xffffff : pyl.color); + drawLineSegment(tess, x0 + (deltaX * j / count), y0 + (deltaY * j / count) - sagJ, @@ -180,7 +182,6 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { jX *= -1; } - tessellator.setColorOpaque_I(0xffffff); tessellator.addVertexWithUV(x + iX, y + iY, z + iZ, 0, 0); tessellator.addVertexWithUV(x - iX, y - iY, z - iZ, 0, 1); tessellator.addVertexWithUV(a - iX, b - iY, c - iZ, wrap, 1); diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java index 080001df1..7581ddaed 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java @@ -3,6 +3,7 @@ package com.hbm.tileentity.network; import java.util.ArrayList; import java.util.List; +import com.hbm.util.ColorUtil; import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.DirPos; @@ -10,6 +11,7 @@ import api.hbm.energymk2.Nodespace; import api.hbm.energymk2.Nodespace.PowerNode; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; @@ -23,6 +25,7 @@ import net.minecraftforge.common.util.ForgeDirection; public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { public List connected = new ArrayList(); + public int color; public static int canConnect(TileEntityPylonBase first, TileEntityPylonBase second) { @@ -45,6 +48,22 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { return len >= delta.lengthVector() ? 0 : 3; } + + public boolean setColor(ItemStack stack) { + if(stack == null) return false; + int color = ColorUtil.getColorFromDye(stack); + if(color == 0 || color == this.color) return false; + stack.stackSize--; + this.color = color; + + this.markDirty(); + if(worldObj instanceof WorldServer) { + WorldServer world = (WorldServer) worldObj; + world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); + } + + return true; + } @Override public PowerNode createNode() { @@ -120,8 +139,9 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - + nbt.setInteger("conCount", connected.size()); + nbt.setInteger("color", color); for(int i = 0; i < connected.size(); i++) { nbt.setIntArray("con" + i, connected.get(i)); @@ -133,6 +153,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { super.readFromNBT(nbt); int count = nbt.getInteger("conCount"); + this.color = nbt.getInteger("color"); this.connected.clear(); diff --git a/src/main/java/com/hbm/util/ColorUtil.java b/src/main/java/com/hbm/util/ColorUtil.java index aec239b53..2d0ad9378 100644 --- a/src/main/java/com/hbm/util/ColorUtil.java +++ b/src/main/java/com/hbm/util/ColorUtil.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import javax.imageio.ImageIO; @@ -182,4 +183,36 @@ public class ColorUtil { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); return hsb[2]; } + + public static HashMap nameToColor = new HashMap() {{ + put("black", 1973019); + put("red", 11743532); + put("green", 3887386); + put("brown", 5320730); + put("blue", 2437522); + put("purple", 8073150); + put("cyan", 2651799); + put("silver", 11250603); + put("gray", 4408131); + put("pink", 14188952); + put("lime", 4312372); + put("yellow", 14602026); + put("lightBlue", 6719955); + put("magenta", 12801229); + put("orange", 15435844); + put("white", 15790320); + }}; + + public static int getColorFromDye(ItemStack stack) { + List oreNames = ItemStackUtil.getOreDictNames(stack); + + for(String dict : oreNames) { + if(dict.length() > 3 && dict.startsWith("dye")) { + String color = dict.substring(3).toLowerCase(Locale.US); + if(nameToColor.containsKey(color)) return nameToColor.get(color); + } + } + + return 0; + } } diff --git a/src/main/resources/assets/hbm/textures/items/card_hbm.png b/src/main/resources/assets/hbm/textures/items/card_hbm.png new file mode 100644 index 000000000..c273750fd Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/card_hbm.png differ diff --git a/src/main/resources/assets/hbm/textures/items/kit_hbm.png b/src/main/resources/assets/hbm/textures/items/kit_hbm.png new file mode 100644 index 000000000..eb11c3cb4 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/items/kit_hbm.png differ diff --git a/src/main/resources/assets/hbm/textures/models/network/wire_greyscale.png b/src/main/resources/assets/hbm/textures/models/network/wire_greyscale.png new file mode 100644 index 000000000..6aa158ed6 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/models/network/wire_greyscale.png differ