-
Notifications
You must be signed in to change notification settings - Fork 497
/
BuildCraftEnergy.java
408 lines (350 loc) · 17.1 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeMap;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.blueprints.BuilderAPI;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.JavaTools;
import buildcraft.api.core.StackKey;
import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.statements.ITriggerExternal;
import buildcraft.api.statements.StatementManager;
import buildcraft.core.BlockSpring;
import buildcraft.core.DefaultProps;
import buildcraft.core.InterModComms;
import buildcraft.core.Version;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.BlockBuildcraftFluid;
import buildcraft.energy.BlockEnergyEmitter;
import buildcraft.energy.BlockEnergyReceiver;
import buildcraft.energy.BlockEngine;
import buildcraft.energy.BucketHandler;
import buildcraft.energy.EnergyProxy;
import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketBuildcraft;
import buildcraft.energy.ItemEngine;
import buildcraft.energy.SchematicEngine;
import buildcraft.energy.TileEnergyEmitter;
import buildcraft.energy.TileEnergyReceiver;
import buildcraft.energy.TileEngine;
import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.statements.EnergyStatementProvider;
import buildcraft.energy.statements.TriggerEngineHeat;
import buildcraft.energy.worldgen.BiomeGenOilDesert;
import buildcraft.energy.worldgen.BiomeGenOilOcean;
import buildcraft.energy.worldgen.BiomeInitializer;
import buildcraft.energy.worldgen.OilPopulate;
import buildcraft.transport.network.PacketHandlerTransport;
@Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE)
public class BuildCraftEnergy extends BuildCraftMod {
@Mod.Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance;
public static final int ENERGY_REMOVE_BLOCK = 25;
public static final int ENERGY_EXTRACT_ITEM = 2;
public static boolean spawnOilSprings = true;
public static BiomeGenOilDesert biomeOilDesert;
public static BiomeGenOilOcean biomeOilOcean;
public static BlockEngine engineBlock;
public static BlockEnergyEmitter emitterBlock;
public static BlockEnergyReceiver receiverBlock;
public static Fluid fluidOil;
public static Fluid fluidFuel;
public static Fluid fluidRedPlasma;
public static Block blockOil;
public static Block blockFuel;
public static Block blockRedPlasma;
public static Block blockEnergyConverter;
public static Item bucketOil;
public static Item bucketFuel;
public static Item bucketRedPlasma;
public static Item fuel;
public static boolean canOilBurn;
public static double oilWellScalar = 1.0;
public static Set<Integer> oilBiomeIDs = new HashSet<Integer>();
public static Set<Integer> excessiveOilBiomeIDs = new HashSet<Integer>();
public static Set<Integer> excludeOilBiomeIDs = new HashSet<Integer>();
public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>();
public static ITriggerExternal triggerBlueEngineHeat = new TriggerEngineHeat(EnergyStage.BLUE);
public static ITriggerExternal triggerGreenEngineHeat = new TriggerEngineHeat(EnergyStage.GREEN);
public static ITriggerExternal triggerYellowEngineHeat = new TriggerEngineHeat(EnergyStage.YELLOW);
public static ITriggerExternal triggerRedEngineHeat = new TriggerEngineHeat(EnergyStage.RED);
private static Fluid buildcraftFluidOil;
private static Fluid buildcraftFluidFuel;
private static Fluid buildcraftFluidRedPlasma;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent evt) {
int oilDesertBiomeId = BuildCraftCore.mainConfiguration.get("biomes", "biomeOilDesert", DefaultProps.BIOME_OIL_DESERT).getInt(DefaultProps.BIOME_OIL_DESERT);
int oilOceanBiomeId = BuildCraftCore.mainConfiguration.get("biomes", "biomeOilOcean", DefaultProps.BIOME_OIL_OCEAN).getInt(DefaultProps.BIOME_OIL_OCEAN);
canOilBurn = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "burnOil", true, "Can oil burn?").getBoolean(true);
oilWellScalar = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "oilWellGenerationRate", 1.0, "Probability of oil well generation").getDouble(1.0);
setBiomeList(
oilBiomeIDs,
BuildCraftCore.mainConfiguration
.get(Configuration.CATEGORY_GENERAL, "oil.increasedBiomeIDs",
new String[] {BiomeDictionary.Type.SANDY.toString(), BiomeGenBase.taiga.biomeName},
"IDs or Biome Types (e.g. SANDY,OCEAN) of biomes that should have increased oil generation rates."));
setBiomeList(
excessiveOilBiomeIDs,
BuildCraftCore.mainConfiguration
.get(Configuration.CATEGORY_GENERAL,
"oil.excessiveBiomeIDs",
new String[] {},
"IDs or Biome Types (e.g. SANDY,OCEAN) of biomes that should have GREATLY increased oil generation rates."));
setBiomeList(excludeOilBiomeIDs, BuildCraftCore.mainConfiguration
.get(Configuration.CATEGORY_GENERAL, "oil.excludeBiomeIDs",
new String[] {BiomeGenBase.sky.biomeName, BiomeGenBase.hell.biomeName},
"IDs or Biome Types (e.g. SANDY,OCEAN) of biomes that are excluded from generating oil."));
double fuelLavaMultiplier = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "fuel.lava.combustion", 1.0F, "adjust energy value of Lava in Combustion Engines").getDouble(1.0F);
double fuelOilMultiplier = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "fuel.oil.combustion", 1.0F, "adjust energy value of Oil in Combustion Engines").getDouble(1.0F);
double fuelFuelMultiplier = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "fuel.fuel.combustion", 1.0F, "adjust energy value of Fuel in Combustion Engines").getDouble(1.0F);
BuildCraftCore.mainConfiguration.save();
if (oilDesertBiomeId > 0) {
if (BiomeGenBase.getBiomeGenArray()[oilDesertBiomeId] != null) {
oilDesertBiomeId = findUnusedBiomeID("oilDesert");
// save changes to config file
BuildCraftCore.mainConfiguration.get("biomes", "biomeOilDesert", oilDesertBiomeId).set(oilDesertBiomeId);
BuildCraftCore.mainConfiguration.save();
}
biomeOilDesert = BiomeGenOilDesert.makeBiome(oilDesertBiomeId);
}
if (oilOceanBiomeId > 0) {
if (BiomeGenBase.getBiomeGenArray()[oilOceanBiomeId] != null) {
oilOceanBiomeId = findUnusedBiomeID("oilOcean");
// save changes to config file
BuildCraftCore.mainConfiguration.get("biomes", "biomeOilOcean", oilOceanBiomeId).set(oilOceanBiomeId);
BuildCraftCore.mainConfiguration.save();
}
biomeOilOcean = BiomeGenOilOcean.makeBiome(oilOceanBiomeId);
}
engineBlock = new BlockEngine();
CoreProxy.proxy.registerBlock(engineBlock, ItemEngine.class);
// Oil and fuel
buildcraftFluidOil = new Fluid("oil").setDensity(800).setViscosity(1500);
FluidRegistry.registerFluid(buildcraftFluidOil);
fluidOil = FluidRegistry.getFluid("oil");
buildcraftFluidFuel = new Fluid("fuel");
FluidRegistry.registerFluid(buildcraftFluidFuel);
fluidFuel = FluidRegistry.getFluid("fuel");
buildcraftFluidRedPlasma = new Fluid("redplasma").setDensity(10000).setViscosity(10000).setLuminosity(30);
FluidRegistry.registerFluid(buildcraftFluidRedPlasma);
fluidRedPlasma = FluidRegistry.getFluid("redplasma");
if (fluidOil.getBlock() == null) {
blockOil = new BlockBuildcraftFluid(fluidOil, Material.water, MapColor.blackColor).setFlammable(canOilBurn).setFlammability(0);
blockOil.setBlockName("blockOil").setLightOpacity(8);
CoreProxy.proxy.registerBlock(blockOil);
fluidOil.setBlock(blockOil);
} else {
blockOil = fluidOil.getBlock();
}
if (blockOil != null) {
spawnOilSprings = BuildCraftCore.mainConfiguration.get("worldgen", "oilSprings", true).getBoolean(true);
BlockSpring.EnumSpring.OIL.canGen = spawnOilSprings;
BlockSpring.EnumSpring.OIL.liquidBlock = blockOil;
}
if (fluidFuel.getBlock() == null) {
blockFuel = new BlockBuildcraftFluid(fluidFuel, Material.water, MapColor.yellowColor).setFlammable(true).setFlammability(5).setParticleColor(0.7F, 0.7F, 0.0F);
blockFuel.setBlockName("blockFuel").setLightOpacity(3);
CoreProxy.proxy.registerBlock(blockFuel);
fluidFuel.setBlock(blockFuel);
} else {
blockFuel = fluidFuel.getBlock();
}
if (fluidRedPlasma.getBlock() == null) {
blockRedPlasma = new BlockBuildcraftFluid(fluidRedPlasma, Material.water, MapColor.redColor).setFlammable(
false).setParticleColor(0.9F, 0, 0);
blockRedPlasma.setBlockName("blockRedPlasma");
CoreProxy.proxy.registerBlock(blockRedPlasma);
fluidRedPlasma.setBlock(blockRedPlasma);
} else {
blockRedPlasma = fluidRedPlasma.getBlock();
}
// Buckets
if (blockOil != null) {
bucketOil = new ItemBucketBuildcraft(blockOil);
bucketOil.setUnlocalizedName("bucketOil").setContainerItem(Items.bucket);
CoreProxy.proxy.registerItem(bucketOil);
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("oil", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketOil), new ItemStack(Items.bucket));
}
if (blockFuel != null) {
bucketFuel = new ItemBucketBuildcraft(blockFuel);
bucketFuel.setUnlocalizedName("bucketFuel").setContainerItem(Items.bucket);
CoreProxy.proxy.registerItem(bucketFuel);
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("fuel", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketFuel), new ItemStack(Items.bucket));
}
if (!BuildCraftCore.NONRELEASED_BLOCKS) {
if (blockRedPlasma != null) {
bucketRedPlasma = new ItemBucketBuildcraft(blockRedPlasma);
bucketRedPlasma.setUnlocalizedName("bucketRedPlasma").setContainerItem(Items.bucket);
CoreProxy.proxy.registerItem(bucketRedPlasma);
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("redplasma", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketRedPlasma), new ItemStack(Items.bucket));
}
}
// BucketHandler ensures empty buckets fill with the correct liquid.
BucketHandler.INSTANCE.buckets.put(blockOil, bucketOil);
BucketHandler.INSTANCE.buckets.put(blockFuel, bucketFuel);
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
BuildcraftRecipeRegistry.refinery.addRecipe("buildcraft:fuel", new FluidStack(fluidOil, 1), new FluidStack(
fluidFuel, 1), 120, 1);
BuildcraftFuelRegistry.fuel.addFuel(FluidRegistry.LAVA, 20, (int) (6000 * fuelLavaMultiplier));
BuildcraftFuelRegistry.fuel.addFuel(fluidOil, 30, (int) (5000 * fuelOilMultiplier));
BuildcraftFuelRegistry.fuel.addFuel(fluidFuel, 60, (int) (25000 * fuelFuelMultiplier));
BuildcraftFuelRegistry.coolant.addCoolant(FluidRegistry.WATER, 0.0023f);
BuildcraftFuelRegistry.coolant.addSolidCoolant(StackKey.stack(Blocks.ice), StackKey.fluid(FluidRegistry.WATER), 2f);
// Receiver / emitter
if (!BuildCraftCore.NONRELEASED_BLOCKS) {
emitterBlock = new BlockEnergyEmitter();
CoreProxy.proxy.registerBlock(emitterBlock.setBlockName("energyEmitterBlock"));
CoreProxy.proxy.registerTileEntity(TileEnergyEmitter.class, "net.minecraft.src.builders.TileEnergyEmitter");
receiverBlock = new BlockEnergyReceiver();
CoreProxy.proxy.registerBlock(receiverBlock.setBlockName("energyReceiverBlock"));
CoreProxy.proxy.registerTileEntity(TileEnergyReceiver.class, "net.minecraft.src.builders.TileEnergyReceiver");
}
MinecraftForge.EVENT_BUS.register(this);
}
private void setBiomeList(Set<Integer> list, Property configuration) {
for (String id : configuration.getStringList()) {
String strippedId = JavaTools.stripSurroundingQuotes(id.trim());
if (strippedId.length() > 0) {
if (strippedId.matches("-?\\d+(\\.\\d+)?")) {
try {
list.add(Integer.parseInt(strippedId));
} catch (NumberFormatException ex) {
BCLog.logger.log
(Level.WARN,
configuration.getName() + ": Could not find biome id: "
+ strippedId + " ; Skipping!");
}
} else {
boolean found = false;
String biomeName = strippedId.toUpperCase();
for (BiomeDictionary.Type t : BiomeDictionary.Type.values()) {
String biomeType = t.name().toUpperCase();
for (BiomeGenBase b : BiomeDictionary.getBiomesForType(t)) {
if (b.biomeName.toUpperCase().equals(biomeName)
|| biomeType.toUpperCase().equals(biomeName)) {
list.add(b.biomeID);
found = true;
}
}
}
if (!found) {
BCLog.logger.log
(Level.WARN,
configuration.getName() + ": Could not find biome id: "
+ strippedId + " ; Skipping!");
}
}
}
}
}
@Mod.EventHandler
public void init(FMLInitializationEvent evt) {
channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-ENERGY", new BuildCraftChannelHandler(), new PacketHandlerTransport());
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
StatementManager.registerTriggerProvider(new EnergyStatementProvider());
BuilderAPI.schematicRegistry.registerSchematicBlock(engineBlock, SchematicEngine.class);
if (BuildCraftCore.loadDefaultRecipes) {
loadRecipes();
}
EnergyProxy.proxy.registerBlockRenderers();
EnergyProxy.proxy.registerTileEntities();
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent evt) {
if (BuildCraftCore.modifyWorld) {
MinecraftForge.EVENT_BUS.register(OilPopulate.INSTANCE);
MinecraftForge.TERRAIN_GEN_BUS.register(new BiomeInitializer());
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureHook(TextureStitchEvent.Post event) {
if (event.map.getTextureType() == 0) {
buildcraftFluidOil.setIcons(blockOil.getBlockTextureFromSide(1), blockOil.getBlockTextureFromSide(2));
buildcraftFluidFuel.setIcons(blockFuel.getBlockTextureFromSide(1), blockFuel.getBlockTextureFromSide(2));
buildcraftFluidRedPlasma.setIcons(blockRedPlasma.getBlockTextureFromSide(1), blockRedPlasma.getBlockTextureFromSide(2));
}
}
public static void loadRecipes() {
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 0),
"www", " g ", "GpG", 'w', "plankWood", 'g', Blocks.glass, 'G',
BuildCraftCore.woodenGearItem, 'p', Blocks.piston);
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 1),
"www", " g ", "GpG", 'w', "cobblestone",
'g', Blocks.glass, 'G', BuildCraftCore.stoneGearItem, 'p', Blocks.piston);
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 2),
"www", " g ", "GpG", 'w', Items.iron_ingot,
'g', Blocks.glass, 'G', BuildCraftCore.ironGearItem, 'p', Blocks.piston);
if (blockEnergyConverter != null) {
CoreProxy.proxy.addCraftingRecipe(new ItemStack(blockEnergyConverter, 1), "rcr", "sgs", "rcr",
'r', Items.redstone, 'c', BuildCraftTransport.pipePowerCobblestone,
's', BuildCraftTransport.pipePowerStone, 'g', Blocks.glass);
}
}
private int findUnusedBiomeID(String biomeName) {
int freeBiomeID = 0;
// code to find a free biome
for (int i = 1; i < 256; i++) {
if (BiomeGenBase.getBiomeGenArray()[i] == null) {
freeBiomeID = i;
return freeBiomeID;
}
}
// failed to find any free biome IDs
class BiomeIdLimitException extends RuntimeException {
private static final long serialVersionUID = 1L;
public BiomeIdLimitException(String biome) {
super(String.format("You have run out of free Biome ID spaces for %s", biome));
}
}
throw new BiomeIdLimitException(biomeName);
}
@Mod.EventHandler
public void processIMCRequests(FMLInterModComms.IMCEvent event) {
InterModComms.processIMC(event);
}
@Mod.EventHandler
public void whiteListAppliedEnergetics(FMLInitializationEvent event) {
FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial",
TileEngine.class.getCanonicalName());
}
}