summaryrefslogtreecommitdiff
path: root/ihl/processing/metallurgy/CoilerTileEntity.java
blob: 6a671b0ca7af3589acae92d57239f815dde3e444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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;
    }

}