Use LiquidTank

Revert RefineryRecipe
This commit is contained in:
gishicrafter 2012-11-29 00:30:45 +09:00
parent df727f0bd1
commit f7b77f589c
6 changed files with 411 additions and 307 deletions

View file

@ -34,53 +34,6 @@ public class RefineryRecipe implements Comparable<RefineryRecipe> {
return null;
}
/**
* Utility method which compares to only the types of source materials.
* We consider non-null < null in order that one-ingredient recipe is checked after
* the failure of matching two-ingredient recipes which include that liquid.
*/
private static int compareLiquids(LiquidStack liquid1, LiquidStack liquid2) {
if (liquid1 == null) {
if(liquid2 == null) {
return 0;
} else {
return 1;
}
} else if(liquid2 == null) {
return -1;
} else if(liquid1.itemID != liquid2.itemID) {
return liquid1.itemID - liquid2.itemID;
} else if(liquid1.itemMeta == -1) {
// liquid which meta is -1 has lower priority.
if(liquid2.itemMeta == -1){
return 0;
}else{
return 1;
}
} else {
if(liquid2.itemMeta == -1) {
return -1;
} else {
return liquid1.itemMeta - liquid2.itemMeta;
}
}
}
private static boolean isLiquidEqual(LiquidStack ingredient, LiquidStack liquid) {
if(ingredient == null)
return liquid == null;
if(liquid == null)
return false;
// ignores meta matching if itemMeta == -1, as the same mannar as the vanilla recipes.
if(ingredient.itemMeta == -1)
return ingredient.itemID == liquid.itemID;
return ingredient.isLiquidEqual(liquid);
}
public final LiquidStack ingredient1;
public final LiquidStack ingredient2;
public final LiquidStack result;
@ -95,7 +48,15 @@ public class RefineryRecipe implements Comparable<RefineryRecipe> {
public RefineryRecipe(LiquidStack ingredient1, LiquidStack ingredient2, LiquidStack result, int energy, int delay) {
// Sort starting materials.
if(compareLiquids(ingredient1, ingredient2) > 0) {
if(ingredient1 != null && ingredient2 != null) {
if( (ingredient1.itemID > ingredient2.itemID) || (ingredient1.itemID == ingredient2.itemID && ingredient1.itemMeta > ingredient2.itemMeta) ) {
this.ingredient1 = ingredient2;
this.ingredient2 = ingredient1;
} else {
this.ingredient1 = ingredient1;
this.ingredient2 = ingredient2;
}
} else if(ingredient2 != null) {
this.ingredient1 = ingredient2;
this.ingredient2 = ingredient1;
} else {
@ -122,32 +83,53 @@ public class RefineryRecipe implements Comparable<RefineryRecipe> {
if(ingredient1 != null) {
if(ingredient2 == null)
return isLiquidEqual(ingredient1, liquid1) || isLiquidEqual(ingredient1, liquid2);
return ingredient1.isLiquidEqual(liquid1) || ingredient1.isLiquidEqual(liquid2);
else
return (isLiquidEqual(ingredient1, liquid1) && isLiquidEqual(ingredient2, liquid2))
|| (isLiquidEqual(ingredient2, liquid1) && isLiquidEqual(ingredient1, liquid2));
return (ingredient1.isLiquidEqual(liquid1) && ingredient2.isLiquidEqual(liquid2))
|| (ingredient2.isLiquidEqual(liquid1) && ingredient1.isLiquidEqual(liquid2));
} else if(ingredient2 != null)
return isLiquidEqual(ingredient2, liquid1) || isLiquidEqual(ingredient2, liquid2);
return ingredient2.isLiquidEqual(liquid1) || ingredient2.isLiquidEqual(liquid2);
else
return false;
}
// Make instance of this class sortable.
// Compares to only the types of source materials.
// We consider non-null < null in order that one-ingredient recipe is checked after
// the failure of matching two-ingredient recipes which include that liquid.
@Override
public int compareTo(RefineryRecipe other) {
int result;
if(other == null) {
return -1;
} else if (ingredient1 == null) {
if(other.ingredient1 == null) {
return 0;
} else {
return 1;
}
} else if(other.ingredient1 == null) {
return -1;
} else if(ingredient1.itemID != other.ingredient1.itemID) {
return ingredient1.itemID - other.ingredient1.itemID;
} else if(ingredient1.itemMeta != other.ingredient1.itemMeta) {
return ingredient1.itemMeta - other.ingredient1.itemMeta;
} else if(ingredient2 == null) {
if(other.ingredient2 == null) {
return 0;
} else {
return 1;
}
} else if(other.ingredient2 == null) {
return -1;
} else if(ingredient2.itemID != other.ingredient2.itemID) {
return ingredient2.itemID - other.ingredient2.itemID;
} else if(ingredient2.itemMeta != other.ingredient2.itemMeta) {
return ingredient2.itemMeta - other.ingredient2.itemMeta;
}
result = compareLiquids(ingredient1, other.ingredient1);
if(result == 0) return compareLiquids(ingredient2, other.ingredient2);
return result;
return 0;
}

View file

@ -34,15 +34,9 @@ public class EngineIron extends Engine {
private ItemStack itemInInventory;
int burnTime = 0;
int liquidQty = 0;
public int liquidId = 0;
public int liquidMeta = 0;
int coolantQty = 0;
public int coolantId = 0;
public int coolantMeta = 0;
int heat = 0;
private LiquidTank fuelTank;
private LiquidTank coolantTank;
public int penaltyCooling = 0;
@ -53,6 +47,8 @@ public class EngineIron extends Engine {
maxEnergy = 100000;
maxEnergyExtracted = 500;
fuelTank = new LiquidTank(MAX_LIQUID);
coolantTank = new LiquidTank(MAX_LIQUID);
}
@Override
@ -88,13 +84,15 @@ public class EngineIron extends Engine {
@Override
public boolean isBurning() {
return liquidQty > 0 && penaltyCooling == 0 && tile.isRedstonePowered;
LiquidStack fuel = fuelTank.getLiquid();
return fuel != null && fuel.amount > 0 && penaltyCooling == 0 && tile.isRedstonePowered;
}
@Override
public void burn() {
currentOutput = 0;
IronEngineFuel currentFuel = IronEngineFuel.getFuelForLiquid(new LiquidStack(liquidId, liquidQty, liquidMeta));
LiquidStack fuel = this.fuelTank.getLiquid();
IronEngineFuel currentFuel = IronEngineFuel.getFuelForLiquid(fuel);
if (currentFuel == null) {
return;
@ -104,11 +102,11 @@ public class EngineIron extends Engine {
lastPowered = true;
if (burnTime > 0 || liquidQty > 0) {
if (burnTime > 0 || fuel.amount > 0) {
if (burnTime > 0) {
burnTime--;
} else {
liquidQty--;
fuel.amount--;
burnTime = currentFuel.totalBurningTime / LiquidContainerRegistry.BUCKET_VOLUME;
}
@ -151,15 +149,16 @@ public class EngineIron extends Engine {
if (heat > COOLANT_THRESHOLD) {
int extraHeat = heat - COOLANT_THRESHOLD;
IronEngineCoolant currentCoolant = IronEngineCoolant.getCoolantForLiquid(new LiquidStack(coolantId, coolantQty, coolantMeta));
LiquidStack coolant = this.coolantTank.getLiquid();
IronEngineCoolant currentCoolant = IronEngineCoolant.getCoolantForLiquid(coolant);
if (currentCoolant != null)
{
if(coolantQty * currentCoolant.coolingPerUnit > extraHeat) {
coolantQty -= Math.round(extraHeat / currentCoolant.coolingPerUnit);
if(coolant.amount * currentCoolant.coolingPerUnit > extraHeat) {
coolant.amount -= Math.round(extraHeat / currentCoolant.coolingPerUnit);
heat = COOLANT_THRESHOLD;
} else {
heat -= coolantQty * currentCoolant.coolingPerUnit;
coolantQty = 0;
heat -= coolant.amount * currentCoolant.coolingPerUnit;
coolant.amount = 0;
}
}
}
@ -193,18 +192,37 @@ public class EngineIron extends Engine {
@Override
public int getScaledBurnTime(int i) {
return (int) (((float) liquidQty / (float) (MAX_LIQUID)) * i);
return this.fuelTank.getLiquid() != null ? (int) (((float) this.fuelTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
liquidId = nbttagcompound.getInteger("liquidId");
liquidQty = nbttagcompound.getInteger("liquidQty");
liquidMeta = nbttagcompound.getInteger("liquidMeta");
if(nbttagcompound.hasKey("liquidId")) {
fuelTank.setLiquid(
new LiquidStack(
nbttagcompound.getInteger("liquidId"),
nbttagcompound.getInteger("liquidQty"),
nbttagcompound.getInteger("liquidMeta")));
} else if(nbttagcompound.hasKey("fuelTank")) {
fuelTank.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("fuelTank")));
}
burnTime = nbttagcompound.getInteger("burnTime");
coolantId = nbttagcompound.getInteger("coolantId");
coolantQty = nbttagcompound.getInteger("coolantQty");
coolantMeta = nbttagcompound.getInteger("coolantMeta");
if(nbttagcompound.hasKey("coolantId")) {
coolantTank.setLiquid(
new LiquidStack(
nbttagcompound.getInteger("coolantId"),
nbttagcompound.getInteger("coolantQty"),
nbttagcompound.getInteger("coolantMeta")));
} else if(nbttagcompound.hasKey("coolantTank")) {
coolantTank.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("coolantTank")));
}
heat = nbttagcompound.getInteger("heat");
penaltyCooling = nbttagcompound.getInteger("penaltyCooling");
@ -217,13 +235,15 @@ public class EngineIron extends Engine {
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("liquidId", liquidId);
nbttagcompound.setInteger("liquidQty", liquidQty);
nbttagcompound.setInteger("liquidMeta", liquidMeta);
if(fuelTank.getLiquid() != null) {
nbttagcompound.setTag("fuelTank", fuelTank.getLiquid().writeToNBT(new NBTTagCompound()));
}
if(coolantTank.getLiquid() != null) {
nbttagcompound.setTag("coolantTank", coolantTank.getLiquid().writeToNBT(new NBTTagCompound()));
}
nbttagcompound.setInteger("burnTime", burnTime);
nbttagcompound.setInteger("coolantId", coolantId);
nbttagcompound.setInteger("coolantQty", coolantQty);
nbttagcompound.setInteger("coolantMeta", coolantMeta);
nbttagcompound.setInteger("heat", heat);
nbttagcompound.setInteger("penaltyCooling", penaltyCooling);
@ -236,7 +256,7 @@ public class EngineIron extends Engine {
}
public int getScaledCoolant(int i) {
return (int) (((float) coolantQty / (float) (MAX_LIQUID)) * i);
return coolantTank.getLiquid() != null ? (int) (((float) coolantTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
@ -267,22 +287,28 @@ public class EngineIron extends Engine {
heat = (heat & 0xff) | ((j & 0xff) << 8 );
break;
case 5:
liquidQty = j;
if(fuelTank.getLiquid() == null) fuelTank.setLiquid(new LiquidStack(0, j));
else fuelTank.getLiquid().amount = j;
break;
case 6:
liquidId = j;
if(fuelTank.getLiquid() == null) fuelTank.setLiquid(new LiquidStack(j, 0));
else fuelTank.getLiquid().itemID = j;
break;
case 7:
coolantQty = j;
if(coolantTank.getLiquid() == null) coolantTank.setLiquid(new LiquidStack(0, j));
else coolantTank.getLiquid().amount = j;
break;
case 8:
coolantId = j;
if(coolantTank.getLiquid() == null) coolantTank.setLiquid(new LiquidStack(j, 0));
else coolantTank.getLiquid().itemID = j;
break;
case 9:
liquidMeta = j;
if(fuelTank.getLiquid() == null) fuelTank.setLiquid(new LiquidStack(0, 0, j));
else fuelTank.getLiquid().itemMeta = j;
break;
case 10:
coolantMeta = j;
if(coolantTank.getLiquid() == null) coolantTank.setLiquid(new LiquidStack(0, 0, j));
else coolantTank.getLiquid().itemMeta = j;
}
}
@ -293,12 +319,12 @@ public class EngineIron extends Engine {
iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, heat & 0xff);
iCrafting.sendProgressBarUpdate(containerEngine, 4, (heat & 0xff00) >> 8);
iCrafting.sendProgressBarUpdate(containerEngine, 5, liquidQty);
iCrafting.sendProgressBarUpdate(containerEngine, 6, liquidId);
iCrafting.sendProgressBarUpdate(containerEngine, 7, coolantQty);
iCrafting.sendProgressBarUpdate(containerEngine, 8, coolantId);
iCrafting.sendProgressBarUpdate(containerEngine, 9, liquidMeta);
iCrafting.sendProgressBarUpdate(containerEngine, 10, coolantMeta);
iCrafting.sendProgressBarUpdate(containerEngine, 5, fuelTank.getLiquid() != null ? fuelTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 6, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 7, coolantTank.getLiquid() != null ? coolantTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 8, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 9, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 10, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0);
}
@Override
@ -318,63 +344,19 @@ public class EngineIron extends Engine {
if (IronEngineCoolant.getCoolantForLiquid(resource) != null)
return fillCoolant(from, resource, doFill);
int res = 0;
if (IronEngineFuel.getFuelForLiquid(resource) != null)
return fuelTank.fill(resource, doFill);
if (liquidQty > 0 && (liquidId != resource.itemID || liquidMeta != resource.itemMeta)) {
return 0;
}
if (IronEngineFuel.getFuelForLiquid(resource) == null)
return 0;
if (liquidQty + resource.amount <= MAX_LIQUID) {
if (doFill) {
liquidQty += resource.amount;
}
res = resource.amount;
} else {
res = MAX_LIQUID - liquidQty;
if (doFill) {
liquidQty = MAX_LIQUID;
}
}
liquidId = resource.itemID;
liquidMeta = resource.itemMeta;
return res;
return 0;
}
private int fillCoolant(ForgeDirection from, LiquidStack resource, boolean doFill) {
int res = 0;
if (coolantQty > 0 && (coolantId != resource.itemID || coolantMeta != resource.itemMeta))
return 0;
if (coolantQty + resource.amount <= MAX_LIQUID) {
if (doFill)
coolantQty += resource.amount;
res = resource.amount;
} else {
res = MAX_LIQUID - coolantQty;
if (doFill)
coolantQty = MAX_LIQUID;
}
coolantId = resource.itemID;
coolantMeta = resource.itemMeta;
return res;
return coolantTank.fill(resource, doFill);
}
@Override
public LiquidTank[] getLiquidSlots() {
return new LiquidTank[] { new LiquidTank(new LiquidStack(liquidId, liquidQty, liquidMeta), MAX_LIQUID),
new LiquidTank(new LiquidStack(coolantId, coolantQty, coolantMeta), MAX_LIQUID) };
return new LiquidTank[] { fuelTank, coolantTank };
}
@ -412,12 +394,27 @@ public class EngineIron extends Engine {
switch (direction)
{
case UP:
return new LiquidTank(new LiquidStack(liquidId, liquidQty, liquidMeta), MAX_LIQUID);
return fuelTank;
case DOWN:
return new LiquidTank(new LiquidStack(coolantId, coolantQty, coolantMeta), MAX_LIQUID);
return coolantTank;
default:
return null;
}
}
public int getFuelId() {
return fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0;
}
public int getFuelMeta() {
return fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0;
}
public int getCoolantId() {
return coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0;
}
public int getCoolantMeta() {
return coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0;
}
}

View file

@ -49,16 +49,18 @@ public class GuiCombustionEngine extends GuiEngine {
EngineIron engineIron = ((EngineIron) engine.engine);
if (engine.getScaledBurnTime(58) > 0)
displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engineIron.liquidId, engineIron.liquidMeta);
displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engineIron.getFuelId(), engineIron.getFuelMeta());
if (engineIron.getScaledCoolant(58) > 0)
displayGauge(j, k, 19, 122, engineIron.getScaledCoolant(58), engineIron.coolantId, engineIron.coolantMeta);
displayGauge(j, k, 19, 122, engineIron.getScaledCoolant(58), engineIron.getCoolantId(), engineIron.getCoolantMeta());
}
private void displayGauge(int j, int k, int line, int col, int squaled, int liquidId, int liquidMeta) {
int liquidImgIndex = 0;
if (liquidId < Block.blocksList.length && Block.blocksList[liquidId] != null) {
if (liquidId <= 0) {
return;
} if (liquidId < Block.blocksList.length && Block.blocksList[liquidId] != null) {
ForgeHooksClient.bindTexture(Block.blocksList[liquidId].getTextureFile(), 0);
liquidImgIndex = Block.blocksList[liquidId].blockIndexInTexture;
} else if (Item.itemsList[liquidId] != null) {

View file

@ -15,9 +15,11 @@ import java.util.TreeSet;
import buildcraft.BuildCraftCore;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.api.core.Position;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
@ -25,6 +27,7 @@ import buildcraft.api.power.PowerFramework;
import buildcraft.core.BlockIndex;
import buildcraft.core.EntityBlock;
import buildcraft.core.IMachine;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
@ -34,28 +37,24 @@ import net.minecraft.src.Block;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
public class TilePump extends TileMachine implements IMachine, IPowerReceptor, ITankContainer {
public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME;
EntityBlock tube;
private TreeMap<Integer, LinkedList<BlockIndex>> blocksToPump = new TreeMap<Integer, LinkedList<BlockIndex>>();
public @TileNetworkData
int internalLiquid;
public @TileNetworkData
LiquidTank tank;
double tubeY = Double.NaN;
public @TileNetworkData
int aimY = 0;
public @TileNetworkData
int liquidId = 0;
public @TileNetworkData
int liquidMeta = 0;
private IPowerProvider powerProvider;
public TilePump() {
powerProvider = PowerFramework.currentFramework.createPowerProvider();
powerProvider.configure(20, 1, 10, 10, 100);
tank = new LiquidTank(MAX_LIQUID);
}
// TODO, manage this by different levels (pump what's above first...)
@ -81,24 +80,22 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
return;
}
if (internalLiquid <= 0) {
if (tank.getLiquid() == null || tank.getLiquid().amount <= 0) {
BlockIndex index = getNextIndexToPump(false);
if (isPumpableLiquid(index)) {
LiquidStack liquidToPump = Utils.liquidFromBlockId(worldObj.getBlockId(index.i, index.j, index.k));
if (internalLiquid == 0 || (liquidId == liquidToPump.itemID && liquidMeta == liquidToPump.itemMeta)) {
liquidId = liquidToPump.itemID;
liquidMeta = liquidToPump.itemMeta;
if (tank.fill(liquidToPump, false) == liquidToPump.amount) {
if (powerProvider.useEnergy(10, 10, true) == 10) {
index = getNextIndexToPump(true);
if (liquidId != Block.waterStill.blockID || BuildCraftCore.consumeWaterSources) {
if (liquidToPump.itemID != Block.waterStill.blockID || BuildCraftCore.consumeWaterSources) {
worldObj.setBlockWithNotify(index.i, index.j, index.k, 0);
}
internalLiquid = internalLiquid += liquidToPump.amount;
tank.fill(liquidToPump, true);
if (CoreProxy.proxy.isSimulating(worldObj)) {
sendNetworkUpdate();
@ -126,7 +123,8 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
}
}
if (internalLiquid >= 0) {
LiquidStack liquid = tank.getLiquid();
if (liquid != null && liquid.amount >= 0) {
for (int i = 0; i < 6; ++i) {
Position p = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[i]);
p.moveForwards(1);
@ -134,9 +132,11 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
TileEntity tile = worldObj.getBlockTileEntity((int) p.x, (int) p.y, (int) p.z);
if(tile instanceof ITankContainer) {
internalLiquid -= ((ITankContainer)tile).fill(p.orientation.getOpposite(), new LiquidStack(liquidId, internalLiquid), true);
if(internalLiquid <= 0)
int moved = ((ITankContainer)tile).fill(p.orientation.getOpposite(), liquid, true);
tank.drain(moved, true);
if(liquid.amount <= 0) {
break;
}
}
}
}
@ -274,11 +274,19 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
internalLiquid = nbttagcompound.getInteger("internalLiquid");
if(nbttagcompound.hasKey("internalLiquid")) {
tank.setLiquid(
new LiquidStack(
nbttagcompound.getInteger("liquidId"),
nbttagcompound.getInteger("internalLiquid")));
} else if(nbttagcompound.hasKey("tank")) {
tank.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("tank")));
}
aimY = nbttagcompound.getInteger("aimY");
tubeY = nbttagcompound.getFloat("tubeY");
liquidId = nbttagcompound.getInteger("liquidId");
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound);
powerProvider.configure(20, 1, 10, 10, 100);
@ -291,7 +299,10 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound);
nbttagcompound.setInteger("internalLiquid", internalLiquid);
if(tank.getLiquid() != null) {
nbttagcompound.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
nbttagcompound.setInteger("aimY", aimY);
if (tube != null) {
@ -299,8 +310,6 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
} else {
nbttagcompound.setFloat("tubeY", yCoord);
}
nbttagcompound.setInteger("liquidId", liquidId);
}
@Override
@ -322,15 +331,43 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
public void doWork() {}
@Override
public void handleDescriptionPacket(PacketUpdate packet) {
super.handleDescriptionPacket(packet);
public PacketPayload getPacketPayload()
{
PacketPayload payload = new PacketPayload(4, 1, 0);
if(tank.getLiquid() != null) {
payload.intPayload[0] = tank.getLiquid().itemID;
payload.intPayload[1] = tank.getLiquid().itemMeta;
payload.intPayload[2] = tank.getLiquid().amount;
} else {
payload.intPayload[0] = 0;
payload.intPayload[1] = 0;
payload.intPayload[2] = 0;
}
payload.intPayload[3] = aimY;
payload.floatPayload[0] = (float) tubeY;
setTubePosition();
return payload;
}
@Override
public void handleDescriptionPacket(PacketUpdate packet) {
handleUpdatePacket(packet);
}
@Override
public void handleUpdatePacket(PacketUpdate packet) {
super.handleDescriptionPacket(packet);
if(packet.payload.intPayload[0] > 0) {
tank.setLiquid(
new LiquidStack(
packet.payload.intPayload[0],
packet.payload.intPayload[2],
packet.payload.intPayload[1]));
} else {
tank.setLiquid(null);
}
aimY = packet.payload.intPayload[3];
tubeY = packet.payload.floatPayload[0];
setTubePosition();
}
@ -376,4 +413,47 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
public boolean allowActions() {
return false;
}
// ITankContainer implementation.
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
// not acceptable
return 0;
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
// not acceptable
return 0;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return drain(0, maxDrain, doDrain);
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if(tankIndex == 0)
return tank.drain(maxDrain, doDrain);
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[]{ tank };
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
}

View file

@ -22,6 +22,8 @@ import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework;
import buildcraft.api.recipes.RefineryRecipe;
import buildcraft.core.IMachine;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
import net.minecraft.src.Container;
@ -38,68 +40,11 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
public static int LIQUID_PER_SLOT = LiquidContainerRegistry.BUCKET_VOLUME * 4;
public static class Slot {
@TileNetworkData
public int liquidId = 0;
@TileNetworkData
public int quantity = 0;
@TileNetworkData
public int liquidMeta = 0;
public int fill(ForgeDirection from, int amount, int id, boolean doFill) {
return fill(from, new LiquidStack(id, amount, 0), doFill);
}
public int fill(ForgeDirection from, LiquidStack liquid, boolean doFill) {
if (quantity != 0 && (liquidId != liquid.itemID || liquidMeta != liquid.itemMeta)) {
return 0;
} else if (quantity + liquid.amount <= LIQUID_PER_SLOT) {
if (doFill) {
quantity = quantity + liquid.amount;
}
liquidId = liquid.itemID;
liquidMeta = liquid.itemMeta;
return liquid.amount;
} else {
int used = LIQUID_PER_SLOT - quantity;
if (doFill) {
quantity = LIQUID_PER_SLOT;
}
liquidId = liquid.itemID;
liquidMeta = liquid.itemMeta;
return used;
}
}
public void writeFromNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("liquidId", liquidId);
nbttagcompound.setInteger("quantity", quantity);
nbttagcompound.setInteger("liquidMeta", liquidMeta);
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
liquidId = nbttagcompound.getInteger("liquidId");
if (liquidId != 0) {
quantity = nbttagcompound.getInteger("quantity");
liquidMeta = nbttagcompound.getInteger("liquidMeta");
} else {
quantity = 0;
}
}
}
@TileNetworkData
public Slot slot1 = new Slot();
@TileNetworkData
public Slot slot2 = new Slot();
@TileNetworkData
public Slot result = new Slot();
@TileNetworkData
public LiquidTank ingredient1 = new LiquidTank(LIQUID_PER_SLOT);
public LiquidTank ingredient2 = new LiquidTank(LIQUID_PER_SLOT);
public LiquidTank result = new LiquidTank(LIQUID_PER_SLOT);
public float animationSpeed = 1;
private int animationStage = 0;
@ -190,19 +135,19 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
RefineryRecipe currentRecipe = null;
currentRecipe = RefineryRecipe.findRefineryRecipe(new LiquidStack(slot1.liquidId, slot1.quantity, slot1.liquidMeta), new LiquidStack(slot2.liquidId, slot2.quantity, slot2.liquidMeta));
currentRecipe = RefineryRecipe.findRefineryRecipe(ingredient1.getLiquid(), ingredient2.getLiquid());
if (currentRecipe == null) {
decreaseAnimation();
return;
}
if (result.quantity != 0 && (result.liquidId != currentRecipe.result.itemID || result.liquidMeta != currentRecipe.result.itemMeta)) {
if (result.getLiquid() != null && result.getLiquid().amount != 0 && !result.getLiquid().isLiquidEqual(currentRecipe.result)) {
decreaseAnimation();
return;
}
if (result.quantity + currentRecipe.result.amount > LIQUID_PER_SLOT) {
if (result.fill(currentRecipe.result, false) != currentRecipe.result.amount) {
decreaseAnimation();
return;
}
@ -228,9 +173,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
if (energyUsed != 0) {
if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) {
result.liquidId = currentRecipe.result.itemID;
result.liquidMeta = currentRecipe.result.itemMeta;
result.quantity += currentRecipe.result.amount;
result.fill(currentRecipe.result, true);
}
}
}
@ -239,18 +182,19 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
if(liquid == null)
return true;
return new LiquidStack(slot1.liquidId, slot1.quantity, slot1.liquidMeta).containsLiquid(liquid) || new LiquidStack(slot2.liquidId, slot2.quantity, slot2.liquidMeta).containsLiquid(liquid);
return (ingredient1.getLiquid() != null && ingredient1.getLiquid().containsLiquid(liquid))
|| (ingredient2.getLiquid() != null && ingredient2.getLiquid().containsLiquid(liquid));
}
private boolean consumeInput(LiquidStack liquid) {
if(liquid == null)
return true;
if(new LiquidStack(slot1.liquidId, slot1.quantity, slot1.liquidMeta).containsLiquid(liquid)) {
slot1.quantity -= liquid.amount;
if(ingredient1.getLiquid() != null && ingredient1.getLiquid().containsLiquid(liquid)) {
ingredient1.drain(liquid.amount, true);
return true;
} else if(new LiquidStack(slot2.liquidId, slot2.quantity, slot2.liquidMeta).containsLiquid(liquid)) {
slot2.quantity -= liquid.amount;
} else if(ingredient2.getLiquid() != null && ingredient2.getLiquid().containsLiquid(liquid)) {
ingredient2.drain(liquid.amount, true);
return true;
}
@ -272,14 +216,49 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
return true;
}
// for compatibility
private LiquidStack readSlotNBT(NBTTagCompound nbttagcompound)
{
int liquidId = nbttagcompound.getInteger("liquidId");
int quantity = 0;
int liquidMeta = 0;
if (liquidId != 0) {
quantity = nbttagcompound.getInteger("quantity");
liquidMeta = nbttagcompound.getInteger("liquidMeta");
} else {
quantity = 0;
}
if(quantity > 0) return new LiquidStack(liquidId, quantity, liquidMeta);
return null;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("slot1")) {
slot1.readFromNBT(nbttagcompound.getCompoundTag("slot1"));
slot2.readFromNBT(nbttagcompound.getCompoundTag("slot2"));
result.readFromNBT(nbttagcompound.getCompoundTag("result"));
ingredient1.setLiquid(readSlotNBT(nbttagcompound.getCompoundTag("slot1")));
ingredient2.setLiquid(readSlotNBT(nbttagcompound.getCompoundTag("slot2")));
result.setLiquid(readSlotNBT(nbttagcompound.getCompoundTag("result")));
} else {
if(nbttagcompound.hasKey("ingredient1")) {
ingredient1.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("ingredient1")));
}
if(nbttagcompound.hasKey("ingredient2")) {
ingredient2.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("ingredient2")));
}
if(nbttagcompound.hasKey("result")) {
result.setLiquid(
LiquidStack.loadLiquidStackFromNBT(
nbttagcompound.getCompoundTag("result")));
}
}
animationStage = nbttagcompound.getInteger("animationStage");
@ -298,17 +277,23 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagCompound NBTslot1 = new NBTTagCompound();
NBTTagCompound NBTslot2 = new NBTTagCompound();
NBTTagCompound NBTresult = new NBTTagCompound();
if(ingredient1.getLiquid() != null) {
nbttagcompound.setTag("ingredient1",
ingredient1.getLiquid().writeToNBT(
new NBTTagCompound()));
}
slot1.writeFromNBT(NBTslot1);
slot2.writeFromNBT(NBTslot2);
result.writeFromNBT(NBTresult);
if(ingredient2.getLiquid() != null) {
nbttagcompound.setTag("ingredient2",
ingredient2.getLiquid().writeToNBT(
new NBTTagCompound()));
}
nbttagcompound.setTag("slot1", NBTslot1);
nbttagcompound.setTag("slot2", NBTslot2);
nbttagcompound.setTag("result", NBTresult);
if(result.getLiquid() != null) {
nbttagcompound.setTag("result",
result.getLiquid().writeToNBT(
new NBTTagCompound()));
}
nbttagcompound.setInteger("animationStage", animationStage);
nbttagcompound.setFloat("animationSpeed", animationSpeed);
@ -423,18 +408,18 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
if (filters[0] != 0 || filters[1] != 0) {
if (filters[0] == resource.itemID && filtersMeta[0] == resource.itemMeta) {
used += slot1.fill(from, resourceUsing, doFill);
used += ingredient1.fill(resourceUsing, doFill);
}
resourceUsing.amount -= used;
if (filters[1] == resource.itemID && filtersMeta[1] == resource.itemMeta) {
used += slot2.fill(from, resourceUsing, doFill);
used += ingredient2.fill(resourceUsing, doFill);
}
} else {
used += slot1.fill(from, resourceUsing, doFill);
used += ingredient1.fill(resourceUsing, doFill);
resourceUsing.amount -= used;
used += slot2.fill(from, resourceUsing, doFill);
used += ingredient2.fill(resourceUsing, doFill);
}
if (doFill && used > 0) {
@ -447,7 +432,9 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
/// FIXME: TileRefinery.Slot must die!
if(tankIndex == 0 && resource.itemID == filters[0] && resource.itemMeta == filtersMeta[0]) return ingredient1.fill(resource, doFill);
if(tankIndex == 1 && resource.itemID == filters[1] && resource.itemMeta == filtersMeta[1]) return ingredient2.fill(resource, doFill);
return 0;
}
@ -458,37 +445,14 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
@Override
public LiquidStack drain(int tankIndex, int maxEmpty, boolean doDrain) {
int res = 0;
if(tankIndex == 2) return result.drain(maxEmpty, doDrain);
if (result.quantity >= maxEmpty) {
res = maxEmpty;
if (doDrain) {
result.quantity -= maxEmpty;
}
} else {
res = result.quantity;
if (doDrain) {
result.quantity = 0;
}
}
if (doDrain && res > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return new LiquidStack(result.liquidId, res, result.liquidMeta);
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction) {
return new ILiquidTank[] {
new LiquidTank(new LiquidStack(slot1.liquidId, slot1.quantity, slot1.liquidMeta), LIQUID_PER_SLOT),
new LiquidTank(new LiquidStack(slot2.liquidId, slot2.quantity, slot2.liquidMeta), LIQUID_PER_SLOT),
new LiquidTank(new LiquidStack(result.liquidId, result.quantity, result.liquidMeta), LIQUID_PER_SLOT),
};
return new ILiquidTank[] {ingredient1, ingredient2, result};
}
@Override
@ -497,4 +461,77 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
return null;
}
// Network
@Override
public PacketPayload getPacketPayload()
{
PacketPayload payload = new PacketPayload(9, 1, 0);
if(ingredient1.getLiquid() != null) {
payload.intPayload[0] = ingredient1.getLiquid().itemID;
payload.intPayload[1] = ingredient1.getLiquid().itemMeta;
payload.intPayload[2] = ingredient1.getLiquid().amount;
} else {
payload.intPayload[0] = 0;
payload.intPayload[1] = 0;
payload.intPayload[2] = 0;
}
if(ingredient2.getLiquid() != null) {
payload.intPayload[3] = ingredient2.getLiquid().itemID;
payload.intPayload[4] = ingredient2.getLiquid().itemMeta;
payload.intPayload[5] = ingredient2.getLiquid().amount;
} else {
payload.intPayload[3] = 0;
payload.intPayload[4] = 0;
payload.intPayload[5] = 0;
}
if(result.getLiquid() != null) {
payload.intPayload[6] = result.getLiquid().itemID;
payload.intPayload[7] = result.getLiquid().itemMeta;
payload.intPayload[8] = result.getLiquid().amount;
} else {
payload.intPayload[6] = 0;
payload.intPayload[7] = 0;
payload.intPayload[8] = 0;
}
payload.floatPayload[0] = animationSpeed;
return payload;
}
@Override
public void handleUpdatePacket(PacketUpdate packet) {
if(packet.payload.intPayload[0] > 0) {
ingredient1.setLiquid(
new LiquidStack(
packet.payload.intPayload[0],
packet.payload.intPayload[2],
packet.payload.intPayload[1]));
} else {
ingredient1.setLiquid(null);
}
if(packet.payload.intPayload[3] > 0) {
ingredient2.setLiquid(
new LiquidStack(
packet.payload.intPayload[3],
packet.payload.intPayload[5],
packet.payload.intPayload[4]));
} else {
ingredient2.setLiquid(null);
}
if(packet.payload.intPayload[6] > 0) {
result.setLiquid(
new LiquidStack(
packet.payload.intPayload[6],
packet.payload.intPayload[8],
packet.payload.intPayload[7]));
} else {
result.setLiquid(null);
}
animationSpeed = packet.payload.floatPayload[0];
}
}

View file

@ -136,17 +136,23 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
ModelRenderer theMagnet = magnet[0];
if (tile != null) {
liquid1 = tile.slot1.liquidId;
liquidMeta1 = tile.slot1.liquidMeta;
qty1 = tile.slot1.quantity;
if(tile.ingredient1.getLiquid() != null) {
liquid1 = tile.ingredient1.getLiquid().itemID;
liquidMeta1 = tile.ingredient1.getLiquid().itemMeta;
qty1 = tile.ingredient1.getLiquid().amount;
}
liquid2 = tile.slot2.liquidId;
liquidMeta2 = tile.slot2.liquidMeta;
qty2 = tile.slot2.quantity;
if(tile.ingredient2.getLiquid() != null) {
liquid2 = tile.ingredient2.getLiquid().itemID;
liquidMeta2 = tile.ingredient2.getLiquid().itemMeta;
qty2 = tile.ingredient2.getLiquid().amount;
}
liquid3 = tile.result.liquidId;
liquidMeta3 = tile.result.liquidMeta;
qty3 = tile.result.quantity;
if(tile.result.getLiquid() != null) {
liquid3 = tile.result.getLiquid().itemID;
liquidMeta3 = tile.result.getLiquid().itemMeta;
qty3 = tile.result.getLiquid().amount;
}
anim = tile.getAnimationStage();