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
172
173
|
package ihl.processing.chemistry;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import ic2.api.network.INetworkClientTileEntityEventListener;
import ic2.api.recipe.IRecipeInput;
import ic2.core.ContainerBase;
import ic2.core.IC2;
import ic2.core.IHasGui;
import ic2.core.block.TileEntityInventory;
import ic2.core.block.invslot.InvSlot.Access;
import ihl.processing.chemistry.ApparatusProcessableInvSlot;
import ihl.processing.invslots.IHLInvSlotOutput;
import ihl.recipes.RecipeInputWire;
import ihl.recipes.UniversalRecipeInput;
import ihl.recipes.UniversalRecipeManager;
import ihl.recipes.UniversalRecipeOutput;
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 LoomTileEntity extends TileEntityInventory implements IHasGui, INetworkClientTileEntityEventListener
{
protected static UniversalRecipeManager recipeManager = new UniversalRecipeManager("loom");
public short progress;
protected short operationLength=200;
public final ApparatusProcessableInvSlot input;
public final IHLInvSlotOutput output;
boolean isGuiScreenOpened=false;
public LoomTileEntity()
{
super();
input = new ApparatusProcessableInvSlot(this, "input", 0, Access.IO, 1, 64);
output = new IHLInvSlotOutput(this, "output", 1, 1);
}
public boolean enableUpdateEntity()
{
return IC2.platform.isSimulating();
}
@Override
public void updateEntityServer()
{
super.updateEntityServer();
if (this.canOperate() && this.isGuiScreenOpened)
{
this.setActive(true);
if (this.progress == 0)
{
IC2.network.get().initiateTileEntityEvent(this, 0, true);
}
++this.progress;
if (this.progress >= this.operationLength)
{
this.operate();
this.progress = 0;
IC2.network.get().initiateTileEntityEvent(this, 2, true);
}
}
else
{
if (this.progress != 0 && this.getActive())
{
IC2.network.get().initiateTileEntityEvent(this, 1, true);
}
if (!this.canOperate())
{
this.progress = 0;
}
this.setActive(false);
}
}
@Override
public String getInventoryName() {
return "Loom";
}
@Override
public ItemStack getWrenchDrop(EntityPlayer player)
{
return IHLUtils.getThisModItemStack("loom");
}
@Override
@SideOnly(Side.CLIENT)
public GuiScreen getGui(EntityPlayer player, boolean arg1) {
return new LoomGui(new LoomContainer(player, this));
}
@Override
public ContainerBase<?> getGuiContainer(EntityPlayer player) {
this.isGuiScreenOpened=true;
return new LoomContainer(player, this);
}
public void operate()
{
List<IRecipeInput> input1 = LoomTileEntity.recipeManager.getRecipeInput(getInput()).getItemInputs();
List<?> output1 = LoomTileEntity.recipeManager.getOutputFor(getInput(), false, false).getItemOutputs();
this.output.add(output1);
if(input1.get(0) instanceof RecipeInputWire)
{
int fiberLength = input1.get(0).getAmount();
boolean isFiberConsumed = IHLUtils.adjustWireLength(this.input.get(), -fiberLength);
if(isFiberConsumed)
{
this.input.put(null);
}
}
else
{
this.input.consume(0, input1.get(0).getAmount());
}
}
@SuppressWarnings("rawtypes")
public List[] getInput()
{
return new List[] {null,Arrays.asList(new ItemStack[] {input.get()})};
}
public boolean canOperate()
{
if(LoomTileEntity.recipeManager.getOutputFor(getInput(), false, false)==null) return false;
List<?> output1 = LoomTileEntity.recipeManager.getOutputFor(getInput(), false, false).getItemOutputs();
return this.output.canAdd(output1);
}
@Override
public void onGuiClosed(EntityPlayer arg0) {}
public static void addRecipe(ItemStack input, ItemStack output)
{
if(input==null || output==null) throw new NullPointerException();
recipeManager.addRecipe(new UniversalRecipeInput(null,new ItemStack[] {input}), new UniversalRecipeOutput(null, new ItemStack[] {output},20));
}
public int gaugeProgressScaled(int i)
{
return this.progress * i / this.operationLength;
}
@Override
public void onNetworkEvent(EntityPlayer player, int event)
{
switch(event)
{
case 0:
this.isGuiScreenOpened=false;
break;
}
}
public static Map<UniversalRecipeInput, UniversalRecipeOutput> getRecipes() {
return recipeManager.getRecipes();
}
@Override
public boolean shouldRenderInPass(int pass)
{
return pass==0;
}
}
|