-
Notifications
You must be signed in to change notification settings - Fork 497
/
BuildCraftEnergy.java
273 lines (240 loc) · 11.5 KB
/
BuildCraftEnergy.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
262
263
264
265
266
267
268
269
270
271
272
273
/**
* BuildCraft is open-source. It is distributed under the terms of the
* BuildCraft Open Source License. It grants rights to read, modify, compile
* or run the code. It does *NOT* grant the right to redistribute this software
* or its modifications in any form, binary or source, except if expressively
* granted by the copyright holder.
*/
package buildcraft;
import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.Property;
import net.minecraftforge.liquids.LiquidContainerData;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.gates.Trigger;
import buildcraft.api.recipes.RefineryRecipe;
import buildcraft.core.BlockIndex;
import buildcraft.core.DefaultProps;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.Version;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.BlockEngine;
import buildcraft.energy.BlockOilFlowing;
import buildcraft.energy.BlockOilStill;
import buildcraft.energy.BptBlockEngine;
import buildcraft.energy.EnergyProxy;
import buildcraft.energy.Engine.EnergyStage;
import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketOil;
import buildcraft.energy.ItemEngine;
import buildcraft.energy.OilBucketHandler;
import buildcraft.energy.OilPopulate;
import buildcraft.energy.TriggerEngineHeat;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE)
@NetworkMod(channels = { DefaultProps.NET_CHANNEL_NAME }, packetHandler = PacketHandler.class, clientSideRequired = true, serverSideRequired = true)
public class BuildCraftEnergy {
public final static int ENERGY_REMOVE_BLOCK = 25;
public final static int ENERGY_EXTRACT_ITEM = 2;
public static BlockEngine engineBlock;
public static Block oilMoving;
public static Block oilStill;
public static Item bucketOil;
public static Item bucketFuel;
public static Item fuel;
public static LiquidStack oilLiquid;
public static LiquidStack fuelLiquid;
public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>();
public static Trigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.Blue);
public static Trigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.Green);
public static Trigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.Yellow);
public static Trigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.Red);
@Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance;
@Init
public static void load(FMLInitializationEvent evt) {
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler());
MinecraftForge.EVENT_BUS.register(new OilPopulate());
new BptBlockEngine(engineBlock.blockID);
if (BuildCraftCore.loadDefaultRecipes) {
loadRecipes();
}
EnergyProxy.proxy.registerBlockRenderers();
EnergyProxy.proxy.registerTileEntities();
EnergyProxy.proxy.registerTextureFX();
}
@PreInit
public void initialize(FMLPreInitializationEvent evt) {
Property engineId = BuildCraftCore.mainConfiguration.getBlock("engine.id", DefaultProps.ENGINE_ID);
Property oilStillId = BuildCraftCore.mainConfiguration.getBlock("oilStill.id", DefaultProps.OIL_STILL_ID);
Property oilMovingId = BuildCraftCore.mainConfiguration.getBlock("oilMoving.id", DefaultProps.OIL_MOVING_ID);
Property bucketOilId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bucketOil.id", DefaultProps.BUCKET_OIL_ID);
Property bucketFuelId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bucketFuel.id", DefaultProps.BUCKET_FUEL_ID);
Property itemFuelId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "fuel.id", DefaultProps.FUEL_ID);
BuildCraftCore.mainConfiguration.save();
engineBlock = new BlockEngine(engineId.getInt(DefaultProps.ENGINE_ID));
GameRegistry.registerBlock(engineBlock, ItemEngine.class);
LanguageRegistry.addName(new ItemStack(engineBlock, 1, 0), "Redstone Engine");
LanguageRegistry.addName(new ItemStack(engineBlock, 1, 1), "Steam Engine");
LanguageRegistry.addName(new ItemStack(engineBlock, 1, 2), "Combustion Engine");
oilStill = (new BlockOilStill(oilStillId.getInt(DefaultProps.OIL_STILL_ID), Material.water)).setBlockName("oil");
CoreProxy.proxy.addName(oilStill.setBlockName("oilStill"), "Oil");
CoreProxy.proxy.registerBlock(oilStill);
oilMoving = (new BlockOilFlowing(oilMovingId.getInt(DefaultProps.OIL_MOVING_ID), Material.water)).setBlockName("oil");
CoreProxy.proxy.addName(oilMoving.setBlockName("oilMoving"), "Oil");
CoreProxy.proxy.registerBlock(oilMoving);
// Oil and fuel
if (oilMoving.blockID + 1 != oilStill.blockID)
throw new RuntimeException("Oil Still id must be Oil Moving id + 1");
fuel = new ItemBuildCraft(itemFuelId.getInt(DefaultProps.FUEL_ID)).setItemName("fuel");
LanguageRegistry.addName(fuel, "Fuel");
MinecraftForge.EVENT_BUS.register(new OilBucketHandler());
bucketOil = (new ItemBucketOil(bucketOilId.getInt(DefaultProps.BUCKET_OIL_ID))).setItemName("bucketOil").setContainerItem(Item.bucketEmpty);
LanguageRegistry.addName(bucketOil, "Oil Bucket");
bucketFuel = new ItemBuildCraft(Integer.parseInt(bucketFuelId.value)).setItemName("bucketFuel").setContainerItem(Item.bucketEmpty);
bucketFuel.setIconIndex(0 * 16 + 3).setMaxStackSize(1).setCreativeTab(CreativeTabs.tabMisc);
LanguageRegistry.addName(bucketFuel, "Fuel Bucket");
oilLiquid = LiquidDictionary.getOrCreateLiquid("Oil", new LiquidStack(oilStill, 1));
fuelLiquid = LiquidDictionary.getOrCreateLiquid("Fuel", new LiquidStack(fuel, 1));
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(LiquidDictionary.getLiquid("Oil", 1), null, LiquidDictionary.getLiquid("Fuel", 1), 12, 1));
// Iron Engine Fuels
IronEngineFuel.fuels.add(new IronEngineFuel(Block.lavaStill.blockID, 1, 20000));
IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), 3, 20000));
IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000));
// Iron Engine Coolants
IronEngineCoolant.coolants.add(new IronEngineCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 1.0f));
LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(
bucketOil), new ItemStack(Item.bucketEmpty)));
LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME),
new ItemStack(bucketFuel), new ItemStack(Item.bucketEmpty)));
}
public static void loadRecipes() {
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 0),
new Object[] { "www", " g ", "GpG", Character.valueOf('w'), "plankWood", Character.valueOf('g'), Block.glass, Character.valueOf('G'),
BuildCraftCore.woodenGearItem, Character.valueOf('p'), Block.pistonBase });
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 1), new Object[] { "www", " g ", "GpG", Character.valueOf('w'), Block.cobblestone,
Character.valueOf('g'), Block.glass, Character.valueOf('G'), BuildCraftCore.stoneGearItem, Character.valueOf('p'), Block.pistonBase });
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 2), new Object[] { "www", " g ", "GpG", Character.valueOf('w'), Item.ingotIron,
Character.valueOf('g'), Block.glass, Character.valueOf('G'), BuildCraftCore.ironGearItem, Character.valueOf('p'), Block.pistonBase });
}
// public static int createPollution (World world, int i, int j, int k, int
// saturation) {
// int remainingSaturation = saturation;
//
// if (world.rand.nextFloat() > 0.7) {
// // Try to place an item on the sides
//
// LinkedList<BlockIndex> orientations = new LinkedList<BlockIndex>();
//
// for (int id = -1; id <= 1; id += 2) {
// for (int kd = -1; kd <= 1; kd += 2) {
// if (canPollute(world, i + id, j, k + kd)) {
// orientations.add(new BlockIndex(i + id, j, k + kd));
// }
// }
// }
//
// if (orientations.size() > 0) {
// BlockIndex toPollute =
// orientations.get(world.rand.nextInt(orientations.size()));
//
// int x = toPollute.i;
// int y = toPollute.j;
// int z = toPollute.k;
//
// if (world.getBlockId(x, y, z) == 0) {
// world.setBlockAndMetadataWithNotify(x, y, z,
// BuildCraftEnergy.pollution.blockID,
// saturation * 16 / 100);
//
// saturationStored.put(new BlockIndex(x, y, z), new Integer(
// saturation));
// remainingSaturation = 0;
// } else if (world.getBlockTileEntity(z, y, z) instanceof TilePollution) {
// remainingSaturation = updateExitingPollution(world, x, y, z, saturation);
// }
// }
// }
//
// if (remainingSaturation > 0) {
// if (world.getBlockId(i, j + 1, k) == 0) {
// if (j + 1 < 128) {
// world.setBlockAndMetadataWithNotify(i, j + 1, k,
// BuildCraftEnergy.pollution.blockID,
// saturation * 16 / 100);
// saturationStored.put(new BlockIndex(i, j + 1, k),
// new Integer(remainingSaturation));
// }
//
// remainingSaturation = 0;
// } else if (world.getBlockTileEntity(i, j + 1, k) instanceof
// TilePollution) {
// remainingSaturation = updateExitingPollution(world, i, j + 1,
// k, remainingSaturation);
// }
// }
//
// if (remainingSaturation == 0) {
// System.out.println ("EXIT 1");
// return 0;
// } else if (remainingSaturation == saturation) {
// System.out.println ("EXIT 2");
// return saturation;
// } else {
// System.out.println ("EXIT 3");
// return createPollution (world, i, j, k, remainingSaturation);
// }
// }
//
// private static int updateExitingPollution (World world, int i, int j, int
// k, int saturation) {
// int remainingSaturation = saturation;
//
// TilePollution tile = (TilePollution) world.getBlockTileEntity(
// i, j, k);
//
// if (tile.saturation + saturation <= 100) {
// remainingSaturation = 0;
// tile.saturation += saturation;
// } else {
// remainingSaturation = (tile.saturation + saturation) - 100;
// tile.saturation += saturation - remainingSaturation;
// }
//
// world.setBlockMetadata(i, j, k, saturation * 16 / 100);
// world.markBlockNeedsUpdate(i, j, k);
//
// return remainingSaturation;
// }
//
// private static boolean canPollute (World world, int i, int j, int k) {
// if (world.getBlockId(i, j, k) == 0) {
// return true;
// } else {
// TileEntity tile = world.getBlockTileEntity(i, j, k);
//
// return (tile instanceof TilePollution && ((TilePollution)
// tile).saturation < 100);
// }
// }
}