Added fluid power manager, imports from forestry and bc
This commit is contained in:
parent
72799a9474
commit
8aafd118f5
9 changed files with 71 additions and 70 deletions
14
src/main/java/techreborn/api/fuel/FluidPowerManager.java
Normal file
14
src/main/java/techreborn/api/fuel/FluidPowerManager.java
Normal file
|
@ -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<Fluid, Double> fluidPowerValues = new HashMap<Fluid, Double>();
|
||||
|
||||
}
|
4
src/main/java/techreborn/api/fuel/package-info.java
Normal file
4
src/main/java/techreborn/api/fuel/package-info.java
Normal file
|
@ -0,0 +1,4 @@
|
|||
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI") package techreborn.api.fuel;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Fluid, GeneratorFuel>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
if (!worldObj.isRemote) {
|
||||
FluidUtils.drainContainers(this, inventory, 0, 1);
|
||||
if (tank.getFluidAmount() > 0
|
||||
&& getMaxPower() - getEnergy() >= euTick) {
|
||||
tank.drain(1, true);
|
||||
addEnergy(euTick);
|
||||
}
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue