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 000000000..243c2da7f Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/oc_cable_base.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/oc_cable_overlay.png b/src/main/resources/assets/hbm/textures/blocks/oc_cable_overlay.png new file mode 100644 index 000000000..15fcf03e6 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/oc_cable_overlay.png differ