-
Notifications
You must be signed in to change notification settings - Fork 753
/
Smeltery.java
261 lines (231 loc) · 8.88 KB
/
Smeltery.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package tconstruct.library.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
/** Melting and hacking, churn and burn */
public class Smeltery
{
public static Smeltery instance = new Smeltery();
private final Map<SmelteryInput, FluidStack> smeltingList = new HashMap<SmelteryInput, FluidStack>();
private final Map<SmelteryInput, Integer> temperatureList = new HashMap<SmelteryInput, Integer>();
private final Map<SmelteryInput, ItemStack> renderIndex = new HashMap<SmelteryInput, ItemStack>();
private final List<AlloyMix> alloys = new ArrayList<AlloyMix>();
/**
* Adds mappings between an itemstack and an output liquid Example:
* Smeltery.addMelting(Block.oreIron, 0, 600, new
* FluidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue * 2, 0));
*
* @param stack The itemstack to liquify. Must hold a block.
* @param temperature How hot the block should be before liquifying. Max temp in the Smeltery is 800, other structures may vary
* @param output The result of the process in liquid form
*/
public static void addMelting (ItemStack stack, int temperature, FluidStack output)
{
if (stack.getItem() instanceof ItemBlock)
addMelting(stack, ((ItemBlock) stack.getItem()).field_150939_a, stack.getItemDamage(), temperature, output);
else
throw new IllegalArgumentException("ItemStack must house a block.");
}
/**
* Adds mappings between a block and its liquid Example:
* Smeltery.addMelting(Block.oreIron, 0, 600, new
* FluidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue * 2, 0));
*
* @param blockID The ID of the block to liquify and render
* @param metadata The metadata of the block to liquify and render
* @param temperature How hot the block should be before liquifying. Max temp in the Smeltery is 800, other structures may vary
* @param output The result of the process in liquid form
*/
public static void addMelting (Block block, int metadata, int temperature, FluidStack output)
{
addMelting(new ItemStack(block, 1, metadata), block, metadata, temperature, output);
}
/**
* Adds mappings between an input and its liquid. Renders with the given
* input's block ID and metadata Example: Smeltery.addMelting(Block.oreIron,
* 0, 600, new FluidStack(liquidMetalStill.blockID,
* TConstruct.ingotLiquidValue * 2, 0));
*
* @param input The item to liquify
* @param block The ID of the block to render
* @param metadata The metadata of the block to render
* @param temperature How hot the block should be before liquifying
* @param liquid The result of the process
*/
public static void addMelting (ItemStack input, Block block, int metadata, int temperature, FluidStack liquid)
{
SmelteryInput in = new SmelteryInput(input);
instance.smeltingList.put(in, liquid);
instance.temperatureList.put(in, temperature);
instance.renderIndex.put(in, new ItemStack(block, input.stackSize, metadata));
}
/**
* Adds an alloy mixing recipe. Example: Smeltery.addAlloyMixing(new
* FluidStack(bronzeID, 2, 0), new FluidStack(copperID, 3, 0), new
* FluidStack(tinID, 1, 0)); The example mixes 3 copper with 1 tin to make 2
* bronze
*
* @param result The output of the combination of mixers. The quantity is used for amount of a successful mix
* @param mixers the liquids to be mixed. Quantities are used as ratios
*/
public static void addAlloyMixing (FluidStack result, FluidStack... mixers)
{
ArrayList inputs = new ArrayList();
for (FluidStack liquid : mixers)
inputs.add(liquid);
instance.alloys.add(new AlloyMix(result, inputs));
}
/**
* Used to get the resulting temperature from a source ItemStack
*
* @param item The Source ItemStack
* @return The result temperature
*/
public static Integer getLiquifyTemperature (ItemStack item)
{
if (item == null)
return 20;
Integer temp = instance.temperatureList.get(new SmelteryInput(item));
if (temp == null)
return 20;
else
return temp;
}
/**
* Used to get the resulting temperature from a source Block
*
* @param block The Source Block
* @return The result ItemStack
*/
public static Integer getLiquifyTemperature (Block block, int metadata)
{
return instance.getLiquifyTemperature(new ItemStack(block, 1, metadata));
}
/**
* Used to get the resulting ItemStack from a source ItemStack
*
* @param item The Source ItemStack
* @return The result ItemStack
*/
public static FluidStack getSmelteryResult (ItemStack item)
{
if (item == null)
return null;
FluidStack stack = instance.smeltingList.get(new SmelteryInput(item));
if (stack == null)
return null;
return stack.copy();
}
/**
* Used to get the resulting ItemStack from a source Block
*
* @param block The Source Block
* @return The result ItemStack
*/
public static FluidStack getSmelteryResult (Block block, int metadata)
{
return instance.getSmelteryResult(new ItemStack(block, 1, metadata));
}
public static ItemStack getRenderIndex (ItemStack input)
{
return instance.renderIndex.get(new SmelteryInput(input));
}
public static ArrayList mixMetals (ArrayList<FluidStack> moltenMetal)
{
ArrayList liquids = new ArrayList();
for (AlloyMix alloy : instance.alloys)
{
FluidStack liquid = alloy.mix(moltenMetal);
if (liquid != null)
liquids.add(liquid);
}
return liquids;
}
public static Map<SmelteryInput, FluidStack> getSmeltingList ()
{
return instance.smeltingList;
}
public static Map<SmelteryInput, Integer> getTemperatureList ()
{
return instance.temperatureList;
}
public static Map<SmelteryInput, ItemStack> getRenderIndex ()
{
return instance.renderIndex;
}
public static List<AlloyMix> getAlloyList ()
{
return instance.alloys;
}
/**
* Adds a mapping between FluidType and ItemStack
*
* @author samtrion
*
* @param type Type of Fluid
* @param input The item to liquify
* @param temperatureDifference Difference between FluidType BaseTemperature
* @param fluidAmount Amount of Fluid
*/
public static void addMelting (FluidType type, ItemStack input, int temperatureDifference, int fluidAmount)
{
int temp = type.baseTemperature + temperatureDifference;
if (temp <= 20)
temp = type.baseTemperature;
if (input.getItem() instanceof ItemBlock)
addMelting(input, ((ItemBlock) input.getItem()).field_150939_a, input.getItemDamage(), type.baseTemperature + temperatureDifference, new FluidStack(type.fluid, fluidAmount));
else
addMelting(input, type.renderBlock, type.renderMeta, type.baseTemperature + temperatureDifference, new FluidStack(type.fluid, fluidAmount));
}
/**
* Adds all Items to the Smeltery based on the oreDictionary Name
*
* @author samtrion
*
* @param oreName oreDictionary name e.g. oreIron
* @param type Type of Fluid
* @param temperatureDifference Difference between FluidType BaseTemperature
* @param fluidAmount Amount of Fluid
*/
public static void addDictionaryMelting (String oreName, FluidType type, int temperatureDifference, int fluidAmount)
{
for (ItemStack is : OreDictionary.getOres(oreName))
addMelting(type, is, temperatureDifference, fluidAmount);
}
// todo: mantle -> itemmeta wrapper
public static class SmelteryInput
{
public final Item input;
public final int meta;
public SmelteryInput(ItemStack inputStack)
{
this(inputStack.getItem(), inputStack.getItemDamage());
}
public SmelteryInput(Item input, int meta)
{
this.input = input;
this.meta = meta;
}
@Override
public int hashCode ()
{
return this.input.hashCode() << 16 | this.meta;
}
@Override
public boolean equals (Object o)
{
if (o == this)
return true;
else if (o instanceof SmelteryInput)
return this.input == ((SmelteryInput) o).input && this.meta == ((SmelteryInput) o).meta;
return false;
}
}
}