Merge branch 'Prototik-iron-engine' into 6.1.x

This commit is contained in:
SpaceToad 2014-09-06 12:29:16 +02:00
commit 89c9d0f34b
15 changed files with 474 additions and 217 deletions

View file

@ -8,49 +8,115 @@
*/
package buildcraft.api.core;
import java.util.Objects;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
/**
* This class is used whenever stacks needs to be stored as keys.
*/
public class StackKey {
public final class StackKey {
public final ItemStack stack;
public final FluidStack fluidStack;
public StackKey(FluidStack fluidStack) {
this(null, fluidStack);
}
public StackKey(ItemStack stack) {
this(stack, null);
}
public StackKey(ItemStack stack, FluidStack fluidStack) {
this.stack = stack;
this.fluidStack = fluidStack;
}
public static StackKey stack(Item item, int amount, int damage) {
return new StackKey(new ItemStack(item, amount, damage));
}
public static StackKey stack(Block block, int amount, int damage) {
return new StackKey(new ItemStack(block, amount, damage));
}
public static StackKey stack(Item item) {
return new StackKey(new ItemStack(item, 1, 0));
}
public static StackKey stack(Block block) {
return new StackKey(new ItemStack(block, 1, 0));
}
public static StackKey stack(ItemStack itemStack) {
return new StackKey(itemStack);
}
public static StackKey fluid(Fluid fluid, int amount) {
return new StackKey(new FluidStack(fluid, amount));
}
public static StackKey fluid(Fluid fluid) {
return new StackKey(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME));
}
public static StackKey fluid(FluidStack fluidStack) {
return new StackKey(fluidStack);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || o.getClass() != StackKey.class) {
return false;
}
StackKey k = (StackKey) o;
if ((stack == null ^ k.stack == null) || (fluidStack == null ^ k.fluidStack == null)) {
return false;
}
if (stack != null) {
if (stack.getItem() != k.stack.getItem() ||
stack.getHasSubtypes() && stack.getItemDamage() != k.stack.getItemDamage() ||
!Objects.equals(stack.getTagCompound(), k.stack.getTagCompound())) {
return false;
}
}
if (fluidStack != null) {
if (fluidStack.fluidID != k.fluidStack.fluidID ||
fluidStack.amount != k.fluidStack.amount ||
!Objects.equals(fluidStack.tag, k.fluidStack.tag)) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 67 * hash + stack.getItem().hashCode();
hash = 67 * hash + stack.getItemDamage();
if (stack.stackTagCompound != null) {
hash = 67 * hash + stack.stackTagCompound.hashCode();
int result = 7;
if (stack != null) {
result = 31 * result + stack.getItem().hashCode();
result = 31 * result + stack.getItemDamage();
result = 31 * result + Objects.hashCode(stack.getTagCompound());
}
return hash;
result = 31 * result + 7;
if (fluidStack != null) {
result = 31 * result + fluidStack.fluidID;
result = 31 * result + fluidStack.amount;
result = 31 * result + Objects.hashCode(fluidStack.tag);
}
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
} else if (getClass() != obj.getClass()) {
return false;
}
final StackKey other = (StackKey) obj;
if (stack.getItem() != other.stack.getItem()) {
return false;
} else if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) {
return false;
} else {
return !(stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound));
}
public StackKey copy() {
return new StackKey(stack != null ? stack.copy() : null,
fluidStack != null ? fluidStack.copy() : null);
}
}

View file

@ -0,0 +1,17 @@
/**
* 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
*/
package buildcraft.api.fuels;
public final class BuildcraftFuelRegistry {
public static IFuelManager fuel;
public static ICoolantManager coolant;
private BuildcraftFuelRegistry() {
}
}

View file

@ -0,0 +1,17 @@
/**
* 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
*/
package buildcraft.api.fuels;
import net.minecraftforge.fluids.Fluid;
public interface ICoolant {
Fluid getFluid();
float getDegreesCoolingPerMB(float heat);
}

View file

@ -0,0 +1,33 @@
/**
* 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
*/
package buildcraft.api.fuels;
import java.util.Collection;
import net.minecraftforge.fluids.Fluid;
import buildcraft.api.core.StackKey;
public interface ICoolantManager {
ICoolant addCoolant(ICoolant coolant);
ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB);
ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant);
ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier);
Collection<ICoolant> getCoolants();
Collection<ISolidCoolant> getSolidCoolants();
ICoolant getCoolant(Fluid fluid);
ISolidCoolant getSolidCoolant(StackKey solid);
}

