Clean up Iron Engine APIs

This commit is contained in:
CovertJaguar 2013-07-14 12:09:54 -07:00
parent b44d60f4fe
commit 33422087a3
5 changed files with 123 additions and 72 deletions

View file

@ -198,9 +198,9 @@ public class BuildCraftEnergy {
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(FluidRegistry.getFluid("oil"), null, FluidRegistry.getFluid("fuel"), 12, 1));
// Iron Engine Fuels
IronEngineFuel.addFuel(FluidRegistry.getFluid("lava"), 1, 20000);
IronEngineFuel.addFuel(FluidRegistry.getFluid("oil"), 3, 20000);
IronEngineFuel.addFuel(FluidRegistry.getFluid("fuel"), 6, 100000);
IronEngineFuel.addFuel("lava", 1, 20000);
IronEngineFuel.addFuel("oil", 3, 20000);
IronEngineFuel.addFuel("fuel", 6, 100000);
// Iron Engine Coolants
IronEngineCoolant.addCoolant(FluidRegistry.getFluid("water"), 0.0023F);

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

View file

@ -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;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import buildcraft.api.core.StackWrapper;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.Item;
@ -11,19 +17,19 @@ import net.minecraftforge.fluids.FluidStack;
public final class IronEngineCoolant {
public static BiMap<String, Coolant> liquidCoolants = HashBiMap.create();
public static Map<ItemData, FluidStack> solidCoolants = new HashMap<ItemData, FluidStack>();
public static Map<String, Coolant> liquidCoolants = new HashMap<String, Coolant>();
public static Map<StackWrapper, FluidStack> solidCoolants = new HashMap<StackWrapper, FluidStack>();
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) {
return getCoolant(getFluidCoolant(stack));
}
public static Coolant getCoolant(FluidStack liquid) {
return liquid != null ? liquidCoolants.get(liquid.getFluid().getName()) : null;
public static Coolant getCoolant(FluidStack fluidStack) {
return fluidStack != null ? liquidCoolants.get(fluidStack.getFluid().getName()) : null;
}
private IronEngineCoolant() {
@ -34,9 +40,9 @@ public final class IronEngineCoolant {
float getDegreesCoolingPerMB(float currentHeat);
}
public static void addCoolant(final Fluid liquid, final float degreesCoolingPerMB) {
if (liquid != null) {
liquidCoolants.put(liquid.getName(), new Coolant() {
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;
@ -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) {
if (Item.itemsList[itemId] != null && coolant != null) {
solidCoolants.put(new ItemData(itemId, metadata), coolant);
}
addCoolant(new ItemStack(itemId, 1, metadata), coolant);
}
public static class ItemData {
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.containsKey(fluid.getName());
}
public static boolean isCoolant(Fluid fluid)
{
return liquidCoolants.inverse().containsKey(fluid);
}
}

View file

@ -1,43 +1,50 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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 com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
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());
}
public final Fluid liquid;
public final float powerPerCycle;
public final int totalBurningTime;
public IronEngineFuel(String fluidName, float powerPerCycle, int totalBurningTime) {
this(FluidRegistry.getFluid(fluidName), powerPerCycle, totalBurningTime);
private IronEngineFuel() {
}
public IronEngineFuel(Fluid liquid, float powerPerCycle, int totalBurningTime) {
this.liquid = liquid;
this.powerPerCycle = powerPerCycle;
this.totalBurningTime = totalBurningTime;
fuels.put(liquid.getName(), this);
public static 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) {
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));
}
}

View file

@ -12,6 +12,7 @@ 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.gates.ITrigger;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
@ -42,7 +43,7 @@ public class TileEngineIron extends TileEngine implements IFluidHandler {
int burnTime = 0;
private FluidTank fuelTank;
private FluidTank coolantTank;
private IronEngineFuel currentFuel = null;
private Fuel currentFuel = null;
public int penaltyCooling = 0;
boolean lastPowered = false;