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 ;
2013-05-01 22:31:18 +02:00
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 ;
2013-03-16 09:21:48 +01:00
import buildcraft.core.triggers.BCTrigger ;
2013-07-13 01:38:03 +02:00
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 ;
2012-08-24 19:25:54 +02:00
import buildcraft.energy.EnergyProxy ;
2012-07-25 12:45:15 +02:00
import buildcraft.energy.GuiHandler ;
2013-07-13 01:38:03 +02:00
import buildcraft.energy.ItemBucketBuildcraft ;
2012-07-25 12:45:15 +02:00
import buildcraft.energy.ItemEngine ;
2013-06-29 10:33:21 +02:00
import buildcraft.energy.TileEngine.EnergyStage ;
2013-12-05 22:38:00 +01:00
import buildcraft.energy.triggers.TriggerEngineHeat ;
2013-07-08 04:57:05 +02:00
import buildcraft.energy.worldgen.BiomeGenOilDesert ;
2013-05-18 16:37:08 +02:00
import buildcraft.energy.worldgen.BiomeGenOilOcean ;
2013-05-17 19:49:41 +02:00
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 ;
2013-05-02 13:19:33 +02:00
import cpw.mods.fml.common.event.FMLInterModComms ;
2013-06-11 23:53:03 +02:00
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 )
2014-01-13 20:26:16 +01:00
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 ;
2013-05-05 15:41:29 +02:00
public static boolean spawnOilSprings = true ;
2013-05-18 16:37:08 +02:00
public static BiomeGenOilDesert biomeOilDesert ;
public static BiomeGenOilOcean biomeOilOcean ;
2012-05-09 22:43:05 +02:00
public static BlockEngine engineBlock ;
2013-07-13 01:38:03 +02:00
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 ;
2013-07-13 01:38:03 +02:00
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 ) ;
2012-08-26 20:27:37 +02:00
@Instance ( " BuildCraft|Energy " )
2012-08-24 19:25:54 +02:00
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 ) ;
2013-09-22 15:48:25 +02:00
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 ) ;
2013-05-17 19:49:41 +02:00
BuildCraftCore . mainConfiguration . save ( ) ;
2012-05-09 22:43:05 +02:00
2013-07-13 01:38:03 +02:00
if ( oilDesertBiomeId > 0 ) {
2014-02-08 20:39:39 +01:00
if ( BiomeGenBase . getBiomeGenArray ( ) [ oilDesertBiomeId ] ! = null ) {
2014-04-02 21:42:10 +02:00
oilDesertBiomeId = findUnusedBiomeID ( " oilDesert " ) ;
// save changes to config file
BuildCraftCore . mainConfiguration . get ( " biomes " , " biomeOilDesert " , oilDesertBiomeId ) . set ( oilDesertBiomeId ) ;
BuildCraftCore . mainConfiguration . save ( ) ;
2013-05-17 19:49:41 +02:00
}
2013-07-13 01:38:03 +02:00
biomeOilDesert = BiomeGenOilDesert . makeBiome ( oilDesertBiomeId ) ;
2013-05-17 19:49:41 +02:00
}
2013-06-11 23:53:03 +02:00
2013-07-13 01:38:03 +02:00
if ( oilOceanBiomeId > 0 ) {
2014-02-08 20:39:39 +01:00
if ( BiomeGenBase . getBiomeGenArray ( ) [ oilOceanBiomeId ] ! = null ) {
2014-04-02 21:42:10 +02:00
oilOceanBiomeId = findUnusedBiomeID ( " oilOcean " ) ;
// save changes to config file
BuildCraftCore . mainConfiguration . get ( " biomes " , " biomeOilOcean " , oilOceanBiomeId ) . set ( oilOceanBiomeId ) ;
BuildCraftCore . mainConfiguration . save ( ) ;
2013-05-18 16:37:08 +02:00
}
2013-07-13 01:38:03 +02:00
biomeOilOcean = BiomeGenOilOcean . makeBiome ( oilOceanBiomeId ) ;
2013-05-18 16:37:08 +02:00
}
2013-05-05 15:41:29 +02:00
2014-02-08 14:47:31 +01:00
engineBlock = new BlockEngine ( ) ;
2013-05-01 22:31:18 +02:00
CoreProxy . proxy . registerBlock ( engineBlock , ItemEngine . class ) ;
2012-05-09 22:43:05 +02:00
2012-08-24 19:25:54 +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
2013-07-13 01:38:03 +02:00
2012-08-17 18:48:06 +02:00
// Oil and fuel
2014-02-16 00:48:23 +01:00
buildcraftFluidOil = new Fluid ( " oil " ) . setDensity ( 800 ) . setViscosity ( 1500 ) ;
2013-12-05 18:56:03 +01:00
2013-07-13 01:38:03 +02:00
FluidRegistry . registerFluid ( buildcraftFluidOil ) ;
2013-07-12 23:21:44 +02:00
fluidOil = FluidRegistry . getFluid ( " oil " ) ;
2013-07-13 01:38:03 +02:00
2014-02-16 00:48:23 +01:00
buildcraftFluidFuel = new Fluid ( " fuel " ) ;
2013-07-13 01:38:03 +02:00
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 ) ;
2013-07-13 01:38:03 +02:00
} else {
2014-02-08 14:47:31 +01:00
blockOil = fluidOil . getBlock ( ) ;
2013-07-13 01:38:03 +02:00
}
if ( blockOil ! = null ) {
2013-12-05 18:56:03 +01:00
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 ;
2013-05-02 13:19:33 +02:00
}
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 ) ;
2013-07-13 01:38:03 +02:00
} else {
2014-02-08 14:47:31 +01:00
blockFuel = fluidFuel . getBlock ( ) ;
2013-07-13 01:38:03 +02:00
}
2012-05-09 22:43:05 +02:00
2013-07-13 01:38:03 +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 ) ;
2013-07-13 01:38:03 +02:00
LanguageRegistry . addName ( bucketOil , " Oil Bucket " ) ;
2013-11-14 02:23:12 +01:00
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 ) ) ;
2013-07-13 01:38:03 +02:00
}
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 ) ;
2013-07-13 01:38:03 +02:00
LanguageRegistry . addName ( bucketFuel , " Fuel Bucket " ) ;
2013-11-14 02:23:12 +01:00
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-07-13 01:38:03 +02:00
}
2013-08-16 05:23:43 +02:00
2014-02-25 10:48:39 +01: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
2012-07-20 23:43:27 +02:00
// Iron Engine Fuels
2013-08-29 16:07:11 +02:00
// 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
2012-07-20 23:43:27 +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 ) ) ;
2012-08-24 19:25:54 +02:00
2013-03-28 10:00:05 +01:00
MinecraftForge . EVENT_BUS . register ( this ) ;
}
2013-07-12 23:21:44 +02:00
@EventHandler
2013-06-11 23:53:03 +02:00
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 ( ) ) ;
2013-06-11 23:53:03 +02:00
2014-02-08 14:47:31 +01:00
//new BptBlockEngine(engineBlock.blockID);
2013-06-11 23:53:03 +02:00
if ( BuildCraftCore . loadDefaultRecipes ) {
loadRecipes ( ) ;
}
EnergyProxy . proxy . registerBlockRenderers ( ) ;
EnergyProxy . proxy . registerTileEntities ( ) ;
}
2013-07-12 23:21:44 +02:00
@EventHandler
2013-06-11 23:53:03 +02:00
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 } ) ;
2013-09-25 22:07:49 +02:00
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
}
2014-04-02 21:42:10 +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 + + ) {
2014-04-02 21:42:10 +02:00
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 ) ;
2014-04-02 21:42:10 +02:00
}
2013-09-12 15:27:11 +02:00
@EventHandler
2013-05-02 13:19:33 +02:00
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
}