View file

@ -0,0 +1,19 @@
/**
* 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
*/
package buildcraft.api.fuels;
import net.minecraftforge.fluids.Fluid;
public interface IFuel {
Fluid getFluid();
int getTotalBurningTime();
float getPowerPerCycle();
}

View file

@ -0,0 +1,23 @@
/**
* 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
*/
package buildcraft.api.fuels;
import java.util.Collection;
import net.minecraftforge.fluids.Fluid;
public interface IFuelManager {
IFuel addFuel(IFuel fuel);
IFuel addFuel(Fluid fluid, float powerPerCycle, int totalBurningTime);
Collection<IFuel> getFuels();
IFuel getFuel(Fluid fluid);
}

View file

@ -0,0 +1,16 @@
/**
* 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
*/
package buildcraft.api.fuels;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface ISolidCoolant {
FluidStack getFluidFromSolidCoolant(ItemStack stack);
}

View file

@ -1,92 +0,0 @@
/**
* 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
*/
package buildcraft.api.fuels;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.core.StackKey;
public final class IronEngineCoolant {
public static Map<String, Coolant> liquidCoolants = new HashMap<String, Coolant>();
public static Map<StackKey, FluidStack> solidCoolants = new HashMap<StackKey, FluidStack>();
private IronEngineCoolant() {
}
public static FluidStack getFluidCoolant(ItemStack stack) {
return solidCoolants.get(new StackKey(stack));
}
public static Coolant getCoolant(ItemStack stack) {
return getCoolant(getFluidCoolant(stack));
}
public static Coolant getCoolant(FluidStack fluidStack) {
return fluidStack != null && fluidStack.getFluid() != null ? liquidCoolants.get(fluidStack.getFluid().getName()) : null;
}
public interface Coolant {
float getDegreesCoolingPerMB(float currentHeat);
}
public static void addCoolant(final Fluid fluid, final float degreesCoolingPerMB) {
if (fluid != null) {
liquidCoolants.put(fluid.getName(), new Coolant() {
@Override
public float getDegreesCoolingPerMB(float currentHeat) {
return degreesCoolingPerMB;
}
});
}
}
/**
* Adds a solid coolant like Ice Blocks. The FluidStack must contain a registered
* Coolant Fluid or nothing will happen. You do not need to call this for
* Fluid Containers.
*
* @param stack
* @param coolant
*/
public static void addCoolant(final ItemStack stack, final FluidStack coolant) {
if (stack != null && stack.getItem() != null && coolant != null) {
solidCoolants.put(new StackKey(stack), coolant);
}
}
/**
* Adds a solid coolant like Ice Blocks. The FluidStack must contain a
* registered Coolant Fluid or nothing will happen. You do not need to call
* this for Fluid Containers.
*
* @param item
* @param coolant
*/
public static void addCoolant(final Item item, final int metadata, final FluidStack coolant) {
addCoolant(new ItemStack(item, 1, metadata), coolant);
}
public static void addCoolant(final Block block, final int metadata, final FluidStack coolant) {
addCoolant(new ItemStack(block, 1, metadata), coolant);
}
public static boolean isCoolant(Fluid fluid) {
return liquidCoolants.containsKey(fluid.getName());
}
}

View file

@ -1,52 +0,0 @@
/**
* 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
*/
package buildcraft.api.fuels;
import java.util.HashMap;
import java.util.Map;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
public final class IronEngineFuel {
public static Map<String, Fuel> fuels = new HashMap<String, Fuel>();
private IronEngineFuel() {
}
public static Fuel getFuelForFluid(Fluid liquid) {
return liquid == null ? null : fuels.get(liquid.getName());
}
public static final class Fuel {
public final Fluid liquid;
public final float powerPerCycle;
public final int totalBurningTime;
private Fuel(String fluidName, float powerPerCycle, int totalBurningTime) {
this(FluidRegistry.getFluid(fluidName), powerPerCycle, totalBurningTime);
}
private Fuel(Fluid liquid, float powerPerCycle, int totalBurningTime) {
this.liquid = liquid;
this.powerPerCycle = powerPerCycle;
this.totalBurningTime = totalBurningTime;
}
}
public static void addFuel(Fluid fluid, float powerPerCycle, int totalBurningTime) {
fuels.put(fluid.getName(), new Fuel(fluid, powerPerCycle, totalBurningTime));
}
public static void addFuel(String fluidName, float powerPerCycle, int totalBurningTime) {
fuels.put(fluidName, new Fuel(fluidName, powerPerCycle, totalBurningTime));
}
}

