From da2abe281dc303d4ddf8e76654e6262077429f5c Mon Sep 17 00:00:00 2001 From: PewPewCricket Date: Sun, 13 Jul 2025 14:57:43 -0500 Subject: [PATCH 1/4] add paintable network cable --- src/main/java/com/hbm/blocks/ModBlocks.java | 11 + .../BlockOpenComputersCablePaintable.java | 244 ++++++++++++++++++ .../java/com/hbm/main/CraftingManager.java | 7 +- .../java/com/hbm/tileentity/TileMappings.java | 9 + src/main/resources/assets/hbm/lang/en_US.lang | 2 + .../hbm/textures/blocks/oc_cable_base.png | Bin 0 -> 624 bytes .../hbm/textures/blocks/oc_cable_overlay.png | Bin 0 -> 340 bytes 7 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java create mode 100644 src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png create mode 100644 src/main/resources/assets/hbm/textures/blocks/oc_cable_overlay.png diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 5f3de7f83..01b28241f 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -34,6 +34,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; +import cpw.mods.fml.common.Loader; import java.util.ArrayList; @@ -803,6 +804,7 @@ public class ModBlocks { public static Block radio_torch_reader; public static Block radio_torch_controller; public static Block radio_telex; + public static Block oc_cable_paintable; public static Block conveyor; public static Block conveyor_express; @@ -2340,6 +2342,10 @@ public class ModBlocks { absorber_pink = new BlockAbsorber(Material.iron, 10000F).setBlockName("absorber_pink").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":absorber_pink"); decon = new BlockDecon(Material.iron).setBlockName("decon").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":decon_side"); + if (Loader.isModLoaded("OpenComputers")) { + oc_cable_paintable = new BlockOpenComputersCablePaintable().setBlockName("oc_cable_paintable").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab); + } + volcano_core = new BlockVolcano().setBlockName("volcano_core").setBlockUnbreakable().setResistance(10000.0F).setCreativeTab(MainRegistry.nukeTab).setBlockTextureName(RefStrings.MODID + ":volcano_core"); volcano_rad_core = new BlockVolcano().setBlockName("volcano_rad_core").setBlockUnbreakable().setResistance(10000.0F).setCreativeTab(MainRegistry.nukeTab).setBlockTextureName(RefStrings.MODID + ":volcano_rad_core"); @@ -3532,6 +3538,11 @@ public class ModBlocks { GameRegistry.registerBlock(gas_explosive, gas_explosive.getUnlocalizedName()); GameRegistry.registerBlock(vacuum, vacuum.getUnlocalizedName()); + // OC Compat Items + if (Loader.isModLoaded("OpenComputers")) { + register(oc_cable_paintable); + } + //??? GameRegistry.registerBlock(crystal_virus, crystal_virus.getUnlocalizedName()); GameRegistry.registerBlock(crystal_hardened, crystal_hardened.getUnlocalizedName()); diff --git a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java new file mode 100644 index 000000000..b755006d5 --- /dev/null +++ b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java @@ -0,0 +1,244 @@ +package com.hbm.blocks.network; + +import api.hbm.block.IToolable; +import com.hbm.blocks.IBlockMultiPass; +import com.hbm.lib.RefStrings; +import com.hbm.render.block.RenderBlockMultipass; +import com.hbm.tileentity.TileEntityLoadedBase; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import li.cil.oc.api.network.Environment; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import li.cil.oc.api.network.Message; +import li.cil.oc.api.network.Node; +import li.cil.oc.api.Network; +import li.cil.oc.api.network.Visibility; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.Loader; + +public class BlockOpenComputersCablePaintable extends BlockContainer implements IToolable, IBlockMultiPass { + + @SideOnly(Side.CLIENT) protected IIcon overlay; + + public BlockOpenComputersCablePaintable() { + super(Material.iron); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileEntityOpenComputersCablePaintable(); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister reg) { + this.blockIcon = reg.registerIcon(RefStrings.MODID + ":oc_cable_base"); + this.overlay = reg.registerIcon(RefStrings.MODID + ":oc_cable_overlay"); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityOpenComputersCablePaintable) { + TileEntityOpenComputersCablePaintable pipe = (TileEntityOpenComputersCablePaintable) tile; + + if(pipe.block != null) { + if(RenderBlockMultipass.currentPass == 1) { + return this.overlay; + } else { + return pipe.block.getIcon(side, pipe.meta); + } + } + } + + return RenderBlockMultipass.currentPass == 1 ? this.overlay : this.blockIcon; + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float fX, float fY, float fZ) { + + ItemStack stack = player.getHeldItem(); + + if(stack != null && stack.getItem() instanceof ItemBlock) { + ItemBlock ib = (ItemBlock) stack.getItem(); + Block block = ib.field_150939_a; + + if(block.renderAsNormalBlock() && block != this) { + + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityOpenComputersCablePaintable) { + TileEntityOpenComputersCablePaintable pipe = (TileEntityOpenComputersCablePaintable) tile; + + if(pipe.block == null) { + pipe.block = block; + pipe.meta = stack.getItemDamage() & 15; + world.markBlockForUpdate(x, y, z); + pipe.markDirty(); + return true; + } + } + } + } + + return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ); + } + + @Override + public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) { + + if(tool != ToolType.SCREWDRIVER) return false; + + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityOpenComputersCablePaintable) { + TileEntityOpenComputersCablePaintable pipe = (TileEntityOpenComputersCablePaintable) tile; + + if(pipe.block != null) { + pipe.block = null; + world.markBlockForUpdate(x, y, z); + pipe.markDirty(); + return true; + } + } + + return false; + } + + @Override + public int getPasses() { + return 2; + } + + @Override + public int getRenderType(){ + return IBlockMultiPass.getRenderType(); + } + + // WHY the fuck is this not compiling + @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = "OpenComputers")}) + public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment { + + protected Node node; + protected boolean addedToNetwork = false; + + private Block block; + private int meta; + private Block lastBlock; + private int lastMeta; + + public TileEntityOpenComputersCablePaintable() { + node = Network.newNode(this, Visibility.None).create(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + + if(worldObj.isRemote && (lastBlock != block || lastMeta != meta)) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + lastBlock = block; + lastMeta = meta; + } + + if(!this.getWorldObj().isRemote && !addedToNetwork) { + addedToNetwork = true; + Network.joinOrCreateNetwork(this); + } + + } + + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + this.writeToNBT(nbt); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); + } + + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + this.readFromNBT(pkt.func_148857_g()); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + int id = nbt.getInteger("block"); + this.block = id == 0 ? null : Block.getBlockById(id); + this.meta = nbt.getInteger("meta"); + + if (node != null && node.host() == this) { + node.load(nbt.getCompoundTag("oc:node")); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + if(block != null) nbt.setInteger("block", Block.getIdFromBlock(block)); + nbt.setInteger("meta", meta); + + if (node != null && node.host() == this) { + final NBTTagCompound nodeNbt = new NBTTagCompound(); + node.save(nodeNbt); + nbt.setTag("oc:node", nodeNbt); + } + } + + public NBTTagCompound getSettings(World world, int x, int y, int z) { + NBTTagCompound nbt = new NBTTagCompound(); + if(block != null) { + nbt.setInteger("paintblock", Block.getIdFromBlock(block)); + nbt.setInteger("paintmeta", meta); + } + return nbt; + } + + public void pasteSettings(NBTTagCompound nbt, int index, World world, EntityPlayer player, int x, int y, int z) { + if(nbt.hasKey("paintblock")) { + this.block = Block.getBlockById(nbt.getInteger("paintblock")); + this.meta = nbt.getInteger("paintmeta"); + } + } + + // OC Cable Things + @Override + public Node node() { + return node; + } + + @Override + public void onConnect(Node node) {} + + @Override + public void onDisconnect(Node node) {} + + @Override + public void onMessage(Message message) {} + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + if (node != null) node.remove(); + } + + public void invalidate() { + super.invalidate(); + if (node != null) node.remove(); + } + } +} diff --git a/src/main/java/com/hbm/main/CraftingManager.java b/src/main/java/com/hbm/main/CraftingManager.java index 67b872581..3892e6a3a 100644 --- a/src/main/java/com/hbm/main/CraftingManager.java +++ b/src/main/java/com/hbm/main/CraftingManager.java @@ -237,6 +237,7 @@ public class CraftingManager { addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_electric_furnace_off), 1), new Object[] { "BBB", "WFW", "RRR", 'B', BE.ingot(), 'R', ModItems.coil_tungsten, 'W', CU.plateCast(), 'F', Item.getItemFromBlock(Blocks.furnace) }); addRecipeAuto(new ItemStack(ModBlocks.red_wire_coated, 16), new Object[] { "WRW", "RIR", "WRW", 'W', ModItems.plate_polymer, 'I', MINGRADE.ingot(), 'R', MINGRADE.wireFine() }); addRecipeAuto(new ItemStack(ModBlocks.red_cable_paintable, 16), new Object[] { "WRW", "RIR", "WRW", 'W', STEEL.plate(), 'I', MINGRADE.ingot(), 'R', MINGRADE.wireFine() }); + addRecipeAuto(new ItemStack(ModBlocks.oc_cable_paintable, 16), new Object[] { "WRW", "RIR", "WRW", 'W', STEEL.plate(), 'I', REDSTONE.dust(), 'R', MINGRADE.wireFine() }); addRecipeAuto(new ItemStack(ModBlocks.cable_switch, 1), new Object[] { "S", "W", 'S', Blocks.lever, 'W', ModBlocks.red_wire_coated }); addRecipeAuto(new ItemStack(ModBlocks.cable_detector, 1), new Object[] { "S", "W", 'S', REDSTONE.dust(), 'W', ModBlocks.red_wire_coated }); addRecipeAuto(new ItemStack(ModBlocks.cable_diode, 1), new Object[] { " Q ", "CAC", " Q ", 'Q', SI.nugget(), 'C', ModBlocks.red_cable, 'A', AL.ingot() }); @@ -410,7 +411,7 @@ public class CraftingManager { addRecipeAuto(new ItemStack(ModBlocks.basalt_polished, 4), new Object[] { "CC", "CC", 'C', ModBlocks.basalt_smooth }); addRecipeAuto(new ItemStack(ModBlocks.basalt_brick, 4), new Object[] { "CC", "CC", 'C', ModBlocks.basalt_polished }); addRecipeAuto(new ItemStack(ModBlocks.basalt_tiles, 4), new Object[] { "CC", "CC", 'C', ModBlocks.basalt_brick }); - + addShapelessAuto(new ItemStack(ModBlocks.lightstone, 4), new Object[] { Blocks.stone, Blocks.stone, Blocks.stone, ModItems.powder_limestone }); addRecipeAuto(new ItemStack(ModBlocks.lightstone, 4, LightstoneType.TILE.ordinal()), new Object[] { "CC", "CC", 'C', new ItemStack(ModBlocks.lightstone, 1, 0) }); addRecipeAuto(new ItemStack(ModBlocks.lightstone, 4, LightstoneType.BRICKS.ordinal()), new Object[] { "CC", "CC", 'C', new ItemStack(ModBlocks.lightstone, 1, LightstoneType.TILE.ordinal()) }); @@ -442,7 +443,7 @@ public class CraftingManager { addRecipeAuto(new ItemStack(ModBlocks.barbed_wire_ultradeath, 4), new Object[] { "BCB", "CIC", "BCB", 'B', ModBlocks.barbed_wire, 'C', ModItems.powder_yellowcake, 'I', ModItems.nuclear_waste }); addShapelessAuto(new ItemStack(ModBlocks.sandbags, 4), new Object[] { ModItems.plate_polymer, KEY_SAND, KEY_SAND, KEY_SAND }); - + addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.tape_recorder), 4), new Object[] { "TST", "SSS", 'T', W.ingot(), 'S', STEEL.ingot() }); addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.steel_poles), 16), new Object[] { "S S", "SSS", "S S", 'S', STEEL.ingot() }); addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.pole_top), 1), new Object[] { "T T", "TRT", "BBB", 'T', W.ingot(), 'B', BE.ingot(), 'R', MINGRADE.ingot() }); @@ -610,7 +611,7 @@ public class CraftingManager { addRecipeAuto(new ItemStack(ModBlocks.fluid_pump, 1), new Object[] { " S ", "PGP", "IMI", 'S', STEEL.shell(), 'P', STEEL.pipe(), 'G', GRAPHITE.ingot(), 'I', STEEL.ingot(), 'M', ModItems.motor }); addRecipeAuto(new ItemStack(ModBlocks.pneumatic_tube, 8), new Object[] { "CRC", 'C', CU.plateCast(), 'R', ANY_RUBBER.ingot() }); addRecipeAuto(new ItemStack(ModBlocks.pneumatic_tube, 24), new Object[] { "CRC", 'C', CU.plateWelded(), 'R', ANY_RUBBER.ingot() }); - + addRecipeAuto(new ItemStack(ModItems.template_folder, 1), new Object[] { "LPL", "BPB", "LPL", 'P', Items.paper, 'L', "dye", 'B', "dye" }); addRecipeAuto(new ItemStack(ModItems.pellet_antimatter, 1), new Object[] { "###", "###", "###", '#', ModItems.cell_antimatter }); addRecipeAuto(new ItemStack(ModItems.fluid_tank_empty, 8), new Object[] { "121", "1G1", "121", '1', AL.plate(), '2', IRON.plate(), 'G', KEY_ANYPANE }); diff --git a/src/main/java/com/hbm/tileentity/TileMappings.java b/src/main/java/com/hbm/tileentity/TileMappings.java index 1c938ab18..438b6c605 100644 --- a/src/main/java/com/hbm/tileentity/TileMappings.java +++ b/src/main/java/com/hbm/tileentity/TileMappings.java @@ -40,6 +40,7 @@ import com.hbm.blocks.network.FluidDuctPaintable.TileEntityPipePaintable; import com.hbm.blocks.network.FluidDuctPaintableBlockExhaust.TileEntityPipeExhaustPaintable; import com.hbm.blocks.network.FluidPump.TileEntityFluidPump; import com.hbm.blocks.rail.RailStandardSwitch.TileEntityRailSwitch; +import com.hbm.blocks.network.BlockOpenComputersCablePaintable.TileEntityOpenComputersCablePaintable; import com.hbm.tileentity.bomb.*; import com.hbm.tileentity.deco.*; import com.hbm.tileentity.machine.*; @@ -50,6 +51,7 @@ import com.hbm.tileentity.machine.rbmk.*; import com.hbm.tileentity.machine.storage.*; import com.hbm.tileentity.network.*; import com.hbm.tileentity.turret.*; +import cpw.mods.fml.common.Loader; import net.minecraft.tileentity.TileEntity; @@ -451,6 +453,13 @@ public class TileMappings { put(TileEntityDroneRequester.class, "tileentity_drone_requester"); put(TileEntityRailSwitch.class, "tileentity_rail_switch"); + + // OC Compat items + boolean ocPresent = Loader.isModLoaded("OpenComputers"); + + if (ocPresent) { + put(TileEntityOpenComputersCablePaintable.class, "tileentity_oc_cable_paintable"); + } } private static void put(Class clazz, String... names) { diff --git a/src/main/resources/assets/hbm/lang/en_US.lang b/src/main/resources/assets/hbm/lang/en_US.lang index cb32c226e..c7ab3f6fe 100644 --- a/src/main/resources/assets/hbm/lang/en_US.lang +++ b/src/main/resources/assets/hbm/lang/en_US.lang @@ -6227,3 +6227,5 @@ desc.gui.upgrade.effectiveness= * §aEffectiveness§r: Stacks to level 3 desc.gui.upgrade.overdrive= * §7Overdrive§r: Stacks to level 3 desc.gui.upgrade.power= * §1Power-Saving§r: Stacks to level 3 desc.gui.upgrade.speed= * §4Speed§r: Stacks to level 3 + +tile.oc_cable_paintable.name=Paintable Network Cable diff --git a/src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png b/src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png new file mode 100644 index 0000000000000000000000000000000000000000..243c2da7f8f52b96ec7dba690200d6902ca3ea4d GIT binary patch literal 624 zcmV-$0+0QPP)nh*GJ9h6YW3HdHDVeE9eYiM2I|nFmv}&*K3B__eWtZ{L5& z9ihduSAnH<9qXH0XxigO#UPZ+WgKX2mEZ=(C+?QMBx2ZTUApGP*Eg%})ovtS9(mcD=%kJ~)klnBb)8}p|4|)RuMCV>&E0wANxOd|#TAUijrUFWy z8LXcfunZ9n4NzZC5HquLH301L0&>P3|zt8 z$@}U>a*|oVD+hy`dvoO(PS6G7^>bP0l+XkK De2Z3~ literal 0 HcmV?d00001 From 02a4bf483e1eeea641a9bf3c59fc3a252b3ceb38 Mon Sep 17 00:00:00 2001 From: PewPewCricket Date: Mon, 14 Jul 2025 20:31:54 -0500 Subject: [PATCH 2/4] add dyable cable color functionality to paintable network cable --- .../BlockOpenComputersCablePaintable.java | 116 +++++++++++++++++- .../java/com/hbm/handler/CompatHandler.java | 84 +++++++++---- .../hbm/textures/blocks/oc_cable_base.png | Bin 624 -> 612 bytes .../hbm/textures/blocks/oc_cable_color.png | Bin 0 -> 111 bytes .../hbm/textures/blocks/oc_cable_overlay.png | Bin 340 -> 139 bytes 5 files changed, 173 insertions(+), 27 deletions(-) create mode 100644 src/main/resources/assets/hbm/textures/blocks/oc_cable_color.png diff --git a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java index b755006d5..915fb58f0 100644 --- a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java +++ b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java @@ -2,6 +2,8 @@ package com.hbm.blocks.network; import api.hbm.block.IToolable; import com.hbm.blocks.IBlockMultiPass; +import com.hbm.blocks.ILookOverlay; +import com.hbm.handler.CompatHandler; import com.hbm.lib.RefStrings; import com.hbm.render.block.RenderBlockMultipass; import com.hbm.tileentity.TileEntityLoadedBase; @@ -13,7 +15,9 @@ import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemDye; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -29,10 +33,16 @@ import li.cil.oc.api.Network; import li.cil.oc.api.network.Visibility; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Loader; +import li.cil.oc.api.network.SidedEnvironment; +import net.minecraftforge.common.util.ForgeDirection; +import li.cil.oc.api.internal.Colored; +import com.hbm.handler.CompatHandler.OCColors; +import net.minecraftforge.oredict.OreDictionary; public class BlockOpenComputersCablePaintable extends BlockContainer implements IToolable, IBlockMultiPass { @SideOnly(Side.CLIENT) protected IIcon overlay; + @SideOnly(Side.CLIENT) protected IIcon overlayColor; public BlockOpenComputersCablePaintable() { super(Material.iron); @@ -48,6 +58,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements public void registerBlockIcons(IIconRegister reg) { this.blockIcon = reg.registerIcon(RefStrings.MODID + ":oc_cable_base"); this.overlay = reg.registerIcon(RefStrings.MODID + ":oc_cable_overlay"); + this.overlayColor = reg.registerIcon(RefStrings.MODID + ":oc_cable_color"); } @Override @@ -61,13 +72,29 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements if(pipe.block != null) { if(RenderBlockMultipass.currentPass == 1) { return this.overlay; + } else if(RenderBlockMultipass.currentPass == 2) { + return this.overlayColor; } else { return pipe.block.getIcon(side, pipe.meta); } } } - return RenderBlockMultipass.currentPass == 1 ? this.overlay : this.blockIcon; + return RenderBlockMultipass.currentPass == 1 ? this.overlay : RenderBlockMultipass.currentPass == 2 ? this.overlayColor : this.blockIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess world, int x, int y, int z) { + if (RenderBlockMultipass.currentPass == 2) { + TileEntityOpenComputersCablePaintable tile = (TileEntityOpenComputersCablePaintable) world.getTileEntity(x, y, z); + if (tile == null) + return 0xffffff; + + return tile.getColor(); + } + + return 0xffffff; } @Override @@ -75,7 +102,10 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements ItemStack stack = player.getHeldItem(); - if(stack != null && stack.getItem() instanceof ItemBlock) { + if (stack == null) + return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ); + + if (stack.getItem() instanceof ItemBlock) { ItemBlock ib = (ItemBlock) stack.getItem(); Block block = ib.field_150939_a; @@ -95,6 +125,21 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements } } } + } else { + boolean isDye = false; + int[] dicts = OreDictionary.getOreIDs(stack); + for (int dict : dicts) { + String dictName = OreDictionary.getOreName(dict); + if (dictName.equals("dye")) + isDye = true; + } + + if (isDye) { + TileEntityOpenComputersCablePaintable tile = (TileEntityOpenComputersCablePaintable) world.getTileEntity(x, y, z); + tile.setColor(OCColors.fromDye(stack).getColor()); + world.markBlockForUpdate(x, y, z); + tile.markDirty(); + } } return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ); @@ -123,7 +168,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements @Override public int getPasses() { - return 2; + return 3; } @Override @@ -131,9 +176,12 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements return IBlockMultiPass.getRenderType(); } - // WHY the fuck is this not compiling - @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = "OpenComputers")}) - public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment { + @Optional.InterfaceList({ + @Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = "OpenComputers"), + @Optional.Interface(iface = "li.cil.oc.api.network.SidedEnvironment", modid = "OpenComputers"), + @Optional.Interface(iface = "li.cil.oc.api.network.Colored", modid = "OpenComputers") + }) + public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment, SidedEnvironment, Colored { protected Node node; protected boolean addedToNetwork = false; @@ -142,6 +190,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements private int meta; private Block lastBlock; private int lastMeta; + private OCColors color = OCColors.LIGHTGRAY; public TileEntityOpenComputersCablePaintable() { node = Network.newNode(this, Visibility.None).create(); @@ -181,6 +230,8 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements this.block = id == 0 ? null : Block.getBlockById(id); this.meta = nbt.getInteger("meta"); + this.color = OCColors.fromInt(nbt.getInteger("dyeColor")); + if (node != null && node.host() == this) { node.load(nbt.getCompoundTag("oc:node")); } @@ -192,6 +243,8 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements if(block != null) nbt.setInteger("block", Block.getIdFromBlock(block)); nbt.setInteger("meta", meta); + nbt.setInteger("dyeColor", color.getColor()); + if (node != null && node.host() == this) { final NBTTagCompound nodeNbt = new NBTTagCompound(); node.save(nodeNbt); @@ -212,6 +265,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements if(nbt.hasKey("paintblock")) { this.block = Block.getBlockById(nbt.getInteger("paintblock")); this.meta = nbt.getInteger("paintmeta"); + this.color = OCColors.fromInt(nbt.getInteger("dyeColor")); } } @@ -221,6 +275,30 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements return node; } + public Node sidedNode(ForgeDirection side) { + if (side == ForgeDirection.UNKNOWN) + return null; + + int neighborX = super.xCoord + side.offsetX; + int neighborY = super.yCoord + side.offsetY; + int neighborZ = super.zCoord + side.offsetZ; + TileEntity neighbor = worldObj.getTileEntity(neighborX, neighborY, neighborZ); + + // If a cable does not support colors but is a valid cable block, allow it to connect regardless of color. + if (!(neighbor instanceof Colored)) { + if (neighbor instanceof Environment) + return node; + else + return null; + } + + Colored cable = (Colored) neighbor; + if (cable.getColor() == color.getColor()) + return node; + else + return null; + } + @Override public void onConnect(Node node) {} @@ -240,5 +318,31 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements super.invalidate(); if (node != null) node.remove(); } + + public boolean canConnect(net.minecraftforge.common.util.ForgeDirection side) { + if (side == ForgeDirection.UNKNOWN) + return false; + + int neighborX = super.xCoord + side.offsetX; + int neighborY = super.yCoord + side.offsetY; + int neighborZ = super.zCoord + side.offsetZ; + TileEntity neighbor = worldObj.getTileEntity(neighborX, neighborY, neighborZ); + + // If a cable does not support colors but is a valid cable block, allow it to connect regardless of color. + if (!(neighbor instanceof Colored)) { + return neighbor instanceof Environment; + } + + Colored cable = (Colored) neighbor; + return cable.getColor() == color.getColor(); + } + + public void setColor(int newColor) { + color = OCColors.fromInt(newColor); + } + + public int getColor() { + return color.getColor(); + } } } diff --git a/src/main/java/com/hbm/handler/CompatHandler.java b/src/main/java/com/hbm/handler/CompatHandler.java index 46ce74fc0..ac4bbe114 100644 --- a/src/main/java/com/hbm/handler/CompatHandler.java +++ b/src/main/java/com/hbm/handler/CompatHandler.java @@ -1,11 +1,13 @@ package com.hbm.handler; import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.network.BlockOpenComputersCablePaintable; import com.hbm.inventory.RecipesCommon; import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; +import com.hbm.util.ItemStackUtil; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Optional; import li.cil.oc.api.Items; @@ -15,6 +17,7 @@ import li.cil.oc.api.machine.Context; import li.cil.oc.api.network.*; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -108,27 +111,66 @@ public class CompatHandler { } } - /** - * Simple enum for mapping OC color ordinals to a nicer format for adding new disks. - */ - public enum OCColors { - BLACK, //0x444444 - RED, //0xB3312C - GREEN, //0x339911 - BROWN, //0x51301A - BLUE, //0x6666FF - PURPLE, //0x7B2FBE - CYAN, //0x66FFFF - LIGHTGRAY, //0xABABAB - GRAY, //0x666666 - PINK, //0xD88198 - LIME, //0x66FF66 - YELLOW, //0xFFFF66 - LIGHTBLUE, //0xAAAAFF - MAGENTA, //0xC354CD - ORANGE, //0xEB8844 - WHITE //0xF0F0F0 - } + /** + * Simple enum for mapping OC color ordinals to a nicer format for adding new disks. + */ + public enum OCColors { + BLACK(0x444444, "dyeBlack"), + RED(0xB3312C, "dyeRed"), + GREEN(0x339911, "dyeGreen"), + BROWN(0x51301A, "dyeBrown"), + BLUE(0x6666FF, "dyeBlue"), + PURPLE(0x7B2FBE, "dyePurple"), + CYAN(0x66FFFF, "dyeCyan"), + LIGHTGRAY(0xABABAB, "dyeLightGray"), + GRAY(0x666666, "dyeGray"), + PINK(0xD88198, "dyePink"), + LIME(0x66FF66, "dyeLime"), + YELLOW(0xFFFF66, "dyeYellow"), + LIGHTBLUE(0xAAAAFF, "dyeLightBlue"), + MAGENTA(0xC354CD, "dyeMagenta"), + ORANGE(0xEB8844, "dyeOrange"), + WHITE(0xF0F0F0, "dyeWhite"), + NONE(0x0, ""); + + private final int color; + private final String dictName; + + OCColors(int color, String dictName) { + this.color = color; + this.dictName = dictName; + } + + public int getColor() { + return color; + } + + public static OCColors fromInt(int intColor) { + for (OCColors iColor : OCColors.values()) { + if (intColor == iColor.getColor()) + return iColor; + } + return OCColors.NONE; + } + + public static OCColors fromDye(ItemStack stack) { + List oreNames = ItemStackUtil.getOreDictNames(stack); + + for(String dict : oreNames) { + if(!(dict.length() > 3) || !dict.startsWith("dye")) + continue; + + for (OCColors color : OCColors.values()) { + if(!color.dictName.equals(dict)) + continue; + + return color; + } + } + + return OCColors.NONE; + } + } // Where all disks are stored with their name and `FloppyDisk` class. public static HashMap disks = new HashMap<>(); diff --git a/src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png b/src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png index 243c2da7f8f52b96ec7dba690200d6902ca3ea4d..7c9e1b0dd15b54f089e760fd3361342c81d78654 100644 GIT binary patch delta 587 zcmV-R0<`_`1mpyeB!4SOL_t(IPmPn$PZL2D$G=k+DQj)Cdg0)e#GnvMsUcv=Dq1mk zl0sX-#DBp*fP+_zH{!u7fq3#FXhm!Vg9a-ej8PK~#%R)@K)Wsd-5uvmvg?-Cgh@6t zdHddHzVF8{pU=lHUhtz>D&bcu1w~PCR8`@2xnOXPcBd20wtqHMDiyS}DB^RVR;%ID zm#;`|Z-Xs9Uf?G^9&iA^cXsgo$4_zMIORDZVR|-;Kf8NyA9JB*a8#>RobKola04^5 z55Z>d&v0)~w*+i#enc#uKv~?z#qCF06{zhhNA&-_}7;uOn0x=PAaM6DY&~vs6?~{Ps%S4FbwC2Bh=Klo zyhyyZ6f|wY0iy+&42QYjdtNHgv$;df0Tq$nhHT@VsVVO5K8KfUYe;8w2{5P7ywsdV z`*czl2t>k0uaEG_v72}_H!oi#Ihg^p(;}#OHg}o<={FPz@Lr)HvHsR_Gz08!zz(yQ Z<1fjbRIG!_>}LP~002ovPDHLkV1lxO4jupi delta 599 zcmV-d0;v7u1n>lqB!4$aL_t(IPmNPePg6k@JyTw#t(9P9L!!nNiBTbzrUt4-6pa{N zNufnBaZBRDf8ZXs#DyypB5|R(p?)A*!5|?O7cSHUjWL=u$Vb~(`rUV(JISlB+C*;h zGLw1to;l~-JHqGl(Ww)DD-OeCOb8g{!}XmYz@5W(qiz<<%$h*GJ9h6YW3HdHDV zeE9eYiM2I|nFmv}&*K3B__eWtZ{L5&9ihduSAnH<9qXH0XxigO#UPZ+WgKX2mEZ=( zC+?QMBx2ZTUApGP*Eg%}XW;v8-aT2oV_!(S(V^C)XVPk>X6;A2Gi$m zC=YrA0Yv9sVk?!Z0l0VLD_Wcy#-;*Fo*As48L$iy4u1_$Ur!J-vvV~7?DFHAU$CAl zV@bb-$%oVR0V1Ig_4l2X5}womc$%AWy1N^P4(?a8@hBRt0&r*e0>$8Jc!*B={g|Df zmo)!K_@A5H0R_M&2D`fOJodVV!Hxk&!eR1zk1GagJ+q@ZU=z7Js*Tr2N6FiM3@;WI zkW8f&fKWMwCJS>Kt<%X}U=VTXVn2-xT*2MR`|3qbLAOOc|E}(bxH=Y l#kbW&v%vZWtYB7uegh`$POLLim?QuI002ovPDHLkV1jWf8Vvvd diff --git a/src/main/resources/assets/hbm/textures/blocks/oc_cable_color.png b/src/main/resources/assets/hbm/textures/blocks/oc_cable_color.png new file mode 100644 index 0000000000000000000000000000000000000000..1a3be6c7bb723b6a0d52cc6190ff27529f04a829 GIT binary patch literal 111 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`W}YsNAr}70DGLM)f>z8=+#&Tr zo?}BRud={`?qpu(35+kgHg-1hNS|X15b0R5TV+J!Z|a0VjCfT@vZ7+!wnWN6x=%|Mm`bv{=a#Cg9nWG^=%&j5S6G7^>bP0l+XkK De2Z3~ From 76368acbf8aa770605a2f65e3b142baa70acf217 Mon Sep 17 00:00:00 2001 From: PewPewCricket Date: Mon, 14 Jul 2025 20:52:12 -0500 Subject: [PATCH 3/4] remove unused imports in BlockOpenComputersCablePaintable.java --- .../hbm/blocks/network/BlockOpenComputersCablePaintable.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java index 915fb58f0..c18f5ce2b 100644 --- a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java +++ b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java @@ -2,8 +2,6 @@ package com.hbm.blocks.network; import api.hbm.block.IToolable; import com.hbm.blocks.IBlockMultiPass; -import com.hbm.blocks.ILookOverlay; -import com.hbm.handler.CompatHandler; import com.hbm.lib.RefStrings; import com.hbm.render.block.RenderBlockMultipass; import com.hbm.tileentity.TileEntityLoadedBase; @@ -15,9 +13,7 @@ import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemDye; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -32,7 +28,6 @@ import li.cil.oc.api.network.Node; import li.cil.oc.api.Network; import li.cil.oc.api.network.Visibility; import cpw.mods.fml.common.Optional; -import cpw.mods.fml.common.Loader; import li.cil.oc.api.network.SidedEnvironment; import net.minecraftforge.common.util.ForgeDirection; import li.cil.oc.api.internal.Colored; From 5f8b0f6aedc1445b934a59ef5b73543f62584995 Mon Sep 17 00:00:00 2001 From: PewPewCricket Date: Tue, 15 Jul 2025 04:10:06 -0500 Subject: [PATCH 4/4] fix TileEntityOpenComputersCablePaintable not implementing ICopyable and add null check for ModBlocks.oc_cable_paintable in CraftingManager.java --- .../hbm/blocks/network/BlockOpenComputersCablePaintable.java | 3 ++- src/main/java/com/hbm/main/CraftingManager.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java index c18f5ce2b..d40d81595 100644 --- a/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java +++ b/src/main/java/com/hbm/blocks/network/BlockOpenComputersCablePaintable.java @@ -2,6 +2,7 @@ package com.hbm.blocks.network; import api.hbm.block.IToolable; import com.hbm.blocks.IBlockMultiPass; +import com.hbm.interfaces.ICopiable; import com.hbm.lib.RefStrings; import com.hbm.render.block.RenderBlockMultipass; import com.hbm.tileentity.TileEntityLoadedBase; @@ -176,7 +177,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements @Optional.Interface(iface = "li.cil.oc.api.network.SidedEnvironment", modid = "OpenComputers"), @Optional.Interface(iface = "li.cil.oc.api.network.Colored", modid = "OpenComputers") }) - public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment, SidedEnvironment, Colored { + public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment, SidedEnvironment, Colored, ICopiable { protected Node node; protected boolean addedToNetwork = false; diff --git a/src/main/java/com/hbm/main/CraftingManager.java b/src/main/java/com/hbm/main/CraftingManager.java index d91f00033..89650f200 100644 --- a/src/main/java/com/hbm/main/CraftingManager.java +++ b/src/main/java/com/hbm/main/CraftingManager.java @@ -237,7 +237,8 @@ public class CraftingManager { addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_electric_furnace_off), 1), new Object[] { "BBB", "WFW", "RRR", 'B', BE.ingot(), 'R', ModItems.coil_tungsten, 'W', CU.plateCast(), 'F', Item.getItemFromBlock(Blocks.furnace) }); addRecipeAuto(new ItemStack(ModBlocks.red_wire_coated, 16), new Object[] { "WRW", "RIR", "WRW", 'W', ModItems.plate_polymer, 'I', MINGRADE.ingot(), 'R', MINGRADE.wireFine() }); addRecipeAuto(new ItemStack(ModBlocks.red_cable_paintable, 16), new Object[] { "WRW", "RIR", "WRW", 'W', STEEL.plate(), 'I', MINGRADE.ingot(), 'R', MINGRADE.wireFine() }); - addRecipeAuto(new ItemStack(ModBlocks.oc_cable_paintable, 16), new Object[] { "WRW", "RIR", "WRW", 'W', STEEL.plate(), 'I', REDSTONE.dust(), 'R', MINGRADE.wireFine() }); + if (ModBlocks.oc_cable_paintable != null) + addRecipeAuto(new ItemStack(ModBlocks.oc_cable_paintable, 16), new Object[] { "WRW", "RIR", "WRW", 'W', STEEL.plate(), 'I', REDSTONE.dust(), 'R', MINGRADE.wireFine() }); addRecipeAuto(new ItemStack(ModBlocks.cable_switch, 1), new Object[] { "S", "W", 'S', Blocks.lever, 'W', ModBlocks.red_wire_coated }); addRecipeAuto(new ItemStack(ModBlocks.cable_detector, 1), new Object[] { "S", "W", 'S', REDSTONE.dust(), 'W', ModBlocks.red_wire_coated }); addRecipeAuto(new ItemStack(ModBlocks.cable_diode, 1), new Object[] { " Q ", "CAC", " Q ", 'Q', SI.nugget(), 'C', ModBlocks.red_cable, 'A', AL.ingot() });