From fe9cd85564117d59eb274394956c9f4206e7d877 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Mon, 5 Aug 2013 23:58:44 -0400 Subject: [PATCH] Work on Logistical Transporter --- common/mekanism/client/ClientProxy.java | 2 + .../client/RenderLogisticalTransporter.java | 42 ++++++- .../mekanism/client/TransmitterRenderer.java | 3 + common/mekanism/common/BlockTransmitter.java | 5 +- .../common/ILogisticalTransporter.java | 6 + .../TileEntityLogisticalTransporter.java | 2 +- common/mekanism/common/TransporterUtils.java | 109 ++++++++++++++++++ 7 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 common/mekanism/common/ILogisticalTransporter.java create mode 100644 common/mekanism/common/TransporterUtils.java diff --git a/common/mekanism/client/ClientProxy.java b/common/mekanism/client/ClientProxy.java index b977636be..2033253c8 100644 --- a/common/mekanism/client/ClientProxy.java +++ b/common/mekanism/client/ClientProxy.java @@ -31,6 +31,7 @@ import mekanism.common.TileEntityEnergyCube; import mekanism.common.TileEntityEnrichmentChamber; import mekanism.common.TileEntityFactory; import mekanism.common.TileEntityGasTank; +import mekanism.common.TileEntityLogisticalTransporter; import mekanism.common.TileEntityMechanicalPipe; import mekanism.common.TileEntityMetallurgicInfuser; import mekanism.common.TileEntityOsmiumCompressor; @@ -187,6 +188,7 @@ public class ClientProxy extends CommonProxy ClientRegistry.registerTileEntity(TileEntityDynamicTank.class, "DynamicTank", new RenderDynamicTank()); ClientRegistry.registerTileEntity(TileEntityDynamicValve.class, "DynamicValve", new RenderDynamicTank()); ClientRegistry.registerTileEntity(TileEntityChargepad.class, "Chargepad", new RenderChargepad()); + ClientRegistry.registerTileEntity(TileEntityLogisticalTransporter.class, "LogisticalTransporter", new RenderLogisticalTransporter()); } @Override diff --git a/common/mekanism/client/RenderLogisticalTransporter.java b/common/mekanism/client/RenderLogisticalTransporter.java index 75dbb1811..746019b93 100644 --- a/common/mekanism/client/RenderLogisticalTransporter.java +++ b/common/mekanism/client/RenderLogisticalTransporter.java @@ -1,6 +1,44 @@ package mekanism.client; -public class RenderLogisticalTransporter -{ +import mekanism.common.MekanismUtils; +import mekanism.common.MekanismUtils.ResourceType; +import mekanism.common.TileEntityLogisticalTransporter; +import mekanism.common.TransporterUtils; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import org.lwjgl.opengl.GL11; + +public class RenderLogisticalTransporter extends TileEntitySpecialRenderer +{ + private ModelTransmitter model = new ModelTransmitter(); + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) + { + renderAModelAt((TileEntityLogisticalTransporter)tileEntity, x, y, z, partialTick); + } + + @SuppressWarnings("incomplete-switch") + public void renderAModelAt(TileEntityLogisticalTransporter tileEntity, double x, double y, double z, float partialTick) + { + func_110628_a(MekanismUtils.getResource(ResourceType.RENDER, "LogisticalTransporter.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); + GL11.glScalef(1.0F, -1F, -1F); + GL11.glDisable(GL11.GL_CULL_FACE); + + boolean[] connectable = TransporterUtils.getConnections(tileEntity); + + model.renderCenter(connectable); + + for(int i = 0; i < 6; i++) + { + model.renderSide(ForgeDirection.getOrientation(i), connectable[i]); + } + + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glPopMatrix(); + } } diff --git a/common/mekanism/client/TransmitterRenderer.java b/common/mekanism/client/TransmitterRenderer.java index 3c60b3196..3401ba668 100644 --- a/common/mekanism/client/TransmitterRenderer.java +++ b/common/mekanism/client/TransmitterRenderer.java @@ -39,6 +39,9 @@ public class TransmitterRenderer implements ISimpleBlockRenderingHandler case 2: Minecraft.getMinecraft().renderEngine.func_110577_a(MekanismUtils.getResource(ResourceType.RENDER, "MechanicalPipe.png")); break; + case 3: + Minecraft.getMinecraft().renderEngine.func_110577_a(MekanismUtils.getResource(ResourceType.RENDER, "LogisticalTransporter.png")); + break; } transmitter.renderSide(ForgeDirection.UP, true); diff --git a/common/mekanism/common/BlockTransmitter.java b/common/mekanism/common/BlockTransmitter.java index c0472a684..e329daae1 100644 --- a/common/mekanism/common/BlockTransmitter.java +++ b/common/mekanism/common/BlockTransmitter.java @@ -198,6 +198,10 @@ public class BlockTransmitter extends Block { connectable = PipeUtils.getConnections(tileEntity); } + else if(world.getBlockMetadata(x, y, z) == 3) + { + connectable = TransporterUtils.getConnections(tileEntity); + } } return connectable; @@ -387,5 +391,4 @@ public class BlockTransmitter extends Block return itemStack; } - } diff --git a/common/mekanism/common/ILogisticalTransporter.java b/common/mekanism/common/ILogisticalTransporter.java new file mode 100644 index 000000000..b1c29de5c --- /dev/null +++ b/common/mekanism/common/ILogisticalTransporter.java @@ -0,0 +1,6 @@ +package mekanism.common; + +public interface ILogisticalTransporter +{ + +} diff --git a/common/mekanism/common/TileEntityLogisticalTransporter.java b/common/mekanism/common/TileEntityLogisticalTransporter.java index 8499b3818..66ea87a25 100644 --- a/common/mekanism/common/TileEntityLogisticalTransporter.java +++ b/common/mekanism/common/TileEntityLogisticalTransporter.java @@ -2,7 +2,7 @@ package mekanism.common; import net.minecraft.tileentity.TileEntity; -public class TileEntityLogisticalTransporter extends TileEntity +public class TileEntityLogisticalTransporter extends TileEntity implements ILogisticalTransporter { } diff --git a/common/mekanism/common/TransporterUtils.java b/common/mekanism/common/TransporterUtils.java new file mode 100644 index 000000000..f26663e44 --- /dev/null +++ b/common/mekanism/common/TransporterUtils.java @@ -0,0 +1,109 @@ +package mekanism.common; + +import java.util.Arrays; + +import mekanism.api.Object3D; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +public final class TransporterUtils +{ + /** + * Gets all the transporters around a tile entity. + * @param tileEntity - center tile entity + * @return array of TileEntities + */ + public static TileEntity[] getConnectedTransporters(TileEntity tileEntity) + { + TileEntity[] transporters = new TileEntity[] {null, null, null, null, null, null}; + + for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity transporter = Object3D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.worldObj); + + if(transporter instanceof ILogisticalTransporter) + { + transporters[orientation.ordinal()] = transporter; + } + } + + return transporters; + } + + /** + * Gets all the adjacent connections to a TileEntity. + * @param tileEntity - center TileEntity + * @return boolean[] of adjacent connections + */ + public static boolean[] getConnections(TileEntity tileEntity) + { + boolean[] connectable = new boolean[] {false, false, false, false, false, false}; + + TileEntity[] connectedTransporters = getConnectedTransporters(tileEntity); + IInventory[] connectedInventories = getConnectedInventories(tileEntity); + + for(IInventory inventory : connectedInventories) + { + if(inventory != null) + { + int side = Arrays.asList(connectedInventories).indexOf(inventory); + ForgeDirection forgeSide = ForgeDirection.getOrientation(side).getOpposite(); + + if(inventory.getSizeInventory() > 0) + { + if(inventory instanceof ISidedInventory) + { + ISidedInventory sidedInventory = (ISidedInventory)inventory; + + if(sidedInventory.getAccessibleSlotsFromSide(forgeSide.ordinal()) != null) + { + if(sidedInventory.getAccessibleSlotsFromSide(forgeSide.ordinal()).length > 0) + { + connectable[side] = true; + } + } + } + else { + connectable[side] = true; + } + } + } + } + + for(TileEntity tile : connectedTransporters) + { + if(tile != null) + { + int side = Arrays.asList(connectedTransporters).indexOf(tile); + + connectable[side] = true; + } + } + + return connectable; + } + + /** + * Gets all the inventories around a tile entity. + * @param tileEntity - center tile entity + * @return array of IInventories + */ + public static IInventory[] getConnectedInventories(TileEntity tileEntity) + { + IInventory[] inventories = new IInventory[] {null, null, null, null, null, null}; + + for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity inventory = Object3D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.worldObj); + + if(inventory instanceof IInventory && !(inventory instanceof ILogisticalTransporter)) + { + inventories[orientation.ordinal()] = (IInventory)inventory; + } + } + + return inventories; + } +} \ No newline at end of file