From 1cae25ad797ad3ddfc9f00770969a49780817a4f Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 21 Dec 2013 22:49:08 -0500 Subject: [PATCH] re-added wires --- .../assemblyline/AssemblyLine.java | 4 +- .../assemblyline/transmit/BlockWire.java | 293 ++++++++++++++++++ .../assemblyline/transmit/ItemBlockWire.java | 22 ++ .../transmit/TileEntityDetectorWire.java | 20 ++ .../transmit/TileEntitySwitchWire.java | 40 +++ .../assemblyline/transmit/TileEntityWire.java | 125 ++++++++ 6 files changed, 503 insertions(+), 1 deletion(-) create mode 100644 src/com/builtbroken/assemblyline/transmit/BlockWire.java create mode 100644 src/com/builtbroken/assemblyline/transmit/ItemBlockWire.java create mode 100644 src/com/builtbroken/assemblyline/transmit/TileEntityDetectorWire.java create mode 100644 src/com/builtbroken/assemblyline/transmit/TileEntitySwitchWire.java create mode 100644 src/com/builtbroken/assemblyline/transmit/TileEntityWire.java diff --git a/src/com/builtbroken/assemblyline/AssemblyLine.java b/src/com/builtbroken/assemblyline/AssemblyLine.java index 3f359b648..18426b3e9 100644 --- a/src/com/builtbroken/assemblyline/AssemblyLine.java +++ b/src/com/builtbroken/assemblyline/AssemblyLine.java @@ -88,6 +88,8 @@ import com.builtbroken.assemblyline.machine.encoder.BlockEncoder; import com.builtbroken.assemblyline.machine.encoder.ItemDisk; import com.builtbroken.assemblyline.machine.processor.BlockProcessor; import com.builtbroken.assemblyline.machine.red.BlockAdvancedHopper; +import com.builtbroken.assemblyline.transmit.BlockWire; +import com.builtbroken.assemblyline.transmit.ItemBlockWire; import com.builtbroken.assemblyline.worldgen.OreGenReplaceStone; import com.builtbroken.assemblyline.worldgen.OreGenerator; import com.builtbroken.minecraft.CoreRegistry; @@ -290,7 +292,7 @@ public class AssemblyLine ALRecipeLoader.blockSteamGen = CoreRegistry.createNewBlock("DMBlockSteamMachine", AssemblyLine.MOD_ID, BlockSmallSteamGen.class, ItemBlockHolder.class); ALRecipeLoader.blockOre = CoreRegistry.createNewBlock("DMBlockOre", AssemblyLine.MOD_ID, BlockOre.class, ItemBlockOre.class); - //ALRecipeLoader.blockWire = CoreRegistry.createNewBlock("DMBlockWire", AssemblyLine.MOD_ID, BlockWire.class, ItemBlockWire.class); + ALRecipeLoader.blockWire = CoreRegistry.createNewBlock("DMBlockWire", AssemblyLine.MOD_ID, BlockWire.class, ItemBlockWire.class); ALRecipeLoader.blockDebug = CoreRegistry.createNewBlock("DMBlockDebug", AssemblyLine.MOD_ID, BlockDebug.class, ItemBlockHolder.class); ALRecipeLoader.blockStainGlass = CoreRegistry.createNewBlock("DMBlockStainedGlass", AssemblyLine.MOD_ID, BlockColorGlass.class, ItemBlockColored.class); ALRecipeLoader.blockColorSand = CoreRegistry.createNewBlock("DMBlockColorSand", AssemblyLine.MOD_ID, BlockColorSand.class, ItemBlockColored.class); diff --git a/src/com/builtbroken/assemblyline/transmit/BlockWire.java b/src/com/builtbroken/assemblyline/transmit/BlockWire.java new file mode 100644 index 000000000..d343d1c93 --- /dev/null +++ b/src/com/builtbroken/assemblyline/transmit/BlockWire.java @@ -0,0 +1,293 @@ +package com.builtbroken.assemblyline.transmit; + +import java.util.List; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.oredict.OreDictionary; +import universalelectricity.api.energy.IConductor; +import universalelectricity.api.vector.Vector3; + +import com.builtbroken.assemblyline.AssemblyLine; +import com.builtbroken.assemblyline.client.render.RenderBlockWire; +import com.builtbroken.common.Pair; +import com.builtbroken.minecraft.IndustryTabs; +import com.builtbroken.minecraft.prefab.BlockMachine; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockWire extends BlockMachine +{ + public static float wireResistance = 0.001f; + public static long energyMax = 100000; + public boolean isWireCollision = true; + public Vector3 minVector = new Vector3(0.3, 0.3, 0.3); + public Vector3 maxVector = new Vector3(0.7, 0.7, 0.7); + + @SideOnly(Side.CLIENT) + public Icon wireIcon; + + public BlockWire() + { + super(AssemblyLine.CONFIGURATION, "DMWire", Material.cloth); + this.setStepSound(soundClothFootstep); + this.setResistance(0.2F); + this.setHardness(0.1f); + this.setBlockBounds(0.3f, 0.3f, 0.3f, 0.7f, 0.7f, 0.7f); + Block.setBurnProperties(this.blockID, 30, 60); + this.setCreativeTab(IndustryTabs.tabIndustrial()); + } + + @Override + public void registerIcons(IconRegister par1IconRegister) + { + this.wireIcon = par1IconRegister.registerIcon(AssemblyLine.PREFIX + "CopperWire"); + } + + @Override + @SideOnly(Side.CLIENT) + public Icon getIcon(int side, int meta) + { + if (meta == 17) + { + return this.blockIcon; + } + return Block.blockRedstone.getIcon(side, 0); + } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + public int getRenderType() + { + return this.zeroRendering ? 0 : -1; + } + + @Override + public TileEntity createTileEntity(World world, int metadata) + { + if (metadata == 1) + { + return new TileEntityDetectorWire(); + } + else if (metadata == 2) + { + return new TileEntitySwitchWire(); + } + return this.createNewTileEntity(world); + } + + @Override + public TileEntity createNewTileEntity(World world) + { + return new TileEntityWire(); + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + super.onBlockAdded(world, x, y, z); + + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + setBlockBoundsBasedOnState(world, x, y, z); + if (tileEntity instanceof TileEntityWire) + { + ((TileEntityWire) tileEntity).refresh(); + } + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int blockID) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + setBlockBoundsBasedOnState(world, x, y, z); + if (tileEntity instanceof TileEntityWire) + { + ((TileEntityWire) tileEntity).refresh(); + } + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { + this.setBlockBoundsBasedOnState(world, x, y, z); + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) + { + this.setBlockBoundsBasedOnState(world, x, y, z); + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + } + + /** Returns the bounding box of the wired rectangular prism to render. */ + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) + { + if (this.isWireCollision) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileEntityWire) + { + TileEntity[] connectable = ((TileEntityWire) tileEntity).getConnections(); + + if (connectable != null) + { + float minX = (float) this.minVector.x; + float minY = (float) this.minVector.y; + float minZ = (float) this.minVector.z; + float maxX = (float) this.maxVector.x; + float maxY = (float) this.maxVector.y; + float maxZ = (float) this.maxVector.z; + + if (connectable[0] != null) + { + minY = 0.0F; + } + + if (connectable[1] != null) + { + maxY = 1.0F; + } + + if (connectable[2] != null) + { + minZ = 0.0F; + } + + if (connectable[3] != null) + { + maxZ = 1.0F; + } + + if (connectable[4] != null) + { + minX = 0.0F; + } + + if (connectable[5] != null) + { + maxX = 1.0F; + } + + this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ); + } + } + } + } + + @Override + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List list, Entity entity) + { + if (this.isWireCollision) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileEntityWire) + { + TileEntity[] connectable = ((TileEntityWire) tileEntity).getConnections(); + + this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + + if (connectable[4] != null) + { + this.setBlockBounds(0, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + if (connectable[5] != null) + { + this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, 1, (float) this.maxVector.y, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + if (connectable[0] != null) + { + this.setBlockBounds((float) this.minVector.x, 0, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + if (connectable[1] != null) + { + this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, 1, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + if (connectable[2] != null) + { + this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, 0, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + if (connectable[3] != null) + { + this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, 1); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + } + else + { + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + } + + @Override + public void getTileEntities(int blockID, Set>> list) + { + list.add(new Pair>("DMWireTile", TileEntityWire.class)); + } + + @Override + @SideOnly(Side.CLIENT) + public void getClientTileEntityRenderers(List, TileEntitySpecialRenderer>> list) + { + if (!this.zeroRendering) + { + list.add(new Pair, TileEntitySpecialRenderer>(TileEntityWire.class, new RenderBlockWire())); + } + } + + @Override + public boolean hasExtraConfigs() + { + return true; + } + + @Override + public void loadExtraConfigs(Configuration config) + { + super.loadExtraConfigs(config); + BlockWire.wireResistance = config.get("Settings", "miliOhms", 1, "Resistance of the wire in 1/1000 of an ohm").getInt() / 1000; + BlockWire.energyMax = config.get("Settings", "maxEnergy", energyMax, "Max energy the wire can move at any given time").getInt(); + + } + + @Override + public void loadOreNames() + { + OreDictionary.registerOre("copperwire", new ItemStack(this, 1, 0)); + OreDictionary.registerOre("wirecopper", new ItemStack(this, 1, 0)); + } +} diff --git a/src/com/builtbroken/assemblyline/transmit/ItemBlockWire.java b/src/com/builtbroken/assemblyline/transmit/ItemBlockWire.java new file mode 100644 index 000000000..c6c39ea72 --- /dev/null +++ b/src/com/builtbroken/assemblyline/transmit/ItemBlockWire.java @@ -0,0 +1,22 @@ +package com.builtbroken.assemblyline.transmit; + +import net.minecraft.util.Icon; + +import com.builtbroken.assemblyline.ALRecipeLoader; +import com.builtbroken.minecraft.prefab.ItemBlockHolder; + +public class ItemBlockWire extends ItemBlockHolder +{ + + public ItemBlockWire(int id) + { + super(id); + } + + @Override + public Icon getIconFromDamage(int par1) + { + return ALRecipeLoader.blockWire instanceof BlockWire ? ((BlockWire) ALRecipeLoader.blockWire).wireIcon : ALRecipeLoader.blockWire.getIcon(0, par1); + } + +} diff --git a/src/com/builtbroken/assemblyline/transmit/TileEntityDetectorWire.java b/src/com/builtbroken/assemblyline/transmit/TileEntityDetectorWire.java new file mode 100644 index 000000000..23acdaf0c --- /dev/null +++ b/src/com/builtbroken/assemblyline/transmit/TileEntityDetectorWire.java @@ -0,0 +1,20 @@ +package com.builtbroken.assemblyline.transmit; + +public class TileEntityDetectorWire extends TileEntityWire +{ + + @Override + public void updateEntity() + { + if (!this.worldObj.isRemote && this.getNetwork() != null && this.ticks % 5 == 0) + { + //TODO if produced watts > minimal set value by the detector gui activate redstone on all sides + } + } + + @Override + public boolean canUpdate() + { + return true; + } +} diff --git a/src/com/builtbroken/assemblyline/transmit/TileEntitySwitchWire.java b/src/com/builtbroken/assemblyline/transmit/TileEntitySwitchWire.java new file mode 100644 index 000000000..41a39e29f --- /dev/null +++ b/src/com/builtbroken/assemblyline/transmit/TileEntitySwitchWire.java @@ -0,0 +1,40 @@ +package com.builtbroken.assemblyline.transmit; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +public class TileEntitySwitchWire extends TileEntityWire +{ + protected boolean activated = true; + + @Override + public TileEntity[] getConnections() + { + if (activated) + { + return super.getConnections(); + } + return null; + } + + public void setActivate(boolean yes) + { + boolean p = this.activated; + this.activated = yes; + if (p != this.activated) + { + this.refresh(); + } + } + + public boolean getActivated() + { + return this.activated; + } + + @Override + public boolean canConnect(ForgeDirection direction) + { + return this.getActivated(); + } +} diff --git a/src/com/builtbroken/assemblyline/transmit/TileEntityWire.java b/src/com/builtbroken/assemblyline/transmit/TileEntityWire.java new file mode 100644 index 000000000..71e97bea8 --- /dev/null +++ b/src/com/builtbroken/assemblyline/transmit/TileEntityWire.java @@ -0,0 +1,125 @@ +package com.builtbroken.assemblyline.transmit; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.api.energy.EnergyNetworkLoader; +import universalelectricity.api.energy.IConductor; +import universalelectricity.api.energy.IEnergyNetwork; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; +import universalelectricity.core.net.EnergyNetwork; + +import com.builtbroken.minecraft.helpers.ColorCode; +import com.builtbroken.minecraft.prefab.TileEntityAdvanced; + +public class TileEntityWire extends TileEntityAdvanced implements IConductor +{ + protected int updateTick = 1; + protected ColorCode color = ColorCode.BLACK; + + private IEnergyNetwork network; + + public TileEntity[] connections = new TileEntity[6]; + + @Override + public void updateEntity() + { + super.updateEntity(); + if (!worldObj.isRemote) + { + if (ticks % this.updateTick == 0) + { + this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20; + this.refresh(); + } + } + } + + public void refresh() + { + this.connections = new TileEntity[6]; + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + if (this.canConnect(direction.getOpposite())) + { + TileEntity entity = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), direction); + if (CompatibilityModule.isHandler(entity)) + { + this.connections[direction.ordinal()] = entity; + } + } + } + } + + @Override + public boolean canUpdate() + { + return true; + } + + @Override + public TileEntity[] getConnections() + { + if (this.connections == null) + { + this.refresh(); + } + return this.connections; + } + + @Override + public IEnergyNetwork getNetwork() + { + if (!(this.network instanceof IEnergyNetwork)) + { + this.network = EnergyNetworkLoader.getNewNetwork(this); + } + return this.network; + } + + @Override + public void setNetwork(IEnergyNetwork network) + { + if (network instanceof IEnergyNetwork) + { + this.network = (EnergyNetwork) network; + } + } + + @Override + public boolean canConnect(ForgeDirection direction) + { + return true; + } + + @Override + public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) + { + if (this.canConnect(from) && network != null) + { + return network.produce(receive); + } + return 0; + } + + @Override + public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract) + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getEnergyLoss() + { + return 0; + } + + @Override + public long getEnergyCapacitance() + { + return BlockWire.energyMax; + } + +}