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 java.util.TreeMap;
import net.minecraft.src.buildcraft.api.BuildCraftAPI; 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.fuels.IronEngineFuel;
import net.minecraft.src.buildcraft.api.gates.Trigger; import net.minecraft.src.buildcraft.api.gates.Trigger;
import net.minecraft.src.buildcraft.api.liquids.LiquidData; 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)); 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, 1, 20000));
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 2, 10000)); IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 2, 10000));
IronEngineFuel.fuels.add(new IronEngineFuel(fuel.shiftedIndex, 5, 50000)); 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(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))); 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,10 +32,10 @@ public enum Orientations {
return Orientations.XNeg; return Orientations.XNeg;
case XNeg: case XNeg:
return Orientations.XPos; return Orientations.XPos;
} default:
return Orientations.Unknown; return Orientations.Unknown;
} }
}
public Orientations rotateLeft() { public Orientations rotateLeft() {
switch (this) { switch (this) {
@ -47,10 +47,10 @@ public enum Orientations {
return ZNeg; return ZNeg;
case ZPos: case ZPos:
return XNeg; return XNeg;
} default:
return this; return this;
} }
}
public static Orientations[] dirs() { public static Orientations[] dirs() {
return new Orientations[] { YNeg, YPos, ZNeg, ZPos, XNeg, XPos }; return new Orientations[] { YNeg, YPos, ZNeg, ZPos, XNeg, XPos };

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