diff --git a/src/main/java/techreborn/api/fuel/FluidPowerManager.java b/src/main/java/techreborn/api/fuel/FluidPowerManager.java new file mode 100644 index 000000000..8e532cb96 --- /dev/null +++ b/src/main/java/techreborn/api/fuel/FluidPowerManager.java @@ -0,0 +1,14 @@ +package techreborn.api.fuel; + +import net.minecraftforge.fluids.Fluid; + +import java.util.HashMap; + +public class FluidPowerManager { + + /** + * Use this to register a fluid with a power value + */ + public static HashMap fluidPowerValues = new HashMap(); + +} diff --git a/src/main/java/techreborn/api/fuel/package-info.java b/src/main/java/techreborn/api/fuel/package-info.java new file mode 100644 index 000000000..a2597367e --- /dev/null +++ b/src/main/java/techreborn/api/fuel/package-info.java @@ -0,0 +1,4 @@ +@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI") package techreborn.api.fuel; + +import cpw.mods.fml.common.API; + diff --git a/src/main/java/techreborn/compat/CompatManager.java b/src/main/java/techreborn/compat/CompatManager.java index d765d3e43..38f6d410e 100644 --- a/src/main/java/techreborn/compat/CompatManager.java +++ b/src/main/java/techreborn/compat/CompatManager.java @@ -25,7 +25,6 @@ public class CompatManager { registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty"); registerCompact(RecipesThaumcraft.class, "Thaumcraft"); registerCompact(RecipesForestry.class, "Forestry"); - registerCompact(FuelsNoForestry.class, "!Forestry"); registerCompact(MinetweakerCompat.class, "MineTweaker3"); } diff --git a/src/main/java/techreborn/compat/recipes/FuelsNoForestry.java b/src/main/java/techreborn/compat/recipes/FuelsNoForestry.java deleted file mode 100644 index 35675da58..000000000 --- a/src/main/java/techreborn/compat/recipes/FuelsNoForestry.java +++ /dev/null @@ -1,36 +0,0 @@ -package techreborn.compat.recipes; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.GeneratorFuel; -import net.minecraftforge.fluids.Fluid; -import techreborn.compat.ICompatModule; - -import java.util.HashMap; - - -public class FuelsNoForestry implements ICompatModule { - @Override - public void preInit(FMLPreInitializationEvent event) { - if(FuelManager.generatorFuel == null){ - FuelManager.generatorFuel = new HashMap(); - } - } - - @Override - public void init(FMLInitializationEvent event) { - } - - @Override - public void postInit(FMLPostInitializationEvent event) { - - } - - @Override - public void serverStarting(FMLServerStartingEvent event) { - - } -} diff --git a/src/main/java/techreborn/compat/recipes/RecipesBuildcraft.java b/src/main/java/techreborn/compat/recipes/RecipesBuildcraft.java index f21a0758b..f81e73f7a 100644 --- a/src/main/java/techreborn/compat/recipes/RecipesBuildcraft.java +++ b/src/main/java/techreborn/compat/recipes/RecipesBuildcraft.java @@ -1,23 +1,20 @@ package techreborn.compat.recipes; -import buildcraft.BuildCraftEnergy; -import buildcraft.api.core.BuildCraftAPI; -import buildcraft.api.fuels.BuildcraftFuelRegistry; +import buildcraft.api.fuels.IFuel; import buildcraft.core.Version; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.GeneratorFuel; import ic2.api.item.IC2Items; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import techreborn.api.fuel.FluidPowerManager; import techreborn.compat.ICompatModule; +import techreborn.config.ConfigTechReborn; import techreborn.util.CraftingHelper; import techreborn.util.LogHelper; import techreborn.util.RecipeRemover; @@ -54,9 +51,7 @@ public class RecipesBuildcraft implements ICompatModule { @Override public void init(FMLInitializationEvent event) { - if(!FuelManager.generatorFuel.containsKey(BuildCraftEnergy.fluidFuel)){ - FuelManager.generatorFuel.put(BuildCraftEnergy.fluidFuel, new GeneratorFuel(new FluidStack(BuildCraftEnergy.fluidFuel, 1000), 38400, 6000)); - } + } @Override @@ -87,6 +82,9 @@ public class RecipesBuildcraft implements ICompatModule { } removeRecipes(); addRecipies(); + for(IFuel fuel : buildcraft.energy.fuels.FuelManager.INSTANCE.getFuels()){ + FluidPowerManager.fluidPowerValues.put(fuel.getFluid(), (double) (fuel.getPowerPerCycle() / fuel.getTotalBurningTime()) * ConfigTechReborn.euPerRF); + } } @Override diff --git a/src/main/java/techreborn/compat/recipes/RecipesForestry.java b/src/main/java/techreborn/compat/recipes/RecipesForestry.java index 991d42f76..7f4da9838 100644 --- a/src/main/java/techreborn/compat/recipes/RecipesForestry.java +++ b/src/main/java/techreborn/compat/recipes/RecipesForestry.java @@ -4,6 +4,8 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.GeneratorFuel; import forestry.core.config.ForestryBlock; import ic2.api.item.IC2Items; import net.minecraft.init.Items; @@ -11,11 +13,14 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import techreborn.api.fuel.FluidPowerManager; import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.machines.IndustrialSawmillRecipe; import techreborn.compat.ICompatModule; import techreborn.config.ConfigTechReborn; +import java.rmi.UnexpectedException; + public class RecipesForestry implements ICompatModule { @Override public void preInit(FMLPreInitializationEvent event) { @@ -266,7 +271,18 @@ public class RecipesForestry implements ICompatModule { @Override public void postInit(FMLPostInitializationEvent event) { - + for(Object fuel : FuelManager.generatorFuel.entrySet().toArray()){ + if(fuel instanceof GeneratorFuel){ + GeneratorFuel generatorFuel = (GeneratorFuel) fuel; + FluidPowerManager.fluidPowerValues.put(generatorFuel.fuelConsumed.getFluid(), (double) (generatorFuel.eu / generatorFuel.rate)); + } else { + try { + throw new UnexpectedException(fuel + " should be an instace of GeneratorFuel"); + } catch (UnexpectedException e) { + e.printStackTrace(); + } + } + } } @Override diff --git a/src/main/java/techreborn/init/ModFluids.java b/src/main/java/techreborn/init/ModFluids.java index b429aa296..01ad1bf2d 100644 --- a/src/main/java/techreborn/init/ModFluids.java +++ b/src/main/java/techreborn/init/ModFluids.java @@ -1,13 +1,11 @@ package techreborn.init; import cpw.mods.fml.common.registry.GameRegistry; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.GeneratorFuel; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; +import techreborn.api.fuel.FluidPowerManager; import techreborn.blocks.fluid.BlockFluidTechReborn; import techreborn.lib.ModInfo; @@ -152,7 +150,7 @@ public class ModFluids { BlockFluidNitrocoalfuel = new BlockFluidTechReborn(fluidNitrocoalfuel, Material.water, "techreborn.nitrocoalfuel"); GameRegistry.registerBlock(BlockFluidNitrocoalfuel, ModInfo.MOD_ID + "_" + BlockFluidNitrocoalfuel.getUnlocalizedName().substring(5)); fluidNitrocoalfuel.setUnlocalizedName(fluidNitrocoalfuel.getUnlocalizedName()); - FuelManager.generatorFuel.put(fluidNitrocoalfuel, new GeneratorFuel(new FluidStack(fluidNitrocoalfuel, 1000), 48000, 6000)); + FluidPowerManager.fluidPowerValues.put(fluidNitrocoalfuel, 48.0); FluidRegistry.registerFluid(fluidNitrofuel); BlockFluidNitrofuel = new BlockFluidTechReborn(fluidNitrofuel, Material.water, "techreborn.nitrofuel"); diff --git a/src/main/java/techreborn/powerSystem/TilePowerAcceptor.java b/src/main/java/techreborn/powerSystem/TilePowerAcceptor.java index a0442fbf9..226d38889 100644 --- a/src/main/java/techreborn/powerSystem/TilePowerAcceptor.java +++ b/src/main/java/techreborn/powerSystem/TilePowerAcceptor.java @@ -303,4 +303,8 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements return Double.toString(Math.floor(euValue)).concat(" EU"); } } + + public double getFreeSpace(){ + return getMaxPower() - energy; + } } diff --git a/src/main/java/techreborn/tiles/TileDieselGenerator.java b/src/main/java/techreborn/tiles/TileDieselGenerator.java index 5f15d0bcf..0c94cc92c 100644 --- a/src/main/java/techreborn/tiles/TileDieselGenerator.java +++ b/src/main/java/techreborn/tiles/TileDieselGenerator.java @@ -11,6 +11,7 @@ import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; +import techreborn.api.fuel.FluidPowerManager; import techreborn.config.ConfigTechReborn; import techreborn.init.ModBlocks; import techreborn.powerSystem.TilePowerAcceptor; @@ -80,12 +81,7 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl @Override public boolean canFill(ForgeDirection from, Fluid fluid) { - if (fluid != null) { - if (FluidRegistry.getFluidName(fluid.getID()).contentEquals("lava")) { - return true; - } - } - return false; + return FluidPowerManager.fluidPowerValues.containsKey(fluid); } @Override @@ -130,19 +126,27 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl @Override public void updateEntity() { super.updateEntity(); - if (!worldObj.isRemote) - FluidUtils.drainContainers(this, inventory, 0, 1); - if (tank.getFluidAmount() > 0 - && getMaxPower() - getEnergy() >= euTick) { - tank.drain(1, true); - addEnergy(euTick); - } - if (tank.getFluidType() != null && getStackInSlot(2) == null) { - inventory.setInventorySlotContents(2, new ItemStack(tank - .getFluidType().getBlock())); - } else if (tank.getFluidType() == null && getStackInSlot(2) != null) { - setInventorySlotContents(2, null); - } + if (!worldObj.isRemote) { + FluidUtils.drainContainers(this, inventory, 0, 1); + FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType()); + if (tank.getFluidType() != null && getStackInSlot(2) == null) { + inventory.setInventorySlotContents(2, new ItemStack(tank + .getFluidType().getBlock())); + syncWithAll(); + } else if (tank.getFluidType() == null && getStackInSlot(2) != null) { + setInventorySlotContents(2, null); + syncWithAll(); + } + + if (!tank.isEmpty()) { + double powerIn = FluidPowerManager.fluidPowerValues.get(tank.getFluidType()); + if(getFreeSpace() >= powerIn){ + addEnergy(powerIn); + tank.drain(1, true); + } + } + } + } @Override