View file

@ -6,6 +6,6 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|fuels")
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|fuels")
package buildcraft.api.fuels;
import cpw.mods.fml.common.API;

View file

@ -64,6 +64,7 @@ import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools;
import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.StatementManager;
@ -123,6 +124,8 @@ import buildcraft.core.utils.WorldPropertyIsOre;
import buildcraft.core.utils.WorldPropertyIsShoveled;
import buildcraft.core.utils.WorldPropertyIsSoft;
import buildcraft.core.utils.WorldPropertyIsWood;
import buildcraft.energy.fuels.CoolantManager;
import buildcraft.energy.fuels.FuelManager;
import buildcraft.silicon.ItemRedstoneChipset.Chipset;
@Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.7.10,1.8)", dependencies = "required-after:Forge@[10.13.0.1179,)")
@ -271,6 +274,9 @@ public class BuildCraftCore extends BuildCraftMod {
BuildcraftRecipeRegistry.integrationTable = IntegrationRecipeManager.INSTANCE;
BuildcraftRecipeRegistry.refinery = RefineryRecipeManager.INSTANCE;
BuildcraftFuelRegistry.fuel = FuelManager.INSTANCE;
BuildcraftFuelRegistry.coolant = CoolantManager.INSTANCE;
mainConfiguration = new BuildCraftConfiguration(new File(evt.getModConfigurationDirectory(), "buildcraft/main.conf"));
try {
mainConfiguration.load();

View file

@ -47,8 +47,8 @@ import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.JavaTools;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.core.StackKey;
import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.core.BlockSpring;
@ -159,6 +159,7 @@ public class BuildCraftEnergy extends BuildCraftMod {
new String[] {BiomeGenBase.sky.biomeName, BiomeGenBase.hell.biomeName},
"IDs or Biome Types (e.g. SANDY,OCEAN) of biomes that are excluded from generating oil."));
double fuelLavaMultiplier = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "fuel.lava.combustion", 1.0F, "adjust energy value of Lava in Combustion Engines").getDouble(1.0F);
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();
@ -266,14 +267,12 @@ public class BuildCraftEnergy extends BuildCraftMod {
BuildcraftRecipeRegistry.refinery.addRecipe("buildcraft:fuel", new FluidStack(fluidOil, 1), new FluidStack(
fluidFuel, 1), 120, 1);
// Iron Engine Fuels
// IronEngineFuel.addFuel("lava", 1, 20000);
IronEngineFuel.addFuel("oil", 3, (int) (5000 * fuelOilMultiplier));
IronEngineFuel.addFuel("fuel", 6, (int) (25000 * fuelFuelMultiplier));
BuildcraftFuelRegistry.fuel.addFuel(FluidRegistry.LAVA, 2, (int) (6000 * fuelLavaMultiplier));
BuildcraftFuelRegistry.fuel.addFuel(fluidOil, 3, (int) (5000 * fuelOilMultiplier));
BuildcraftFuelRegistry.fuel.addFuel(fluidFuel, 6, (int) (25000 * fuelFuelMultiplier));
// Iron Engine Coolants
IronEngineCoolant.addCoolant(FluidRegistry.getFluid("water"), 0.0023F);
IronEngineCoolant.addCoolant(Blocks.ice, 0, FluidRegistry.getFluidStack("water", FluidContainerRegistry.BUCKET_VOLUME * 2));
BuildcraftFuelRegistry.coolant.addCoolant(FluidRegistry.WATER, 0.0023f);
BuildcraftFuelRegistry.coolant.addSolidCoolant(StackKey.stack(Blocks.ice), StackKey.fluid(FluidRegistry.WATER), 2f);
// Receiver / emitter

View file

@ -26,10 +26,10 @@ import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineCoolant.Coolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.fuels.IronEngineFuel.Fuel;
import buildcraft.api.core.StackKey;
import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.api.fuels.ICoolant;
import buildcraft.api.fuels.IFuel;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
@ -50,8 +50,9 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public Tank tankCoolant = new Tank("tankCoolant", MAX_LIQUID, this);
private int burnTime = 0;
private TankManager tankManager = new TankManager();
private Fuel currentFuel = null;
private TankManager<Tank> tankManager = new TankManager<Tank>();
private IFuel currentFuel;
private int penaltyCooling = 0;
private boolean lastPowered = false;
private BiomeGenBase biomeCache;
@ -74,20 +75,18 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
@Override
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
ItemStack current = player.getCurrentEquippedItem();
if (current != null) {
if (current.getItem() instanceof IItemPipe) {
return false;
}
ItemStack current = player.getCurrentEquippedItem();
if (current != null) {
if (!worldObj.isRemote) {
if (FluidUtils.handleRightClick(this, side, player, true, true)) {
return true;
}
} else {
if (FluidContainerRegistry.isContainer(current)) {
return true;
}
if (!worldObj.isRemote) {
if (FluidUtils.handleRightClick(this, side, player, true, true)) {
return true;
}
} else {
if (FluidContainerRegistry.isContainer(current)) {
return true;
}
}
}
@ -147,7 +146,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public void burn() {
FluidStack fuel = this.tankFuel.getFluid();
if (currentFuel == null && fuel != null) {
currentFuel = IronEngineFuel.getFuelForFluid(fuel.getFluid());
currentFuel = BuildcraftFuelRegistry.fuel.getFuel(fuel.getFluid());
}
if (currentFuel == null) {
@ -167,7 +166,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
if (--fuel.amount <= 0) {
tankFuel.setFluid(null);
}
burnTime = currentFuel.totalBurningTime / FluidContainerRegistry.BUCKET_VOLUME;
burnTime = currentFuel.getTotalBurningTime() / FluidContainerRegistry.BUCKET_VOLUME;
} else {
currentFuel = null;
return;
@ -175,11 +174,11 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
}
if (!this.constantPower) {
currentOutput = currentFuel.powerPerCycle;
currentOutput = currentFuel.getPowerPerCycle();
}
addEnergy(currentFuel.powerPerCycle);
heat += currentFuel.powerPerCycle * HEAT_PER_MJ * getBiomeTempScalar();
addEnergy(currentFuel.getPowerPerCycle());
heat += currentFuel.getPowerPerCycle() * HEAT_PER_MJ * getBiomeTempScalar();
}
} else if (penaltyCooling <= 0) {
if (lastPowered) {
@ -201,7 +200,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
if (stack != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
if (liquid == null && heat > MIN_HEAT * 2) {
liquid = IronEngineCoolant.getFluidCoolant(stack);
liquid = BuildcraftFuelRegistry.coolant.getSolidCoolant(StackKey.stack(stack)).getFluidFromSolidCoolant(stack);
}
if (liquid != null) {
@ -238,7 +237,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
}
int coolantAmount = Math.min(MAX_COOLANT_PER_TICK, coolant.amount);
Coolant currentCoolant = IronEngineCoolant.getCoolant(coolant);
ICoolant currentCoolant = BuildcraftFuelRegistry.coolant.getCoolant(coolant.getFluid());
if (currentCoolant != null) {
float cooling = currentCoolant.getDegreesCoolingPerMB(heat);
cooling /= getBiomeTempScalar();
@ -364,9 +363,9 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
// Handle coolant
if (IronEngineCoolant.getCoolant(resource) != null) {
if (BuildcraftFuelRegistry.coolant.getCoolant(resource.getFluid()) != null) {
return tankCoolant.fill(resource, doFill);
} else if (IronEngineFuel.getFuelForFluid(resource.getFluid()) != null) {
} else if (BuildcraftFuelRegistry.fuel.getFuel(resource.getFluid()) != null) {
return tankFuel.fill(resource, doFill);
} else {
return 0;
@ -375,11 +374,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
if (IronEngineCoolant.isCoolant(fluid)) {
return true;
} else {
return IronEngineFuel.getFuelForFluid(fluid) != null;
}
return BuildcraftFuelRegistry.coolant.getCoolant(fluid) != null || BuildcraftFuelRegistry.fuel.getFuel(fluid) != null;
}
@Override
@ -391,10 +386,11 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
if (itemstack == null) {
return false;
} else if (IronEngineCoolant.getCoolant(itemstack) != null) {
} else if (BuildcraftFuelRegistry.coolant.getSolidCoolant(StackKey.stack(itemstack)) != null) {
return true;
} else {
return FluidContainerRegistry.getFluidForFilledItem(itemstack) != null;
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemstack);
return fluidStack != null && canFill(ForgeDirection.UNKNOWN, fluidStack.getFluid());
}
}
@ -425,8 +421,9 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public double getCurrentOutput() {
if (currentFuel == null) {
return 0;
} else {
return currentFuel.getPowerPerCycle();
}
return currentFuel.powerPerCycle;
}
@Override

View file

@ -0,0 +1,128 @@
/**
* 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
*/
package buildcraft.energy.fuels;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.core.StackKey;
import buildcraft.api.fuels.ICoolant;
import buildcraft.api.fuels.ICoolantManager;
import buildcraft.api.fuels.ISolidCoolant;
public final class CoolantManager implements ICoolantManager {
public static final CoolantManager INSTANCE = new CoolantManager();
private final List<ICoolant> coolants = new LinkedList<ICoolant>();
private final List<ISolidCoolant> solidCoolants = new LinkedList<ISolidCoolant>();
private CoolantManager() {
}
@Override
public ICoolant addCoolant(ICoolant coolant) {
coolants.add(coolant);
return coolant;
}
@Override
public ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB) {
return addCoolant(new BCCoolant(fluid, degreesCoolingPerMB));
}
@Override
public ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant) {
solidCoolants.add(solidCoolant);
return solidCoolant;
}
@Override
public ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier) {
assert solid.stack != null && solid.fluidStack == null;
assert liquid.stack == null && liquid.fluidStack != null;
return addSolidCoolant(new BCSolidCoolant(solid, liquid, multiplier));
}
@Override
public Collection<ICoolant> getCoolants() {
return coolants;
}
@Override
public Collection<ISolidCoolant> getSolidCoolants() {
return solidCoolants;
}
@Override
public ICoolant getCoolant(Fluid fluid) {
for (ICoolant coolant : coolants) {
if (coolant.getFluid() == fluid) {
return coolant;
}
}
return null;
}
@Override
public ISolidCoolant getSolidCoolant(StackKey solid) {
assert solid.stack != null && solid.fluidStack == null;
for (ISolidCoolant solidCoolant : solidCoolants) {
if (solidCoolant.getFluidFromSolidCoolant(solid.stack) != null) {
return solidCoolant;
}
}
return null;
}
private static final class BCCoolant implements ICoolant {
private final Fluid fluid;
private final float degreesCoolingPerMB;
public BCCoolant(Fluid fluid, float degreesCoolingPerMB) {
this.fluid = fluid;
this.degreesCoolingPerMB = degreesCoolingPerMB;
}
@Override
public Fluid getFluid() {
return fluid;
}
@Override
public float getDegreesCoolingPerMB(float heat) {
return degreesCoolingPerMB;
}
}
private static final class BCSolidCoolant implements ISolidCoolant {
private final StackKey solid;
private final StackKey liquid;
private final float multiplier;
public BCSolidCoolant(StackKey solid, StackKey liquid, float multiplier) {
this.solid = solid;
this.liquid = liquid;
this.multiplier = multiplier;
}
@Override
public FluidStack getFluidFromSolidCoolant(ItemStack stack) {
if (stack == null || !stack.isItemEqual(solid.stack)) {
return null;
}
int liquidAmount = (int) (stack.stackSize * liquid.fluidStack.amount * multiplier / solid.stack.stackSize);
return new FluidStack(liquid.fluidStack.fluidID, liquidAmount);
}
}
}

View file

@ -0,0 +1,80 @@
/**
* 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
*/
package buildcraft.energy.fuels;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import net.minecraftforge.fluids.Fluid;
import buildcraft.api.fuels.IFuel;
import buildcraft.api.fuels.IFuelManager;
public final class FuelManager implements IFuelManager {
public static final FuelManager INSTANCE = new FuelManager();
private final List<IFuel> fuels = new LinkedList<IFuel>();
private FuelManager() {
}
@Override
public IFuel addFuel(IFuel fuel) {
fuels.add(fuel);
return fuel;
}
@Override
public IFuel addFuel(Fluid fluid, float powerPerCycle, int totalBurningTime) {
return addFuel(new BCFuel(fluid, powerPerCycle, totalBurningTime));
}
@Override
public Collection<IFuel> getFuels() {
return fuels;
}
@Override
public IFuel getFuel(Fluid fluid) {
for (IFuel fuel : fuels) {
if (fuel.getFluid() == fluid) {
return fuel;
}
}
return null;
}
private static final class BCFuel implements IFuel {
private final Fluid fluid;
private final float powerPerCycle;
private final int totalBurningTime;
public BCFuel(Fluid fluid, float powerPerCycle, int totalBurningTime) {
this.fluid = fluid;
this.powerPerCycle = powerPerCycle;
this.totalBurningTime = totalBurningTime;
}
@Override
public Fluid getFluid() {
return fluid;
}
@Override
public int getTotalBurningTime() {
return totalBurningTime;
}
@Override
public float getPowerPerCycle() {
return powerPerCycle;
}
}
}