summaryrefslogtreecommitdiff
path: root/ihl/processing/metallurgy/CoilerTileEntity.java
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/processing/metallurgy/CoilerTileEntity.java
Initial commit
Diffstat (limited to 'ihl/processing/metallurgy/CoilerTileEntity.java')
-rw-r--r--ihl/processing/metallurgy/CoilerTileEntity.java171
1 files changed, 171 insertions, 0 deletions
diff --git a/ihl/processing/metallurgy/CoilerTileEntity.java b/ihl/processing/metallurgy/CoilerTileEntity.java
new file mode 100644
index 0000000..6a671b0
--- /dev/null
+++ b/ihl/processing/metallurgy/CoilerTileEntity.java
@@ -0,0 +1,171 @@
+package ihl.processing.metallurgy;
+
+import java.util.List;
+
+import ic2.core.ContainerBase;
+import ic2.core.IC2;
+import ic2.core.block.invslot.InvSlotOutput;
+import ic2.core.network.NetworkManager;
+import ihl.interfaces.IWire;
+import ihl.utils.IHLUtils;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+public class CoilerTileEntity extends BasicElectricMotorTileEntity implements IProductionLine{
+
+ public final InvSlotOutput output;
+ private int activeTimer=0;
+ public boolean hasCoil=false;
+ public boolean hasEngine=false;
+
+ public CoilerTileEntity()
+ {
+ super();
+ this.output = new InvSlotOutput(this, "output", 1, 1);
+ this.isGuiScreenOpened=true;
+ }
+
+
+ @Override
+ public String getInventoryName() {
+ return "Coiler";
+ }
+
+ @Override
+ public List<String> getNetworkedFields()
+ {
+ List<String> fields = super.getNetworkedFields();
+ fields.add("hasCoil");
+ fields.add("hasEngine");
+ return fields;
+ }
+
+ @Override
+ public ItemStack getWrenchDrop(EntityPlayer player)
+ {
+ return IHLUtils.getThisModItemStack("coiler");
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public GuiScreen getGui(EntityPlayer player, boolean arg1) {
+ return new CoilerGui(new CoilerContainer(player, this));
+ }
+
+ @Override
+ public ContainerBase<?> getGuiContainer(EntityPlayer player)
+ {
+ return new CoilerContainer(player, this);
+ }
+
+ @Override
+ public boolean canOperate()
+ {
+ return false;
+ }
+
+ @Override
+ public void updateEntityServer()
+ {
+ super.updateEntityServer();
+ if(activeTimer>0)
+ {
+ activeTimer--;
+ }
+ else
+ {
+ setActive(false);
+ }
+ if(this.output.isEmpty() && hasCoil==true)
+ {
+ this.hasCoil=false;
+ IC2.network.get().updateTileEntityField(this, "hasCoil");
+ }
+ else if(!this.output.isEmpty() && hasCoil==false)
+ {
+ this.hasCoil=true;
+ IC2.network.get().updateTileEntityField(this, "hasCoil");
+ }
+ if(this.engine.isEmpty() && hasEngine==true)
+ {
+ this.hasEngine=false;
+ IC2.network.get().updateTileEntityField(this, "hasEngine");
+ }
+ else if(this.engine.correctContent() && hasEngine==false)
+ {
+ this.hasEngine=true;
+ IC2.network.get().updateTileEntityField(this, "hasEngine");
+ }
+
+ }
+
+ @Override
+ public void operate()
+ {}
+
+
+ @Override
+ public List[] getInput()
+ {
+ return null;
+ }
+
+
+ @Override
+ public boolean canProcess(ItemStack cable) {
+ if(this.engine.correctContent() && this.energy>1D/this.engine.getEfficiency() && cable.getItem() instanceof IWire)
+ {
+ if(this.output.isEmpty())
+ {
+ return true;
+ }
+ else if(this.output.get().getItem() instanceof IWire)
+ {
+ return ((IWire)this.output.get().getItem()).isSameWire(this.output.get(), cable);
+ }
+ else
+ {
+ return this.output.get().isItemEqual(cable);
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ public void process(ItemStack cable) {
+ if(cable.getItem() instanceof IWire)
+ {
+ this.energy-=1D/this.engine.getEfficiency();
+ if(this.output.isEmpty())
+ {
+ setActive(true);
+ activeTimer=800;
+ this.output.put(cable);
+ this.hasCoil=true;
+ IC2.network.get().updateTileEntityField(this, "hasCoil");
+ }
+ else
+ {
+ setActive(true);
+ activeTimer=800;
+ int length = this.output.get().stackTagCompound.getInteger(((IWire)this.output.get().getItem()).getTag());
+ int fullLength = this.output.get().stackTagCompound.getInteger(((IWire)this.output.get().getItem()).getTagSecondary());
+ int lengthToAdd = cable.stackTagCompound.getInteger(((IWire)cable.getItem()).getTag());
+ int fullLengthToAdd = cable.stackTagCompound.getInteger(((IWire)cable.getItem()).getTagSecondary());
+ this.output.get().stackTagCompound.setInteger(((IWire)this.output.get().getItem()).getTag(), length+lengthToAdd);
+ this.output.get().stackTagCompound.setInteger(((IWire)this.output.get().getItem()).getTagSecondary(),fullLength+fullLengthToAdd);
+ }
+ }
+ }
+
+ @Override
+ public boolean shouldRenderInPass(int pass)
+ {
+ return pass==0;
+ }
+
+}