buildcraft/common/buildcraft/BuildCraftEnergy.java

269 lines
11 KiB
Java
Raw Normal View History

2012-05-09 22:43:05 +02:00
/**
2014-02-15 09:21:40 +01:00
* 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
2012-05-09 22:43:05 +02:00
*/
2012-07-25 12:45:15 +02:00
package buildcraft;
2012-05-09 22:43:05 +02:00
2014-04-03 08:44:33 +02:00
import java.util.TreeMap;
import net.minecraft.block.Block;
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 net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
2012-07-25 12:45:15 +02:00
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineFuel;
2013-12-02 06:57:31 +01:00
import buildcraft.api.recipes.BuildcraftRecipes;
2012-07-25 12:45:15 +02:00
import buildcraft.core.BlockIndex;
import buildcraft.core.BlockSpring;
2012-07-25 12:45:15 +02:00
import buildcraft.core.DefaultProps;
2013-09-12 15:27:11 +02:00
import buildcraft.core.InterModComms;
2012-09-08 21:46:17 +02:00
import buildcraft.core.Version;
2012-09-05 22:29:38 +02:00
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.energy.BlockBuildcraftFluid;
2012-07-25 12:45:15 +02:00
import buildcraft.energy.BlockEngine;
2014-04-03 08:44:33 +02:00
import buildcraft.energy.BucketHandler;
import buildcraft.energy.EnergyProxy;
2012-07-25 12:45:15 +02:00
import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketBuildcraft;
2012-07-25 12:45:15 +02:00
import buildcraft.energy.ItemEngine;
import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.triggers.TriggerEngineHeat;
2013-07-08 04:57:05 +02:00
import buildcraft.energy.worldgen.BiomeGenOilDesert;
import buildcraft.energy.worldgen.BiomeGenOilOcean;
import buildcraft.energy.worldgen.BiomeInitializer;
2013-07-08 04:57:05 +02:00
import buildcraft.energy.worldgen.OilPopulate;
2014-02-09 21:29:23 +01:00
import buildcraft.transport.network.PacketHandlerTransport;
2012-12-17 23:30:54 +01:00
import cpw.mods.fml.common.Mod;
2013-07-08 04:57:05 +02:00
import cpw.mods.fml.common.Mod.EventHandler;
2012-12-17 23:30:54 +01:00
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
2012-12-17 23:30:54 +01:00
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
2014-02-08 16:04:03 +01:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
2012-12-17 23:30:54 +01:00
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
2013-03-28 10:00:05 +01:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2014-02-08 14:47:31 +01:00
2012-12-17 23:30:54 +01:00
@Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE)
public class BuildCraftEnergy extends BuildCraftMod {
2012-05-09 22:43:05 +02:00
public final static int ENERGY_REMOVE_BLOCK = 25;
public final static int ENERGY_EXTRACT_ITEM = 2;
public static boolean spawnOilSprings = true;
public static BiomeGenOilDesert biomeOilDesert;
public static BiomeGenOilOcean biomeOilOcean;
2012-05-09 22:43:05 +02:00
public static BlockEngine engineBlock;
private static Fluid buildcraftFluidOil;
private static Fluid buildcraftFluidFuel;
2013-07-12 23:21:44 +02:00
public static Fluid fluidOil;
public static Fluid fluidFuel;
public static Block blockOil;
public static Block blockFuel;
2012-05-09 22:43:05 +02:00
public static Item bucketOil;
public static Item bucketFuel;
public static Item fuel;
2013-06-13 22:50:51 +02:00
public static boolean canOilBurn;
2013-12-02 06:57:31 +01:00
public static double oilWellScalar = 1.0;
2012-05-09 22:43:05 +02:00
public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>();
2013-12-27 17:40:44 +01:00
public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(EnergyStage.BLUE);
public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(EnergyStage.GREEN);
public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(EnergyStage.YELLOW);
public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(EnergyStage.RED);
@Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance;
2012-06-04 22:48:18 +02:00
2013-07-12 23:21:44 +02:00
@EventHandler
2014-04-03 08:44:33 +02:00
public void preInit(FMLPreInitializationEvent evt) {
2014-02-16 09:19:11 +01:00
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);
2013-06-13 22:50:51 +02:00
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);
2013-10-07 18:14:51 +02:00
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();
2012-05-09 22:43:05 +02:00
if (oilDesertBiomeId > 0) {
2014-02-08 20:39:39 +01:00
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) {
2014-02-08 20:39:39 +01:00
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);
}
2014-02-08 14:47:31 +01:00
engineBlock = new BlockEngine();
CoreProxy.proxy.registerBlock(engineBlock, ItemEngine.class);
2012-05-09 22:43:05 +02:00
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");
2012-05-09 22:43:05 +02:00
// Oil and fuel
2014-02-16 00:48:23 +01:00
buildcraftFluidOil = new Fluid("oil").setDensity(800).setViscosity(1500);
FluidRegistry.registerFluid(buildcraftFluidOil);
2013-07-12 23:21:44 +02:00
fluidOil = FluidRegistry.getFluid("oil");
2014-02-16 00:48:23 +01:00
buildcraftFluidFuel = new Fluid("fuel");
FluidRegistry.registerFluid(buildcraftFluidFuel);
2013-07-12 23:21:44 +02:00
fluidFuel = FluidRegistry.getFluid("fuel");
2014-02-08 14:47:31 +01:00
if (fluidOil.getBlock() == null) {
blockOil = new BlockBuildcraftFluid(fluidOil, Material.water).setFlammable(canOilBurn).setFlammability(0);
blockOil.setBlockName("blockOil");
CoreProxy.proxy.registerBlock(blockOil);
2014-04-03 08:44:33 +02:00
fluidOil.setBlock(blockOil);
} else {
2014-02-08 14:47:31 +01:00
blockOil = fluidOil.getBlock();
}
if (blockOil != null) {
spawnOilSprings = BuildCraftCore.mainConfiguration.get("worldgen", "oilSprings", true).getBoolean(true);
2013-07-12 23:21:44 +02:00
BlockSpring.EnumSpring.OIL.canGen = spawnOilSprings;
BlockSpring.EnumSpring.OIL.liquidBlock = blockOil;
}
2012-05-09 22:43:05 +02:00
2014-02-08 14:47:31 +01:00
if (fluidFuel.getBlock() == null) {
blockFuel = new BlockBuildcraftFluid(fluidFuel, Material.water).setFlammable(true).setFlammability(5).setParticleColor(0.7F, 0.7F, 0.0F);
blockFuel.setBlockName("blockFuel");
CoreProxy.proxy.registerBlock(blockFuel);
2014-04-03 08:44:33 +02:00
fluidFuel.setBlock(blockFuel);
} else {
2014-02-08 14:47:31 +01:00
blockFuel = fluidFuel.getBlock();
}
2012-05-09 22:43:05 +02:00
// Buckets
2012-05-09 22:43:05 +02:00
2014-02-08 14:47:31 +01:00
if (blockOil != null) {
bucketOil = new ItemBucketBuildcraft(blockOil);
bucketOil.setUnlocalizedName("bucketOil").setContainerItem(Items.bucket);
LanguageRegistry.addName(bucketOil, "Oil Bucket");
CoreProxy.proxy.registerItem(bucketOil);
2014-02-08 14:47:31 +01:00
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("oil", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketOil), new ItemStack(Items.bucket));
}
2012-05-09 22:43:05 +02:00
2014-02-08 14:47:31 +01:00
if (blockFuel != null) {
bucketFuel = new ItemBucketBuildcraft(blockFuel);
bucketFuel.setUnlocalizedName("bucketFuel").setContainerItem(Items.bucket);
LanguageRegistry.addName(bucketFuel, "Fuel Bucket");
CoreProxy.proxy.registerItem(bucketFuel);
2014-02-08 14:47:31 +01:00
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("fuel", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketFuel), new ItemStack(Items.bucket));
}
2013-08-16 05:23:43 +02:00
// 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);
2012-12-17 23:30:54 +01:00
2013-12-02 06:57:31 +01:00
BuildcraftRecipes.refinery.addRecipe(new FluidStack(fluidOil, 1), new FluidStack(fluidFuel, 1), 12, 1);
2012-05-09 22:43:05 +02:00
// Iron Engine Fuels
// IronEngineFuel.addFuel("lava", 1, 20000);
2013-10-07 18:14:51 +02:00
IronEngineFuel.addFuel("oil", 3, (int) (5000 * fuelOilMultiplier));
IronEngineFuel.addFuel("fuel", 6, (int) (25000 * fuelFuelMultiplier));
2012-05-09 22:43:05 +02:00
// Iron Engine Coolants
2013-07-08 04:57:05 +02:00
IronEngineCoolant.addCoolant(FluidRegistry.getFluid("water"), 0.0023F);
2014-02-08 14:47:31 +01:00
IronEngineCoolant.addCoolant(Blocks.ice, 0, FluidRegistry.getFluidStack("water", FluidContainerRegistry.BUCKET_VOLUME * 2));
2013-03-28 10:00:05 +01:00
MinecraftForge.EVENT_BUS.register(this);
}
2013-07-12 23:21:44 +02:00
@EventHandler
public void init(FMLInitializationEvent evt) {
2014-02-09 21:29:23 +01:00
channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-ENERGY", new PacketHandlerTransport());
2014-04-03 08:44:33 +02:00
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
2014-02-08 14:47:31 +01:00
//new BptBlockEngine(engineBlock.blockID);
if (BuildCraftCore.loadDefaultRecipes) {
loadRecipes();
}
EnergyProxy.proxy.registerBlockRenderers();
EnergyProxy.proxy.registerTileEntities();
}
2013-07-12 23:21:44 +02:00
@EventHandler
public void postInit(FMLPostInitializationEvent evt) {
if (BuildCraftCore.modifyWorld) {
MinecraftForge.EVENT_BUS.register(OilPopulate.INSTANCE);
MinecraftForge.TERRAIN_GEN_BUS.register(new BiomeInitializer());
}
}
2014-02-08 16:04:03 +01:00
@SubscribeEvent
2013-03-28 10:00:05 +01:00
@SideOnly(Side.CLIENT)
public void textureHook(TextureStitchEvent.Post event) {
2014-02-08 16:04:03 +01:00
if (event.map.getTextureType() == 0) {
2013-08-16 05:23:43 +02:00
buildcraftFluidOil.setIcons(blockOil.getBlockTextureFromSide(1), blockOil.getBlockTextureFromSide(2));
buildcraftFluidFuel.setIcons(blockFuel.getBlockTextureFromSide(1), blockFuel.getBlockTextureFromSide(2));
2013-03-28 10:00:05 +01:00
}
2012-05-09 22:43:05 +02:00
}
2012-06-04 22:48:18 +02:00
public static void loadRecipes() {
2012-12-17 23:30:54 +01:00
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 0),
2014-02-08 14:47:31 +01:00
new Object[]{"www", " g ", "GpG", 'w', "plankWood", 'g', Blocks.glass, 'G',
BuildCraftCore.woodenGearItem, 'p', Blocks.piston});
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 1), new Object[]{"www", " g ", "GpG", 'w', "cobblestone",
2014-02-08 14:47:31 +01:00
'g', Blocks.glass, 'G', BuildCraftCore.stoneGearItem, 'p', Blocks.piston});
CoreProxy.proxy.addCraftingRecipe(new ItemStack(engineBlock, 1, 2), new Object[]{"www", " g ", "GpG", 'w', Items.iron_ingot,
'g', Blocks.glass, 'G', BuildCraftCore.ironGearItem, 'p', Blocks.piston});
2012-05-09 22:43:05 +02:00
}
private int findUnusedBiomeID (String biomeName) {
int freeBiomeID = 0;
// code to find a free biome
2014-04-03 08:44:33 +02:00
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 {
public BiomeIdLimitException(String biome) {
super(String.format("You have a run out of free Biome Ids for %s", biome));
}
}
2014-04-03 08:44:33 +02:00
2014-04-03 04:12:26 +02:00
throw new BiomeIdLimitException(biomeName);
}
2013-09-12 15:27:11 +02:00
@EventHandler
public void processIMCRequests(FMLInterModComms.IMCEvent event) {
2013-10-07 18:14:51 +02:00
InterModComms.processIMC(event);
}
2012-05-09 22:43:05 +02:00
}