From edb4234ad015eea7c7d0320605f2e8bc82787edd Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 28 Oct 2012 17:21:13 +0800 Subject: [PATCH] Massive cleanup to manipulator --- src/common/assemblyline/ALCommonProxy.java | 10 +- src/common/assemblyline/AssemblyLine.java | 10 +- .../belts/TileEntityConveyorBelt.java | 22 +- .../interaction/TileEntityManipulator.java | 342 ------------------ .../BlockInteraction.java | 2 +- .../ContainerSorter.java} | 6 +- .../ItemBlockInteraction.java | 4 +- .../machines/TileEntityManipulator.java | 184 ++++++++++ .../TileEntitySorter.java | 2 +- .../crafter}/BlockCrafter.java | 2 +- .../crafter}/EntityCraftingArm.java | 2 +- .../crafter}/TileEntityAutoCrafter.java | 2 +- .../crafter}/TileEntityCraftingArm.java | 2 +- src/minecraft/assemblyline/ALClientProxy.java | 4 +- ...GuiEjectorSettings.java => GuiSorter.java} | 10 +- .../assemblyline/model/ModelConveyorBelt.java | 8 +- .../render/RenderConveyorBelt.java | 43 ++- .../assemblyline/render/RenderHelper.java | 12 +- .../render/RenderManipulator.java | 50 ++- .../assemblyline/render/RenderSorter.java | 37 +- 20 files changed, 318 insertions(+), 436 deletions(-) delete mode 100644 src/common/assemblyline/interaction/TileEntityManipulator.java rename src/common/assemblyline/{interaction => machines}/BlockInteraction.java (99%) rename src/common/assemblyline/{interaction/ContainerEjector.java => machines/ContainerSorter.java} (93%) rename src/common/assemblyline/{interaction => machines}/ItemBlockInteraction.java (94%) create mode 100644 src/common/assemblyline/machines/TileEntityManipulator.java rename src/common/assemblyline/{interaction => machines}/TileEntitySorter.java (99%) rename src/common/assemblyline/{crafting => machines/crafter}/BlockCrafter.java (95%) rename src/common/assemblyline/{crafting => machines/crafter}/EntityCraftingArm.java (92%) rename src/common/assemblyline/{crafting => machines/crafter}/TileEntityAutoCrafter.java (96%) rename src/common/assemblyline/{crafting => machines/crafter}/TileEntityCraftingArm.java (71%) rename src/minecraft/assemblyline/gui/{GuiEjectorSettings.java => GuiSorter.java} (81%) diff --git a/src/common/assemblyline/ALCommonProxy.java b/src/common/assemblyline/ALCommonProxy.java index 9ad5ad099..5ce3678d6 100644 --- a/src/common/assemblyline/ALCommonProxy.java +++ b/src/common/assemblyline/ALCommonProxy.java @@ -3,9 +3,9 @@ package assemblyline; import net.minecraft.src.EntityPlayer; import net.minecraft.src.TileEntity; import net.minecraft.src.World; -import assemblyline.gui.GuiEjectorSettings; -import assemblyline.interaction.ContainerEjector; -import assemblyline.interaction.TileEntitySorter; +import assemblyline.gui.GuiSorter; +import assemblyline.machines.ContainerSorter; +import assemblyline.machines.TileEntitySorter; import cpw.mods.fml.common.network.IGuiHandler; public class ALCommonProxy implements IGuiHandler @@ -32,7 +32,7 @@ public class ALCommonProxy implements IGuiHandler { switch(ID) { - case 0: return new GuiEjectorSettings(player.inventory, ((TileEntitySorter)tileEntity)); + case 0: return new GuiSorter(player.inventory, ((TileEntitySorter)tileEntity)); } } @@ -48,7 +48,7 @@ public class ALCommonProxy implements IGuiHandler { switch(ID) { - case 0: return new ContainerEjector(player.inventory, ((TileEntitySorter)tileEntity)); + case 0: return new ContainerSorter(player.inventory, ((TileEntitySorter)tileEntity)); } } diff --git a/src/common/assemblyline/AssemblyLine.java b/src/common/assemblyline/AssemblyLine.java index 83485f029..a24e8877f 100644 --- a/src/common/assemblyline/AssemblyLine.java +++ b/src/common/assemblyline/AssemblyLine.java @@ -12,11 +12,11 @@ import universalelectricity.core.UEConfig; import universalelectricity.prefab.network.PacketManager; import assemblyline.belts.BlockConveyorBelt; import assemblyline.belts.TileEntityConveyorBelt; -import assemblyline.interaction.BlockInteraction; -import assemblyline.interaction.BlockInteraction.MachineType; -import assemblyline.interaction.ItemBlockInteraction; -import assemblyline.interaction.TileEntitySorter; -import assemblyline.interaction.TileEntityManipulator; +import assemblyline.machines.BlockInteraction; +import assemblyline.machines.ItemBlockInteraction; +import assemblyline.machines.TileEntityManipulator; +import assemblyline.machines.TileEntitySorter; +import assemblyline.machines.BlockInteraction.MachineType; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; diff --git a/src/common/assemblyline/belts/TileEntityConveyorBelt.java b/src/common/assemblyline/belts/TileEntityConveyorBelt.java index 48effbb72..7e7d1f2ae 100644 --- a/src/common/assemblyline/belts/TileEntityConveyorBelt.java +++ b/src/common/assemblyline/belts/TileEntityConveyorBelt.java @@ -35,7 +35,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem */ public double wattsReceived = 0; - private float speed = -0.05F; + private float speed = -0.045F; public float wheelRotation = 0; public boolean running = false; public boolean flip = false; @@ -43,12 +43,11 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem { null, null, null, null }; public int clearCount = 0; - public int range = 0; + public int powerTransferRange = 0; public List entityIgnoreList = new ArrayList(); /** - * Powers nearby conveyor belts. - * + * Steal power from nearby belts. * @return */ public boolean searchNeighborBelts() @@ -74,13 +73,14 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem if (adjBelts[b] instanceof TileEntityConveyorBelt) { TileEntityConveyorBelt belt = (TileEntityConveyorBelt) adjBelts[b]; - if (belt.range > rr) + if (belt.powerTransferRange > rr) { - rr = belt.range; + rr = belt.powerTransferRange; } } } - this.range = rr - 1; + + this.powerTransferRange = rr - 1; return false; } @@ -98,12 +98,12 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem if (this.wattsReceived >= JOULES_REQUIRED) { - this.wattsReceived = Math.max(this.wattsReceived - JOULES_REQUIRED, 0); - this.range = 20; + this.wattsReceived = 0; + this.powerTransferRange = 20; } else { - this.range = 0; + this.powerTransferRange = 0; } if (!(worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord) instanceof IConductor)) @@ -111,7 +111,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem searchNeighborBelts(); } - if (this.range > 0) + if (this.powerTransferRange > 0) { this.running = true; } diff --git a/src/common/assemblyline/interaction/TileEntityManipulator.java b/src/common/assemblyline/interaction/TileEntityManipulator.java deleted file mode 100644 index 251cad7e5..000000000 --- a/src/common/assemblyline/interaction/TileEntityManipulator.java +++ /dev/null @@ -1,342 +0,0 @@ -package assemblyline.interaction; - -import java.util.List; - -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.IInventory; -import net.minecraft.src.INetworkManager; -import net.minecraft.src.ItemStack; -import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.NBTTagList; -import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.TileEntity; -import net.minecraft.src.TileEntityChest; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.prefab.TileEntityElectricityReceiver; -import universalelectricity.prefab.network.IPacketReceiver; - -import com.google.common.io.ByteArrayDataInput; - -public class TileEntityManipulator extends TileEntityElectricityReceiver implements IPacketReceiver, IInventory -{ - public float energyReq = .1f; - public float energyMax = 10f; - public float energyStor = 0f; - private ItemStack[] containingItems = new ItemStack[1]; - public ForgeDirection dir = ForgeDirection.DOWN; - private int count = 0; - - @Override - public double wattRequest() - { - return energyMax - energyStor; - } - - @Override - public void updateEntity() - { - if (count++ >= 10) - { - count = 0; - if (!isDisabled()) - { - int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); - ForgeDirection searchPosition = ForgeDirection.getOrientation(this.getBeltDirection()); - dir = searchPosition; - try - { - AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(xCoord + searchPosition.offsetX, yCoord + searchPosition.offsetY, zCoord + searchPosition.offsetZ, xCoord + searchPosition.offsetX + 1, yCoord + searchPosition.offsetY + 1, zCoord + searchPosition.offsetZ + 1); - TileEntity bEnt = worldObj.getBlockTileEntity(xCoord + searchPosition.getOpposite().offsetX, yCoord + searchPosition.getOpposite().offsetY, zCoord + searchPosition.getOpposite().offsetZ); - List itemsBehind = worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); - ItemStack tItem = this.containingItems[0]; - if (itemsBehind.size() > 0 && this.energyStor > this.energyReq && bEnt instanceof IInventory) - { - energyStor -= energyReq; - - for (EntityItem entity : itemsBehind) - { - ItemStack eStack = entity.item; - int ite = eStack.stackSize; - if (bEnt instanceof TileEntityChest) - { - TileEntityChest bEntChest2 = null; - TileEntityChest bEntChest = (TileEntityChest) bEnt; - for (int i = 2; i < 6; i++) - { - ForgeDirection si = ForgeDirection.getOrientation(i); - if (worldObj.getBlockTileEntity(xCoord + dir.getOpposite().offsetX + si.offsetX, yCoord + dir.getOpposite().offsetY + si.offsetY, zCoord + dir.getOpposite().offsetZ + si.offsetZ) instanceof TileEntityChest) - { - bEntChest2 = (TileEntityChest) worldObj.getBlockTileEntity(xCoord + dir.getOpposite().offsetX + si.offsetX, yCoord + dir.getOpposite().offsetY + si.offsetY, zCoord + dir.getOpposite().offsetZ + si.offsetZ); - break; - } - } - if (eStack != null && eStack.stackSize > 0) - { - for (int i = 0; i < bEntChest.getSizeInventory(); i++) - { - - ItemStack stack = bEntChest.getStackInSlot(i); - if (stack == null) - { - bEntChest.setInventorySlotContents(i, eStack); - entity.setDead(); - eStack = null; - break; - } - else if (stack.getItem().equals(eStack.getItem()) && stack.getItemDamage() == eStack.getItemDamage()) - { - int rej = Math.max((stack.stackSize + eStack.stackSize) - stack.getItem().getItemStackLimit(), 0); - stack.stackSize = Math.min(Math.max((stack.stackSize + eStack.stackSize - rej), 0), stack.getItem().getItemStackLimit()); - eStack.stackSize = rej; - bEntChest.setInventorySlotContents(i, stack); - if (eStack.stackSize <= 0) - { - entity.setDead(); - eStack = null; - break; - } - - } - - } - } - if (bEntChest2 != null && eStack != null && eStack.stackSize > 0) - { - for (int i = 0; i < bEntChest2.getSizeInventory(); i++) - { - ItemStack stack = bEntChest2.getStackInSlot(i); - if (stack == null) - { - bEntChest2.setInventorySlotContents(i, eStack); - entity.setDead(); - eStack = null; - break; - } - else if (stack.getItem().equals(eStack.getItem()) && stack.getItemDamage() == eStack.getItemDamage()) - { - int rej = Math.max((stack.stackSize + eStack.stackSize) - stack.getItem().getItemStackLimit(), 0); - stack.stackSize = Math.min(Math.max((stack.stackSize + eStack.stackSize - rej), 0), stack.getItem().getItemStackLimit()); - eStack.stackSize = rej; - bEntChest2.setInventorySlotContents(i, stack); - if (eStack.stackSize <= 0) - { - entity.setDead(); - eStack = null; - break; - } - } - } - } - if (entity != null && eStack != null) - { - if (eStack != null && eStack.stackSize <= 0) - { - entity.setDead(); - eStack = null; - break; - } - else - { - entity.setDead(); - EntityItem var23 = new EntityItem(worldObj, entity.posX, entity.posY + 0.1D, entity.posZ, eStack); - worldObj.spawnEntityInWorld(var23); - } - } - - }// end chest trade - // TODO setup for - // ISideInventory - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - } - } - - public int getBeltDirection() - { - int meta = worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); - if (meta >= 4 && meta < 8) - { - switch (meta) - { - case 4: - return 2; - case 5: - return 5; - case 6: - return 3; - case 7: - return 4; - } - } - return 0; - } - - @Override - public boolean canReceiveFromSide(ForgeDirection side) - { - if (side == dir || side == dir.getOpposite()) { return false; } - return true; - } - - @Override - public void readFromNBT(NBTTagCompound par1NBTTagCompound) - { - super.readFromNBT(par1NBTTagCompound); - NBTTagList var2 = par1NBTTagCompound.getTagList("Items"); - this.containingItems = new ItemStack[this.getSizeInventory()]; - - for (int var3 = 0; var3 < var2.tagCount(); ++var3) - { - NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3); - byte var5 = var4.getByte("Slot"); - - if (var5 >= 0 && var5 < this.containingItems.length) - { - this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4); - } - } - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound par1NBTTagCompound) - { - super.writeToNBT(par1NBTTagCompound); - NBTTagList var2 = new NBTTagList(); - - for (int var3 = 0; var3 < this.containingItems.length; ++var3) - { - if (this.containingItems[var3] != null) - { - NBTTagCompound var4 = new NBTTagCompound(); - var4.setByte("Slot", (byte) var3); - this.containingItems[var3].writeToNBT(var4); - var2.appendTag(var4); - } - } - - par1NBTTagCompound.setTag("Items", var2); - } - - @Override - public int getSizeInventory() - { - return this.containingItems.length; - } - - @Override - public ItemStack getStackInSlot(int par1) - { - return this.containingItems[par1]; - } - - @Override - public ItemStack decrStackSize(int par1, int par2) - { - if (this.containingItems[par1] != null) - { - ItemStack var3; - - if (this.containingItems[par1].stackSize <= par2) - { - var3 = this.containingItems[par1]; - this.containingItems[par1] = null; - return var3; - } - else - { - var3 = this.containingItems[par1].splitStack(par2); - - if (this.containingItems[par1].stackSize == 0) - { - this.containingItems[par1] = null; - } - - return var3; - } - } - else - { - return null; - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.containingItems[par1] != null) - { - ItemStack var2 = this.containingItems[par1]; - this.containingItems[par1] = null; - return var2; - } - else - { - return null; - } - } - - @Override - public void setInventorySlotContents(int par1, ItemStack par2ItemStack) - { - this.containingItems[par1] = par2ItemStack; - - if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) - { - par2ItemStack.stackSize = this.getInventoryStackLimit(); - } - } - - @Override - public String getInvName() - { - return "Ejector"; - } - - @Override - public int getInventoryStackLimit() - { - // TODO change - return 0; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) - { - return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; - } - - @Override - public void openChest() - { - } - - @Override - public void closeChest() - { - } - - @Override - public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) - { - this.energyStor += (amps * voltage); - - } - - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - - } -} diff --git a/src/common/assemblyline/interaction/BlockInteraction.java b/src/common/assemblyline/machines/BlockInteraction.java similarity index 99% rename from src/common/assemblyline/interaction/BlockInteraction.java rename to src/common/assemblyline/machines/BlockInteraction.java index 3c8869047..0edf24f9a 100644 --- a/src/common/assemblyline/interaction/BlockInteraction.java +++ b/src/common/assemblyline/machines/BlockInteraction.java @@ -1,4 +1,4 @@ -package assemblyline.interaction; +package assemblyline.machines; import net.minecraft.src.CreativeTabs; import net.minecraft.src.EntityPlayer; diff --git a/src/common/assemblyline/interaction/ContainerEjector.java b/src/common/assemblyline/machines/ContainerSorter.java similarity index 93% rename from src/common/assemblyline/interaction/ContainerEjector.java rename to src/common/assemblyline/machines/ContainerSorter.java index bf67dfec2..0e7a138b2 100644 --- a/src/common/assemblyline/interaction/ContainerEjector.java +++ b/src/common/assemblyline/machines/ContainerSorter.java @@ -1,4 +1,4 @@ -package assemblyline.interaction; +package assemblyline.machines; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; @@ -7,11 +7,11 @@ import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; -public class ContainerEjector extends Container +public class ContainerSorter extends Container { private TileEntitySorter tileEntity; - public ContainerEjector(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity) + public ContainerSorter(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity) { this.tileEntity = tileEntity; for(int i = 0; i < 4; i++) diff --git a/src/common/assemblyline/interaction/ItemBlockInteraction.java b/src/common/assemblyline/machines/ItemBlockInteraction.java similarity index 94% rename from src/common/assemblyline/interaction/ItemBlockInteraction.java rename to src/common/assemblyline/machines/ItemBlockInteraction.java index 41f206a65..fed516eba 100644 --- a/src/common/assemblyline/interaction/ItemBlockInteraction.java +++ b/src/common/assemblyline/machines/ItemBlockInteraction.java @@ -1,4 +1,4 @@ -package assemblyline.interaction; +package assemblyline.machines; import java.util.List; @@ -10,7 +10,7 @@ import net.minecraft.src.ItemStack; import net.minecraft.src.MathHelper; import net.minecraft.src.World; import assemblyline.AssemblyLine; -import assemblyline.interaction.BlockInteraction.MachineType; +import assemblyline.machines.BlockInteraction.MachineType; public class ItemBlockInteraction extends ItemBlock { diff --git a/src/common/assemblyline/machines/TileEntityManipulator.java b/src/common/assemblyline/machines/TileEntityManipulator.java new file mode 100644 index 000000000..75588c6ce --- /dev/null +++ b/src/common/assemblyline/machines/TileEntityManipulator.java @@ -0,0 +1,184 @@ +package assemblyline.machines; + +import java.util.List; + +import net.minecraft.src.AxisAlignedBB; +import net.minecraft.src.EntityItem; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.IInventory; +import net.minecraft.src.INetworkManager; +import net.minecraft.src.ItemStack; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.TileEntity; +import net.minecraft.src.TileEntityChest; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.Vector3; +import universalelectricity.prefab.TileEntityElectricityReceiver; +import universalelectricity.prefab.network.IPacketReceiver; + +import assemblyline.machines.BlockInteraction.MachineType; + +import com.google.common.io.ByteArrayDataInput; + +public class TileEntityManipulator extends TileEntityElectricityReceiver +{ + /** + * Joules required to run this thing. + */ + public static final int JOULES_REQUIRED = 15; + + /** + * The amount of watts received. + */ + public double wattsReceived = 0; + + @Override + public double wattRequest() + { + return JOULES_REQUIRED; + } + + @Override + public void updateEntity() + { + super.updateEntity(); + + if (this.worldObj.isRemote) + { + if (!this.isDisabled()) + { + if (!this.isOutput()) + { + /** + * Find items going into the + * manipulator and input them + * into an inventory behind + * this manipulator. + */ + Vector3 inputPosition = Vector3.get(this); + inputPosition.modifyPositionFromSide(this.getBeltDirection()); + + Vector3 outputPosition = Vector3.get(this); + outputPosition.modifyPositionFromSide(this.getBeltDirection().getOpposite()); + + AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(inputPosition.x, inputPosition.y, inputPosition.z, inputPosition.x + 1, inputPosition.y + 1, inputPosition.z + 1); + List itemsInBound = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); + + for (EntityItem entity : itemsInBound) + { + ItemStack remainingStack = this.tryPlaceInPosition(entity.item.copy(), outputPosition); + + if (remainingStack != null) + { + if (remainingStack.stackSize > 0) + { + EntityItem var23 = new EntityItem(worldObj, entity.posX, entity.posY + 0.1D, entity.posZ, remainingStack); + worldObj.spawnEntityInWorld(var23); + } + } + + entity.setDead(); + } + } + } + } + } + + /** + * Tries to place an itemStack in a specific + * position if it is an inventory. + * + * @return The ItemStack remained after place + * attempt + */ + private ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position) + { + TileEntity tileEntity = position.getTileEntity(this.worldObj); + + if (tileEntity != null) + { + /** + * Try to put items into a chest. + */ + if (tileEntity instanceof TileEntityChest) + { + TileEntityChest[] chests = + { (TileEntityChest) tileEntity, null }; + + /** + * Try to find a double chest. + */ + for (int i = 2; i < 6; i++) + { + ForgeDirection searchDirection = ForgeDirection.getOrientation(i); + Vector3 searchPosition = position.clone(); + searchPosition.modifyPositionFromSide(searchDirection); + + if (searchPosition.getTileEntity(this.worldObj) instanceof TileEntityChest) + { + chests[1] = (TileEntityChest) searchPosition.getTileEntity(this.worldObj); + break; + } + } + + for (TileEntityChest chest : chests) + { + if (itemStack != null && itemStack.stackSize > 0) + { + for (int i = 0; i < chest.getSizeInventory(); i++) + { + ItemStack stackInChest = chest.getStackInSlot(i); + + if (stackInChest == null) + { + chest.setInventorySlotContents(i, itemStack); + return null; + } + else if (stackInChest.getItem().equals(itemStack.getItem()) && stackInChest.getItemDamage() == itemStack.getItemDamage()) + { + int rejectedAmount = Math.max((stackInChest.stackSize + itemStack.stackSize) - stackInChest.getItem().getItemStackLimit(), 0); + stackInChest.stackSize = Math.min(Math.max((stackInChest.stackSize + itemStack.stackSize - rejectedAmount), 0), stackInChest.getItem().getItemStackLimit()); + itemStack.stackSize = rejectedAmount; + chest.setInventorySlotContents(i, stackInChest); + + if (itemStack.stackSize <= 0) { return null; } + + } + + } + } + } + } + } + + if (itemStack.stackSize <= 0) { return null; } + + return itemStack; + } + + /** + * If the manipulator is powered, it will + * output items instead of input. + */ + public boolean isOutput() + { + return this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) || this.worldObj.isBlockGettingPowered(this.xCoord, this.yCoord, this.zCoord); + } + + public ForgeDirection getBeltDirection() + { + return ForgeDirection.getOrientation(MachineType.getDirection(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)) + 2); + } + + @Override + public boolean canReceiveFromSide(ForgeDirection side) + { + return true; + } + + @Override + public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) + { + this.wattsReceived += (amps * voltage); + } +} diff --git a/src/common/assemblyline/interaction/TileEntitySorter.java b/src/common/assemblyline/machines/TileEntitySorter.java similarity index 99% rename from src/common/assemblyline/interaction/TileEntitySorter.java rename to src/common/assemblyline/machines/TileEntitySorter.java index a8024756b..3ec778c38 100644 --- a/src/common/assemblyline/interaction/TileEntitySorter.java +++ b/src/common/assemblyline/machines/TileEntitySorter.java @@ -1,4 +1,4 @@ -package assemblyline.interaction; +package assemblyline.machines; import java.util.List; diff --git a/src/common/assemblyline/crafting/BlockCrafter.java b/src/common/assemblyline/machines/crafter/BlockCrafter.java similarity index 95% rename from src/common/assemblyline/crafting/BlockCrafter.java rename to src/common/assemblyline/machines/crafter/BlockCrafter.java index 4bf756902..8c8861c70 100644 --- a/src/common/assemblyline/crafting/BlockCrafter.java +++ b/src/common/assemblyline/machines/crafter/BlockCrafter.java @@ -1,4 +1,4 @@ -package assemblyline.crafting; +package assemblyline.machines.crafter; import net.minecraft.src.BlockContainer; import net.minecraft.src.CreativeTabs; diff --git a/src/common/assemblyline/crafting/EntityCraftingArm.java b/src/common/assemblyline/machines/crafter/EntityCraftingArm.java similarity index 92% rename from src/common/assemblyline/crafting/EntityCraftingArm.java rename to src/common/assemblyline/machines/crafter/EntityCraftingArm.java index 4328b455b..0ea4f2c61 100644 --- a/src/common/assemblyline/crafting/EntityCraftingArm.java +++ b/src/common/assemblyline/machines/crafter/EntityCraftingArm.java @@ -1,4 +1,4 @@ -package assemblyline.crafting; +package assemblyline.machines.crafter; import net.minecraft.src.Entity; import net.minecraft.src.NBTTagCompound; diff --git a/src/common/assemblyline/crafting/TileEntityAutoCrafter.java b/src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java similarity index 96% rename from src/common/assemblyline/crafting/TileEntityAutoCrafter.java rename to src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java index 996c5c678..fb289912c 100644 --- a/src/common/assemblyline/crafting/TileEntityAutoCrafter.java +++ b/src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java @@ -1,4 +1,4 @@ -package assemblyline.crafting; +package assemblyline.machines.crafter; import net.minecraft.src.EntityPlayer; import net.minecraft.src.INetworkManager; diff --git a/src/common/assemblyline/crafting/TileEntityCraftingArm.java b/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java similarity index 71% rename from src/common/assemblyline/crafting/TileEntityCraftingArm.java rename to src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java index 1bb10ab21..9f48622e4 100644 --- a/src/common/assemblyline/crafting/TileEntityCraftingArm.java +++ b/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java @@ -1,4 +1,4 @@ -package assemblyline.crafting; +package assemblyline.machines.crafter; import net.minecraft.src.TileEntity; diff --git a/src/minecraft/assemblyline/ALClientProxy.java b/src/minecraft/assemblyline/ALClientProxy.java index 9f1ae04a0..ca4a491fb 100644 --- a/src/minecraft/assemblyline/ALClientProxy.java +++ b/src/minecraft/assemblyline/ALClientProxy.java @@ -4,8 +4,8 @@ import net.minecraftforge.client.MinecraftForgeClient; import assemblyline.AssemblyLine; import assemblyline.ALCommonProxy; import assemblyline.belts.TileEntityConveyorBelt; -import assemblyline.interaction.TileEntitySorter; -import assemblyline.interaction.TileEntityManipulator; +import assemblyline.machines.TileEntityManipulator; +import assemblyline.machines.TileEntitySorter; import assemblyline.render.RenderSorter; import assemblyline.render.RenderHelper; import assemblyline.render.RenderConveyorBelt; diff --git a/src/minecraft/assemblyline/gui/GuiEjectorSettings.java b/src/minecraft/assemblyline/gui/GuiSorter.java similarity index 81% rename from src/minecraft/assemblyline/gui/GuiEjectorSettings.java rename to src/minecraft/assemblyline/gui/GuiSorter.java index 683c82a45..7108fd046 100644 --- a/src/minecraft/assemblyline/gui/GuiEjectorSettings.java +++ b/src/minecraft/assemblyline/gui/GuiSorter.java @@ -7,19 +7,19 @@ import net.minecraft.src.StatCollector; import org.lwjgl.opengl.GL11; import assemblyline.AssemblyLine; -import assemblyline.interaction.ContainerEjector; -import assemblyline.interaction.TileEntitySorter; +import assemblyline.machines.ContainerSorter; +import assemblyline.machines.TileEntitySorter; -public class GuiEjectorSettings extends GuiContainer +public class GuiSorter extends GuiContainer { private TileEntitySorter tileEntity; private int containerWidth; private int containerHeight; - public GuiEjectorSettings(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity) + public GuiSorter(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity) { - super(new ContainerEjector(par1InventoryPlayer, tileEntity)); + super(new ContainerSorter(par1InventoryPlayer, tileEntity)); this.tileEntity = tileEntity; } diff --git a/src/minecraft/assemblyline/model/ModelConveyorBelt.java b/src/minecraft/assemblyline/model/ModelConveyorBelt.java index c607832b3..fd92e6eba 100644 --- a/src/minecraft/assemblyline/model/ModelConveyorBelt.java +++ b/src/minecraft/assemblyline/model/ModelConveyorBelt.java @@ -164,7 +164,7 @@ public class ModelConveyorBelt extends ModelBase setRotation(c1, 0F, 0F, 0F); } - public void render(float f5, int pos, boolean front, boolean back, boolean above) + public void render(float f5, float radians, boolean front, boolean back, boolean above) { boolean mid = front && back ? true : false; boolean leftCap = !front && back ? true : false; @@ -214,9 +214,9 @@ public class ModelConveyorBelt extends ModelBase } // rollers - MRoller.rotateAngleX = 0.7853982F * pos; - BRoller.rotateAngleX = 0.7853982F * pos; - FRoller.rotateAngleX = 0.7853982F * pos; + MRoller.rotateAngleX = radians; + BRoller.rotateAngleX = radians; + FRoller.rotateAngleX = radians; MRoller.render(f5); BRoller.render(f5); FRoller.render(f5); diff --git a/src/minecraft/assemblyline/render/RenderConveyorBelt.java b/src/minecraft/assemblyline/render/RenderConveyorBelt.java index 5f49b7fdc..c78c01aca 100644 --- a/src/minecraft/assemblyline/render/RenderConveyorBelt.java +++ b/src/minecraft/assemblyline/render/RenderConveyorBelt.java @@ -15,32 +15,43 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer public void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f) { - String flip = "";//if(tileEntity.flip){flip = "F";} + String flip = "";// if(tileEntity.flip){flip + // = "F";} boolean mid = tileEntity.middleBelt(); int face = tileEntity.getBeltDirection(); - + GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glRotatef(180f, 0f, 0f, 1f); - - int pos = 0; - bindTextureByName(AssemblyLine.TEXTURE_PATH+"BeltTexture"+flip+".png"); - if(face==2){ GL11.glRotatef(180f, 0f, 1f, 0f);} - if(face==3){ GL11.glRotatef(0f, 0f, 1f, 0f);} - if(face==4){ GL11.glRotatef(90f, 0f, 1f, 0f);} - if(face==5){ GL11.glRotatef(270f, 0f, 1f, 0f);} - int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); - model.render(0.0625F,pos,tileEntity.BackCap(),tileEntity.FrontCap(), false); - - + + bindTextureByName(AssemblyLine.TEXTURE_PATH + "BeltTexture" + flip + ".png"); + if (face == 2) + { + GL11.glRotatef(180f, 0f, 1f, 0f); + } + if (face == 3) + { + GL11.glRotatef(0f, 0f, 1f, 0f); + } + if (face == 4) + { + GL11.glRotatef(90f, 0f, 1f, 0f); + } + if (face == 5) + { + GL11.glRotatef(270f, 0f, 1f, 0f); + } + int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.BackCap(), tileEntity.FrontCap(), false); + GL11.glPopMatrix(); - + } @Override - public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { - this.renderAModelAt((TileEntityConveyorBelt)tileEntity, var2, var4, var6, var8); + this.renderAModelAt((TileEntityConveyorBelt) tileEntity, var2, var4, var6, var8); } } \ No newline at end of file diff --git a/src/minecraft/assemblyline/render/RenderHelper.java b/src/minecraft/assemblyline/render/RenderHelper.java index 169ab78dc..bd1c59378 100644 --- a/src/minecraft/assemblyline/render/RenderHelper.java +++ b/src/minecraft/assemblyline/render/RenderHelper.java @@ -7,7 +7,7 @@ import net.minecraft.src.RenderBlocks; import org.lwjgl.opengl.GL11; import assemblyline.AssemblyLine; -import assemblyline.interaction.BlockInteraction.MachineType; +import assemblyline.machines.BlockInteraction.MachineType; import assemblyline.model.ModelConveyorBelt; import assemblyline.model.ModelSorter; import assemblyline.model.ModelManipulator; @@ -31,15 +31,15 @@ public class RenderHelper implements ISimpleBlockRenderingHandler GL11.glPushMatrix(); GL11.glTranslatef((float) 0.0F, (float) 1.5F, (float) 0.0F); GL11.glRotatef(180f, 0f, 0f, 1f); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH+"BeltTexture.png")); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "BeltTexture.png")); modelConveyorBelt.render(0.0625F, 0, false, false, false); GL11.glPopMatrix(); } else if (block.blockID == AssemblyLine.blockInteraction.blockID) { - if(metadata == MachineType.SORTER.metadata) + if (metadata == MachineType.SORTER.metadata) { - GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH+"ejector.png")); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "ejector.png")); GL11.glPushMatrix(); GL11.glTranslatef((float) 0.6F, (float) 1.5F, (float) 0.6F); GL11.glRotatef(180f, 0f, 0f, 1f); @@ -48,9 +48,9 @@ public class RenderHelper implements ISimpleBlockRenderingHandler modelEjector.renderPiston(0.0625F, 1); GL11.glPopMatrix(); } - else if(metadata == MachineType.MANIPULATOR.metadata) + else if (metadata == MachineType.MANIPULATOR.metadata) { - GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH+"injector.png")); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "injector.png")); GL11.glPushMatrix(); GL11.glTranslatef((float) 0.6F, (float) 1.5F, (float) 0.6F); GL11.glRotatef(180f, 0f, 0f, 1f); diff --git a/src/minecraft/assemblyline/render/RenderManipulator.java b/src/minecraft/assemblyline/render/RenderManipulator.java index ba965cdec..51e88f2e5 100644 --- a/src/minecraft/assemblyline/render/RenderManipulator.java +++ b/src/minecraft/assemblyline/render/RenderManipulator.java @@ -7,7 +7,7 @@ import org.lwjgl.opengl.GL11; import assemblyline.AssemblyLine; import assemblyline.belts.TileEntityConveyorBelt; -import assemblyline.interaction.TileEntityManipulator; +import assemblyline.machines.TileEntityManipulator; import assemblyline.model.ModelManipulator; public class RenderManipulator extends TileEntitySpecialRenderer @@ -16,31 +16,45 @@ public class RenderManipulator extends TileEntitySpecialRenderer public void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f) { - String flip = "";//if(tileEntity.flip){flip = "F";} - int face = tileEntity.getBeltDirection(); - + String flip = "";// if(tileEntity.flip){flip + // = "F";} + int face = tileEntity.getBeltDirection().ordinal(); + GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glRotatef(180f, 0f, 0f, 1f); - - this.bindTextureByName(AssemblyLine.TEXTURE_PATH+"injector.png"); - - - if(face==2){ GL11.glRotatef(0f, 0f, 1f, 0f);} - if(face==3){ GL11.glRotatef(180f, 0f, 1f, 0f);} - if(face==4){ GL11.glRotatef(270f, 0f, 1f, 0f);} - if(face==5){ GL11.glRotatef(90f, 0f, 1f, 0f);} - int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); - model.render(0.0625F, true, 0); - //TODO change the true part to check if there is a TE on the input side + + this.bindTextureByName(AssemblyLine.TEXTURE_PATH + "injector.png"); + + if (face == 2) + { + GL11.glRotatef(0f, 0f, 1f, 0f); + } + if (face == 3) + { + GL11.glRotatef(180f, 0f, 1f, 0f); + } + if (face == 4) + { + GL11.glRotatef(270f, 0f, 1f, 0f); + } + if (face == 5) + { + GL11.glRotatef(90f, 0f, 1f, 0f); + } + + model.render(0.0625F, true, 0); + + // TODO change the true part to check if + // there is a TE on the input side GL11.glPopMatrix(); - + } @Override - public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { - this.renderAModelAt((TileEntityManipulator)tileEntity, var2, var4, var6, var8); + this.renderAModelAt((TileEntityManipulator) tileEntity, var2, var4, var6, var8); } } \ No newline at end of file diff --git a/src/minecraft/assemblyline/render/RenderSorter.java b/src/minecraft/assemblyline/render/RenderSorter.java index 7257a493b..402123052 100644 --- a/src/minecraft/assemblyline/render/RenderSorter.java +++ b/src/minecraft/assemblyline/render/RenderSorter.java @@ -6,7 +6,7 @@ import net.minecraft.src.TileEntitySpecialRenderer; import org.lwjgl.opengl.GL11; import assemblyline.AssemblyLine; -import assemblyline.interaction.TileEntitySorter; +import assemblyline.machines.TileEntitySorter; import assemblyline.model.ModelSorter; public class RenderSorter extends TileEntitySpecialRenderer @@ -16,27 +16,42 @@ public class RenderSorter extends TileEntitySpecialRenderer public void renderAModelAt(TileEntitySorter tileEntity, double x, double y, double z, float f) { boolean fire = tileEntity.firePiston; - int face = tileEntity.getDirection(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + int face = tileEntity.getDirection(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); int pos = 0; - if(fire){pos = 8;} - bindTextureByName(AssemblyLine.TEXTURE_PATH+"ejector.png"); + if (fire) + { + pos = 8; + } + bindTextureByName(AssemblyLine.TEXTURE_PATH + "ejector.png"); GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glScalef(1.0F, -1F, -1F); - if(face==2){ GL11.glRotatef(180f, 0f, 1f, 0f);} - if(face==3){ GL11.glRotatef(0f, 0f, 1f, 0f);} - if(face==4){ GL11.glRotatef(90f, 0f, 1f, 0f);} - if(face==5){ GL11.glRotatef(270f, 0f, 1f, 0f);} + if (face == 2) + { + GL11.glRotatef(180f, 0f, 1f, 0f); + } + if (face == 3) + { + GL11.glRotatef(0f, 0f, 1f, 0f); + } + if (face == 4) + { + GL11.glRotatef(90f, 0f, 1f, 0f); + } + if (face == 5) + { + GL11.glRotatef(270f, 0f, 1f, 0f); + } model.renderMain(0.0625F); model.renderPiston(0.0625F, pos); GL11.glPopMatrix(); - + } @Override - public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { - this.renderAModelAt((TileEntitySorter)tileEntity, var2, var4, var6, var8); + this.renderAModelAt((TileEntitySorter) tileEntity, var2, var4, var6, var8); } } \ No newline at end of file