Added fluid power manager, imports from forestry and bc

This commit is contained in:
modmuss50 2015-09-08 18:39:59 +01:00
parent 72799a9474
commit 8aafd118f5
9 changed files with 71 additions and 70 deletions

View 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>();
}

View file

@ -0,0 +1,4 @@
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI") package techreborn.api.fuel;
import cpw.mods.fml.common.API;

View file

@ -25,7 +25,6 @@ public class CompatManager {
registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty"); registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty");
registerCompact(RecipesThaumcraft.class, "Thaumcraft"); registerCompact(RecipesThaumcraft.class, "Thaumcraft");
registerCompact(RecipesForestry.class, "Forestry"); registerCompact(RecipesForestry.class, "Forestry");
registerCompact(FuelsNoForestry.class, "!Forestry");
registerCompact(MinetweakerCompat.class, "MineTweaker3"); registerCompact(MinetweakerCompat.class, "MineTweaker3");
} }

View file

@ -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) {
}
}

View file

@ -1,23 +1,20 @@
package techreborn.compat.recipes; package techreborn.compat.recipes;
import buildcraft.BuildCraftEnergy; import buildcraft.api.fuels.IFuel;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.core.Version; import buildcraft.core.Version;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.GeneratorFuel;
import ic2.api.item.IC2Items; import ic2.api.item.IC2Items;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import techreborn.api.fuel.FluidPowerManager;
import techreborn.compat.ICompatModule; import techreborn.compat.ICompatModule;
import techreborn.config.ConfigTechReborn;
import techreborn.util.CraftingHelper; import techreborn.util.CraftingHelper;
import techreborn.util.LogHelper; import techreborn.util.LogHelper;
import techreborn.util.RecipeRemover; import techreborn.util.RecipeRemover;
@ -54,9 +51,7 @@ public class RecipesBuildcraft implements ICompatModule {
@Override @Override
public void init(FMLInitializationEvent event) { 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 @Override
@ -87,6 +82,9 @@ public class RecipesBuildcraft implements ICompatModule {
} }
removeRecipes(); removeRecipes();
addRecipies(); addRecipies();
for(IFuel fuel : buildcraft.energy.fuels.FuelManager.INSTANCE.getFuels()){
FluidPowerManager.fluidPowerValues.put(fuel.getFluid(), (double) (fuel.getPowerPerCycle() / fuel.getTotalBurningTime()) * ConfigTechReborn.euPerRF);
}
} }
@Override @Override

View file

@ -4,6 +4,8 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.GeneratorFuel;
import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryBlock;
import ic2.api.item.IC2Items; import ic2.api.item.IC2Items;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -11,11 +13,14 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import techreborn.api.fuel.FluidPowerManager;
import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.IndustrialSawmillRecipe; import techreborn.api.recipe.machines.IndustrialSawmillRecipe;
import techreborn.compat.ICompatModule; import techreborn.compat.ICompatModule;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import java.rmi.UnexpectedException;
public class RecipesForestry implements ICompatModule { public class RecipesForestry implements ICompatModule {
@Override @Override
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
@ -266,7 +271,18 @@ public class RecipesForestry implements ICompatModule {
@Override @Override
public void postInit(FMLPostInitializationEvent event) { 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 @Override

View file

@ -1,13 +1,11 @@
package techreborn.init; package techreborn.init;
import cpw.mods.fml.common.registry.GameRegistry; 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.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import techreborn.api.fuel.FluidPowerManager;
import techreborn.blocks.fluid.BlockFluidTechReborn; import techreborn.blocks.fluid.BlockFluidTechReborn;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
@ -152,7 +150,7 @@ public class ModFluids {
BlockFluidNitrocoalfuel = new BlockFluidTechReborn(fluidNitrocoalfuel, Material.water, "techreborn.nitrocoalfuel"); BlockFluidNitrocoalfuel = new BlockFluidTechReborn(fluidNitrocoalfuel, Material.water, "techreborn.nitrocoalfuel");
GameRegistry.registerBlock(BlockFluidNitrocoalfuel, ModInfo.MOD_ID + "_" + BlockFluidNitrocoalfuel.getUnlocalizedName().substring(5)); GameRegistry.registerBlock(BlockFluidNitrocoalfuel, ModInfo.MOD_ID + "_" + BlockFluidNitrocoalfuel.getUnlocalizedName().substring(5));
fluidNitrocoalfuel.setUnlocalizedName(fluidNitrocoalfuel.getUnlocalizedName()); 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); FluidRegistry.registerFluid(fluidNitrofuel);
BlockFluidNitrofuel = new BlockFluidTechReborn(fluidNitrofuel, Material.water, "techreborn.nitrofuel"); BlockFluidNitrofuel = new BlockFluidTechReborn(fluidNitrofuel, Material.water, "techreborn.nitrofuel");

View file

@ -303,4 +303,8 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
return Double.toString(Math.floor(euValue)).concat(" EU"); return Double.toString(Math.floor(euValue)).concat(" EU");
} }
} }
public double getFreeSpace(){
return getMaxPower() - energy;
}
} }

View file

@ -11,6 +11,7 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.*;
import techreborn.api.fuel.FluidPowerManager;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.powerSystem.TilePowerAcceptor; import techreborn.powerSystem.TilePowerAcceptor;
@ -80,12 +81,7 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) { public boolean canFill(ForgeDirection from, Fluid fluid) {
if (fluid != null) { return FluidPowerManager.fluidPowerValues.containsKey(fluid);
if (FluidRegistry.getFluidName(fluid.getID()).contentEquals("lava")) {
return true;
}
}
return false;
} }
@Override @Override
@ -130,19 +126,27 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (!worldObj.isRemote) if (!worldObj.isRemote) {
FluidUtils.drainContainers(this, inventory, 0, 1); FluidUtils.drainContainers(this, inventory, 0, 1);
if (tank.getFluidAmount() > 0 FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType());
&& getMaxPower() - getEnergy() >= euTick) { if (tank.getFluidType() != null && getStackInSlot(2) == null) {
tank.drain(1, true); inventory.setInventorySlotContents(2, new ItemStack(tank
addEnergy(euTick); .getFluidType().getBlock()));
} syncWithAll();
if (tank.getFluidType() != null && getStackInSlot(2) == null) { } else if (tank.getFluidType() == null && getStackInSlot(2) != null) {
inventory.setInventorySlotContents(2, new ItemStack(tank setInventorySlotContents(2, null);
.getFluidType().getBlock())); syncWithAll();
} else if (tank.getFluidType() == null && getStackInSlot(2) != null) { }
setInventorySlotContents(2, null);
} if (!tank.isEmpty()) {
double powerIn = FluidPowerManager.fluidPowerValues.get(tank.getFluidType());
if(getFreeSpace() >= powerIn){
addEnergy(powerIn);
tank.drain(1, true);
}
}
}
} }
@Override @Override