diff --git a/src/main/java/api/hbm/energy/IEnergyConnector.java b/src/main/java/api/hbm/energy/IEnergyConnector.java index 0891a9d90..f6bc475f0 100644 --- a/src/main/java/api/hbm/energy/IEnergyConnector.java +++ b/src/main/java/api/hbm/energy/IEnergyConnector.java @@ -4,6 +4,7 @@ import net.minecraftforge.common.util.ForgeDirection; /** * For anything that connects to power and can be transferred power to, the bottom-level interface. + * This is mean for TILE ENTITIES * @author hbm */ public interface IEnergyConnector { diff --git a/src/main/java/api/hbm/energy/IEnergyConnectorBlock.java b/src/main/java/api/hbm/energy/IEnergyConnectorBlock.java new file mode 100644 index 000000000..53253b3ed --- /dev/null +++ b/src/main/java/api/hbm/energy/IEnergyConnectorBlock.java @@ -0,0 +1,25 @@ +package api.hbm.energy; + +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Interface for all blocks that should visually connect to cables without having an IEnergyConnector tile entity. + * This is meant for BLOCKS + * @author hbm + * + */ +public interface IEnergyConnectorBlock { + + /** + * Same as IEnergyConnector's method but for regular blocks that might not even have TEs. Used for rendering only! + * @param world + * @param x + * @param y + * @param z + * @param dir + * @return + */ + public boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir); +} diff --git a/src/main/java/com/hbm/interfaces/package-info.java b/src/main/java/com/hbm/interfaces/package-info.java new file mode 100644 index 000000000..d3a3d0506 --- /dev/null +++ b/src/main/java/com/hbm/interfaces/package-info.java @@ -0,0 +1,5 @@ +package com.hbm.interfaces; + +/* + * Please kill me + */ \ No newline at end of file diff --git a/src/main/java/com/hbm/render/block/RenderTestCable.java b/src/main/java/com/hbm/render/block/RenderTestCable.java index cfb2e8462..a25dda220 100644 --- a/src/main/java/com/hbm/render/block/RenderTestCable.java +++ b/src/main/java/com/hbm/render/block/RenderTestCable.java @@ -7,13 +7,16 @@ import com.hbm.main.ResourceManager; import com.hbm.render.util.ObjUtil; import api.hbm.energy.IEnergyConnector; +import api.hbm.energy.IEnergyConnectorBlock; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.model.obj.WavefrontObject; +import net.minecraftforge.common.util.ForgeDirection; public class RenderTestCable implements ISimpleBlockRenderingHandler { @@ -56,12 +59,12 @@ public class RenderTestCable implements ISimpleBlockRenderingHandler { tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); tessellator.setColorOpaque_F(1, 1, 1); - boolean pX = world.getTileEntity(x + 1, y, z) instanceof IEnergyConnector; - boolean nX = world.getTileEntity(x - 1, y, z) instanceof IEnergyConnector; - boolean pY = y > 255 ? false : world.getTileEntity(x, y + 1, z) instanceof IEnergyConnector; - boolean nY = y < 0 ? false : world.getTileEntity(x, y - 1, z) instanceof IEnergyConnector; - boolean pZ = world.getTileEntity(x, y, z + 1) instanceof IEnergyConnector; - boolean nZ = world.getTileEntity(x, y, z - 1) instanceof IEnergyConnector; + boolean pX = canConnect(world, x + 1, y, z, ForgeDirection.EAST); + boolean nX = canConnect(world, x - 1, y, z, ForgeDirection.WEST); + boolean pY = canConnect(world, x, y + 1, z, ForgeDirection.UP); + boolean nY = canConnect(world, x, y - 1, z, ForgeDirection.DOWN); + boolean pZ = canConnect(world, x, y, z + 1, ForgeDirection.SOUTH); + boolean nZ = canConnect(world, x, y, z - 1, ForgeDirection.NORTH); tessellator.addTranslation(x + 0.5F, y + 0.5F, z + 0.5F); @@ -86,6 +89,31 @@ public class RenderTestCable implements ISimpleBlockRenderingHandler { return true; } + + private boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir) { + + if(y > 255 || y < 0) + return false; + + Block b = world.getBlock(x, y, z); + TileEntity te = world.getTileEntity(x, y, z); + + if(b instanceof IEnergyConnectorBlock) { + IEnergyConnectorBlock con = (IEnergyConnectorBlock) b; + + if(con.canConnect(world, x, y, z, dir)) + return true; + } + + if(te instanceof IEnergyConnectorBlock) { + IEnergyConnector con = (IEnergyConnector) te; + + if(con.canConnect(dir)) + return true; + } + + return false; + } @Override public boolean shouldRender3DInInventory(int modelId) {