Added coolant for combustion engines to API.

This commit is contained in:
SirSengir 2012-07-20 23:43:27 +02:00
parent b318fc818e
commit 910fee26a7
5 changed files with 52 additions and 14 deletions

View file

@ -12,6 +12,7 @@ import java.util.Random;
import java.util.TreeMap;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.fuels.IronEngineCoolant;
import net.minecraft.src.buildcraft.api.fuels.IronEngineFuel;
import net.minecraft.src.buildcraft.api.gates.Trigger;
import net.minecraft.src.buildcraft.api.liquids.LiquidData;
@ -130,10 +131,14 @@ public class BuildCraftEnergy {
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(new LiquidStack(oilStill.blockID, 1, 0), null, new LiquidStack(fuel.shiftedIndex, 1, 0), 10, 1));
// Iron Engine Fuels
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 1, 20000));
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 2, 10000));
IronEngineFuel.fuels.add(new IronEngineFuel(fuel.shiftedIndex, 5, 50000));
// Iron Engine Coolants
IronEngineCoolant.coolants.add(new IronEngineCoolant(new LiquidStack(Block.waterStill, BuildCraftAPI.BUCKET_VOLUME), 1.0f));
LiquidManager.liquids.add(new LiquidData(new LiquidStack(oilStill, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(oilMoving, BuildCraftAPI.BUCKET_VOLUME), new ItemStack(bucketOil), new ItemStack(Item.bucketEmpty)));
LiquidManager.liquids.add(new LiquidData(new LiquidStack(fuel, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(fuel, BuildCraftAPI.BUCKET_VOLUME), new ItemStack(bucketFuel), new ItemStack(Item.bucketEmpty)));

View file

@ -32,9 +32,9 @@ public enum Orientations {
return Orientations.XNeg;
case XNeg:
return Orientations.XPos;
default:
return Orientations.Unknown;
}
return Orientations.Unknown;
}
public Orientations rotateLeft() {
@ -47,9 +47,9 @@ public enum Orientations {
return ZNeg;
case ZPos:
return XNeg;
default:
return this;
}
return this;
}
public static Orientations[] dirs() {

View file

@ -0,0 +1,32 @@
package net.minecraft.src.buildcraft.api.fuels;
import java.util.LinkedList;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
public class IronEngineCoolant {
public static LinkedList<IronEngineCoolant> coolants = new LinkedList<IronEngineCoolant>();
public static IronEngineCoolant getCoolantForLiquid(LiquidStack liquid) {
if(liquid == null)
return null;
if(liquid.itemID <= 0)
return null;
for(IronEngineCoolant coolant : coolants)
if(coolant.liquid.isLiquidEqual(liquid))
return coolant;
return null;
}
public final LiquidStack liquid;
public final float coolingPerUnit;
public IronEngineCoolant(LiquidStack liquid, float coolingPerUnit) {
this.liquid = liquid;
this.coolingPerUnit = coolingPerUnit;
}
}

View file

@ -22,6 +22,8 @@ public class IronEngineFuel {
public static IronEngineFuel getFuelForLiquid(LiquidStack liquid) {
if(liquid == null)
return null;
if(liquid.itemID <= 0)
return null;
for(IronEngineFuel fuel : fuels)
if(fuel.liquid.isLiquidEqual(liquid))

View file

@ -15,6 +15,7 @@ import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.fuels.IronEngineCoolant;
import net.minecraft.src.buildcraft.api.fuels.IronEngineFuel;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
@ -138,11 +139,12 @@ public class EngineIron extends Engine {
if (heat > COOLANT_THRESHOLD) {
int extraHeat = heat - COOLANT_THRESHOLD;
if (coolantQty > extraHeat) {
coolantQty -= extraHeat;
IronEngineCoolant currentCoolant = IronEngineCoolant.getCoolantForLiquid(new LiquidStack(coolantId, coolantQty, 0));
if(coolantQty * currentCoolant.coolingPerUnit > extraHeat) {
coolantQty -= Math.round(extraHeat / currentCoolant.coolingPerUnit);
heat = COOLANT_THRESHOLD;
} else {
heat -= coolantQty;
heat -= coolantQty * currentCoolant.coolingPerUnit;
coolantQty = 0;
}
}
@ -273,7 +275,7 @@ public class EngineIron extends Engine {
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
// Handle coolant
if (resource.itemID == Block.waterStill.blockID)
if (IronEngineCoolant.getCoolantForLiquid(resource) != null)
return fillCoolant(from, resource, doFill);
int res = 0;
@ -307,22 +309,19 @@ public class EngineIron extends Engine {
private int fillCoolant(Orientations from, LiquidStack resource, boolean doFill) {
int res = 0;
if (coolantQty > 0 && coolantId != resource.itemID) {
if (coolantQty > 0 && coolantId != resource.itemID)
return 0;
}
if (coolantQty + resource.amount <= MAX_LIQUID) {
if (doFill) {
if (doFill)
coolantQty += resource.amount;
}
res = resource.amount;
} else {
res = MAX_LIQUID - coolantQty;
if (doFill) {
if (doFill)
coolantQty = MAX_LIQUID;
}
}
coolantId = resource.itemID;