Clean up Iron Engine APIs
This commit is contained in:
parent
b44d60f4fe
commit
33422087a3
5 changed files with 123 additions and 72 deletions
|
@ -198,9 +198,9 @@ public class BuildCraftEnergy {
|
||||||
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(FluidRegistry.getFluid("oil"), null, FluidRegistry.getFluid("fuel"), 12, 1));
|
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(FluidRegistry.getFluid("oil"), null, FluidRegistry.getFluid("fuel"), 12, 1));
|
||||||
|
|
||||||
// Iron Engine Fuels
|
// Iron Engine Fuels
|
||||||
IronEngineFuel.addFuel(FluidRegistry.getFluid("lava"), 1, 20000);
|
IronEngineFuel.addFuel("lava", 1, 20000);
|
||||||
IronEngineFuel.addFuel(FluidRegistry.getFluid("oil"), 3, 20000);
|
IronEngineFuel.addFuel("oil", 3, 20000);
|
||||||
IronEngineFuel.addFuel(FluidRegistry.getFluid("fuel"), 6, 100000);
|
IronEngineFuel.addFuel("fuel", 6, 100000);
|
||||||
|
|
||||||
// Iron Engine Coolants
|
// Iron Engine Coolants
|
||||||
IronEngineCoolant.addCoolant(FluidRegistry.getFluid("water"), 0.0023F);
|
IronEngineCoolant.addCoolant(FluidRegistry.getFluid("water"), 0.0023F);
|
||||||
|
|
50
common/buildcraft/api/core/StackWrapper.java
Normal file
50
common/buildcraft/api/core/StackWrapper.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) SpaceToad, 2011-2012
|
||||||
|
* 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.core;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author CovertJaguar <http://www.railcraft.info/>
|
||||||
|
*/
|
||||||
|
public class StackWrapper {
|
||||||
|
|
||||||
|
public final ItemStack stack;
|
||||||
|
|
||||||
|
public StackWrapper(ItemStack stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 5;
|
||||||
|
hash = 67 * hash + stack.itemID;
|
||||||
|
hash = 67 * hash + stack.getItemDamage();
|
||||||
|
if (stack.stackTagCompound != null)
|
||||||
|
hash = 67 * hash + stack.stackTagCompound.hashCode();
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
final StackWrapper other = (StackWrapper) obj;
|
||||||
|
if (stack.itemID != other.stack.itemID)
|
||||||
|
return false;
|
||||||
|
if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage())
|
||||||
|
return false;
|
||||||
|
if (stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,13 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) SpaceToad, 2011 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;
|
package buildcraft.api.fuels;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import buildcraft.api.core.StackWrapper;
|
||||||
import com.google.common.collect.HashBiMap;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -11,19 +17,19 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public final class IronEngineCoolant {
|
public final class IronEngineCoolant {
|
||||||
|
|
||||||
public static BiMap<String, Coolant> liquidCoolants = HashBiMap.create();
|
public static Map<String, Coolant> liquidCoolants = new HashMap<String, Coolant>();
|
||||||
public static Map<ItemData, FluidStack> solidCoolants = new HashMap<ItemData, FluidStack>();
|
public static Map<StackWrapper, FluidStack> solidCoolants = new HashMap<StackWrapper, FluidStack>();
|
||||||
|
|
||||||
public static FluidStack getFluidCoolant(ItemStack stack) {
|
public static FluidStack getFluidCoolant(ItemStack stack) {
|
||||||
return solidCoolants.get(new ItemData(stack.itemID, stack.getItemDamage()));
|
return solidCoolants.get(new StackWrapper(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Coolant getCoolant(ItemStack stack) {
|
public static Coolant getCoolant(ItemStack stack) {
|
||||||
return getCoolant(getFluidCoolant(stack));
|
return getCoolant(getFluidCoolant(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Coolant getCoolant(FluidStack liquid) {
|
public static Coolant getCoolant(FluidStack fluidStack) {
|
||||||
return liquid != null ? liquidCoolants.get(liquid.getFluid().getName()) : null;
|
return fluidStack != null ? liquidCoolants.get(fluidStack.getFluid().getName()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IronEngineCoolant() {
|
private IronEngineCoolant() {
|
||||||
|
@ -34,9 +40,9 @@ public final class IronEngineCoolant {
|
||||||
float getDegreesCoolingPerMB(float currentHeat);
|
float getDegreesCoolingPerMB(float currentHeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addCoolant(final Fluid liquid, final float degreesCoolingPerMB) {
|
public static void addCoolant(final Fluid fluid, final float degreesCoolingPerMB) {
|
||||||
if (liquid != null) {
|
if (fluid != null) {
|
||||||
liquidCoolants.put(liquid.getName(), new Coolant() {
|
liquidCoolants.put(fluid.getName(), new Coolant() {
|
||||||
@Override
|
@Override
|
||||||
public float getDegreesCoolingPerMB(float currentHeat) {
|
public float getDegreesCoolingPerMB(float currentHeat) {
|
||||||
return degreesCoolingPerMB;
|
return degreesCoolingPerMB;
|
||||||
|
@ -45,46 +51,33 @@ public final class IronEngineCoolant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 && Item.itemsList[stack.itemID] != null && coolant != null) {
|
||||||
|
solidCoolants.put(new StackWrapper(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 stack
|
||||||
|
* @param coolant
|
||||||
|
*/
|
||||||
public static void addCoolant(final int itemId, final int metadata, final FluidStack coolant) {
|
public static void addCoolant(final int itemId, final int metadata, final FluidStack coolant) {
|
||||||
if (Item.itemsList[itemId] != null && coolant != null) {
|
addCoolant(new ItemStack(itemId, 1, metadata), coolant);
|
||||||
solidCoolants.put(new ItemData(itemId, metadata), coolant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ItemData {
|
public static boolean isCoolant(Fluid fluid) {
|
||||||
|
return liquidCoolants.containsKey(fluid.getName());
|
||||||
public final int itemId, meta;
|
|
||||||
|
|
||||||
public ItemData(int itemId, int meta) {
|
|
||||||
this.itemId = itemId;
|
|
||||||
this.meta = meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = 5;
|
|
||||||
hash = 67 * hash + this.itemId;
|
|
||||||
hash = 67 * hash + this.meta;
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
final ItemData other = (ItemData) obj;
|
|
||||||
if (this.itemId != other.itemId)
|
|
||||||
return false;
|
|
||||||
if (this.meta != other.meta)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCoolant(Fluid fluid)
|
|
||||||
{
|
|
||||||
return liquidCoolants.inverse().containsKey(fluid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,50 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) SpaceToad, 2011
|
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||||
* http://www.mod-buildcraft.com
|
|
||||||
*
|
*
|
||||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
* 1.0, or MMPL. Please check the contents of the license located in
|
||||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package buildcraft.api.fuels;
|
package buildcraft.api.fuels;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
|
||||||
public class IronEngineFuel {
|
public class IronEngineFuel {
|
||||||
|
|
||||||
public static Map<String, IronEngineFuel> fuels = Maps.newHashMap();
|
public static Map<String, Fuel> fuels = new HashMap<String, Fuel>();
|
||||||
|
|
||||||
public static IronEngineFuel getFuelForFluid(Fluid liquid) {
|
public static Fuel getFuelForFluid(Fluid liquid) {
|
||||||
return liquid == null ? null : fuels.get(liquid.getName());
|
return liquid == null ? null : fuels.get(liquid.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Fluid liquid;
|
private IronEngineFuel() {
|
||||||
public final float powerPerCycle;
|
|
||||||
public final int totalBurningTime;
|
|
||||||
|
|
||||||
public IronEngineFuel(String fluidName, float powerPerCycle, int totalBurningTime) {
|
|
||||||
this(FluidRegistry.getFluid(fluidName), powerPerCycle, totalBurningTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IronEngineFuel(Fluid liquid, float powerPerCycle, int totalBurningTime) {
|
public static class Fuel {
|
||||||
this.liquid = liquid;
|
|
||||||
this.powerPerCycle = powerPerCycle;
|
public final Fluid liquid;
|
||||||
this.totalBurningTime = totalBurningTime;
|
public final float powerPerCycle;
|
||||||
fuels.put(liquid.getName(), this);
|
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) {
|
public static void addFuel(Fluid fluid, float powerPerCycle, int totalBurningTime) {
|
||||||
new IronEngineFuel(fluid, powerPerCycle, 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import buildcraft.BuildCraftEnergy;
|
||||||
import buildcraft.api.fuels.IronEngineCoolant;
|
import buildcraft.api.fuels.IronEngineCoolant;
|
||||||
import buildcraft.api.fuels.IronEngineCoolant.Coolant;
|
import buildcraft.api.fuels.IronEngineCoolant.Coolant;
|
||||||
import buildcraft.api.fuels.IronEngineFuel;
|
import buildcraft.api.fuels.IronEngineFuel;
|
||||||
|
import buildcraft.api.fuels.IronEngineFuel.Fuel;
|
||||||
import buildcraft.api.gates.ITrigger;
|
import buildcraft.api.gates.ITrigger;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.GuiIds;
|
import buildcraft.core.GuiIds;
|
||||||
|
@ -42,7 +43,7 @@ public class TileEngineIron extends TileEngine implements IFluidHandler {
|
||||||
int burnTime = 0;
|
int burnTime = 0;
|
||||||
private FluidTank fuelTank;
|
private FluidTank fuelTank;
|
||||||
private FluidTank coolantTank;
|
private FluidTank coolantTank;
|
||||||
private IronEngineFuel currentFuel = null;
|
private Fuel currentFuel = null;
|
||||||
public int penaltyCooling = 0;
|
public int penaltyCooling = 0;
|
||||||
boolean lastPowered = false;
|
boolean lastPowered = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue