From ae184f76b2bb146f23c5c87218c7100e7b577c69 Mon Sep 17 00:00:00 2001 From: Prototik Date: Fri, 29 Aug 2014 17:57:10 +0800 Subject: [PATCH] Rewrite fuel/coolant api for iron engine Add lava as fuel source --- api/buildcraft/api/core/StackKey.java | 122 +++++++++++++---- .../api/fuels/BuildcraftFuelRegistry.java | 17 +++ api/buildcraft/api/fuels/ICoolant.java | 17 +++ api/buildcraft/api/fuels/ICoolantManager.java | 33 +++++ api/buildcraft/api/fuels/IFuel.java | 19 +++ api/buildcraft/api/fuels/IFuelManager.java | 23 ++++ api/buildcraft/api/fuels/ISolidCoolant.java | 16 +++ .../api/fuels/IronEngineCoolant.java | 92 ------------- api/buildcraft/api/fuels/IronEngineFuel.java | 52 ------- api/buildcraft/api/fuels/package-info.java | 2 +- common/buildcraft/BuildCraftCore.java | 6 + common/buildcraft/BuildCraftEnergy.java | 17 ++- common/buildcraft/energy/TileEngineIron.java | 60 ++++---- .../energy/fuels/CoolantManager.java | 128 ++++++++++++++++++ .../buildcraft/energy/fuels/FuelManager.java | 80 +++++++++++ 15 files changed, 470 insertions(+), 214 deletions(-) create mode 100644 api/buildcraft/api/fuels/BuildcraftFuelRegistry.java create mode 100644 api/buildcraft/api/fuels/ICoolant.java create mode 100644 api/buildcraft/api/fuels/ICoolantManager.java create mode 100644 api/buildcraft/api/fuels/IFuel.java create mode 100644 api/buildcraft/api/fuels/IFuelManager.java create mode 100644 api/buildcraft/api/fuels/ISolidCoolant.java delete mode 100644 api/buildcraft/api/fuels/IronEngineCoolant.java delete mode 100644 api/buildcraft/api/fuels/IronEngineFuel.java create mode 100644 common/buildcraft/energy/fuels/CoolantManager.java create mode 100644 common/buildcraft/energy/fuels/FuelManager.java diff --git a/api/buildcraft/api/core/StackKey.java b/api/buildcraft/api/core/StackKey.java index c3cf4fd6..df8515b4 100644 --- a/api/buildcraft/api/core/StackKey.java +++ b/api/buildcraft/api/core/StackKey.java @@ -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); } } diff --git a/api/buildcraft/api/fuels/BuildcraftFuelRegistry.java b/api/buildcraft/api/fuels/BuildcraftFuelRegistry.java new file mode 100644 index 00000000..eda676eb --- /dev/null +++ b/api/buildcraft/api/fuels/BuildcraftFuelRegistry.java @@ -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() { + } +} diff --git a/api/buildcraft/api/fuels/ICoolant.java b/api/buildcraft/api/fuels/ICoolant.java new file mode 100644 index 00000000..fd0e6d4d --- /dev/null +++ b/api/buildcraft/api/fuels/ICoolant.java @@ -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); +} diff --git a/api/buildcraft/api/fuels/ICoolantManager.java b/api/buildcraft/api/fuels/ICoolantManager.java new file mode 100644 index 00000000..6e29c15c --- /dev/null +++ b/api/buildcraft/api/fuels/ICoolantManager.java @@ -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 getCoolants(); + + Collection getSolidCoolants(); + + ICoolant getCoolant(Fluid fluid); + + ISolidCoolant getSolidCoolant(StackKey solid); +} diff --git a/api/buildcraft/api/fuels/IFuel.java b/api/buildcraft/api/fuels/IFuel.java new file mode 100644 index 00000000..368e3097 --- /dev/null +++ b/api/buildcraft/api/fuels/IFuel.java @@ -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(); +} diff --git a/api/buildcraft/api/fuels/IFuelManager.java b/api/buildcraft/api/fuels/IFuelManager.java new file mode 100644 index 00000000..d64bf41e --- /dev/null +++ b/api/buildcraft/api/fuels/IFuelManager.java @@ -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 getFuels(); + + IFuel getFuel(Fluid fluid); +} diff --git a/api/buildcraft/api/fuels/ISolidCoolant.java b/api/buildcraft/api/fuels/ISolidCoolant.java new file mode 100644 index 00000000..69e4871e --- /dev/null +++ b/api/buildcraft/api/fuels/ISolidCoolant.java @@ -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); +} diff --git a/api/buildcraft/api/fuels/IronEngineCoolant.java b/api/buildcraft/api/fuels/IronEngineCoolant.java deleted file mode 100644 index 78cf315b..00000000 --- a/api/buildcraft/api/fuels/IronEngineCoolant.java +++ /dev/null @@ -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 liquidCoolants = new HashMap(); - public static Map solidCoolants = new HashMap(); - - 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()); - } -} diff --git a/api/buildcraft/api/fuels/IronEngineFuel.java b/api/buildcraft/api/fuels/IronEngineFuel.java deleted file mode 100644 index 68b6653c..00000000 --- a/api/buildcraft/api/fuels/IronEngineFuel.java +++ /dev/null @@ -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 fuels = new HashMap(); - - 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)); - } -} diff --git a/api/buildcraft/api/fuels/package-info.java b/api/buildcraft/api/fuels/package-info.java index 67ca22bc..fe46ec34 100644 --- a/api/buildcraft/api/fuels/package-info.java +++ b/api/buildcraft/api/fuels/package-info.java @@ -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; diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 4d7dad8d..4e058672 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -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(); diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 616f07d6..2c240a15 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -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; @@ -162,6 +162,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(); @@ -276,14 +277,12 @@ public class BuildCraftEnergy extends BuildCraftMod { BuildcraftRecipeRegistry.refinery.addRecipe("buildcraft:fuel", new FluidStack(fluidOil, 1), new FluidStack( fluidFuel, 1), 12, 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 diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index 224f306a..399218b1 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -27,10 +27,10 @@ import net.minecraftforge.fluids.IFluidHandler; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftEnergy; import buildcraft.api.core.NetworkData; -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.api.mj.IOMode; import buildcraft.api.mj.MjBattery; @@ -54,7 +54,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan private int burnTime = 0; private TankManager tankManager = new TankManager(); - private Fuel currentFuel = null; + private IFuel currentFuel; private int penaltyCooling = 0; private boolean lastPowered = false; private BiomeGenBase biomeCache; @@ -81,20 +81,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; } } } @@ -154,7 +152,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) { @@ -174,14 +172,15 @@ 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; } } - addEnergy(currentFuel.powerPerCycle); - heat += currentFuel.powerPerCycle * HEAT_PER_MJ * getBiomeTempScalar(); + final float powerPerCycle = currentFuel.getPowerPerCycle(); + addEnergy(powerPerCycle); + heat += powerPerCycle * HEAT_PER_MJ * getBiomeTempScalar(); } } else if (penaltyCooling <= 0) { if (lastPowered) { @@ -203,7 +202,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) { @@ -240,7 +239,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(); @@ -369,9 +368,9 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } // 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; @@ -380,11 +379,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 @@ -396,10 +391,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()); } } diff --git a/common/buildcraft/energy/fuels/CoolantManager.java b/common/buildcraft/energy/fuels/CoolantManager.java new file mode 100644 index 00000000..e88a6d9c --- /dev/null +++ b/common/buildcraft/energy/fuels/CoolantManager.java @@ -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 coolants = new LinkedList(); + private final List solidCoolants = new LinkedList(); + + 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 getCoolants() { + return coolants; + } + + @Override + public Collection 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); + } + } +} diff --git a/common/buildcraft/energy/fuels/FuelManager.java b/common/buildcraft/energy/fuels/FuelManager.java new file mode 100644 index 00000000..35bdcd01 --- /dev/null +++ b/common/buildcraft/energy/fuels/FuelManager.java @@ -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 fuels = new LinkedList(); + + 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 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; + } + } +}