Converted refinery, tank and pump to use ITankContainer.

This commit is contained in:
SirSengir 2012-07-17 18:21:11 +02:00
parent 45a4c299dd
commit 305947fe66
3 changed files with 191 additions and 86 deletions

View file

@ -26,6 +26,8 @@ import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.core.BlockIndex;
import net.minecraft.src.buildcraft.core.EntityBlock;
import net.minecraft.src.buildcraft.core.IMachine;
@ -127,13 +129,15 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor {
p.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) p.x, (int) p.y, (int) p.z);
if (tile instanceof ILiquidContainer) {
internalLiquid -= ((ILiquidContainer) tile).fill(p.orientation.reverse(), internalLiquid, liquidId, true);
if (internalLiquid <= 0) {
if(tile instanceof ITankContainer) {
internalLiquid -= ((ITankContainer)tile).fill(p.orientation.reverse(), new LiquidStack(liquidId, internalLiquid), true);
if(internalLiquid <= 0)
break;
} else if (tile instanceof ILiquidContainer) {
internalLiquid -= ((ILiquidContainer) tile).fill(p.orientation.reverse(), internalLiquid, liquidId, true);
if (internalLiquid <= 0)
break;
}
}
}
}

View file

@ -26,11 +26,13 @@ import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.api.liquids.LiquidTank;
import net.minecraft.src.buildcraft.api.recipes.RefineryRecipe;
import net.minecraft.src.buildcraft.core.IMachine;
public class TileRefinery extends TileMachine implements ILiquidContainer, IPowerReceptor, IInventory, IMachine {
public class TileRefinery extends TileMachine implements ILiquidContainer, ITankContainer, IPowerReceptor, IInventory, IMachine {
private int[] filters = new int[2];
@ -107,67 +109,6 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
filters[1] = 0;
}
@Override
public int fill(Orientations from, int quantity, int id, boolean doFill) {
int used = 0;
if (filters[0] != 0 || filters[1] != 0) {
if (filters[0] == id) {
used += slot1.fill(from, quantity, id, doFill);
}
if (filters[1] == id) {
used += slot2.fill(from, quantity - used, id, doFill);
}
} else {
used += slot1.fill(from, quantity, id, doFill);
used += slot2.fill(from, quantity - used, id, doFill);
}
if (doFill && used > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return used;
}
@Override
public int empty(int quantityMax, boolean doEmpty) {
int res = 0;
if (result.quantity >= quantityMax) {
res = quantityMax;
if (doEmpty) {
result.quantity -= quantityMax;
}
} else {
res = result.quantity;
if (doEmpty) {
result.quantity = 0;
}
}
if (doEmpty && res > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return res;
}
@Override
public int getLiquidQuantity() {
return result.quantity;
}
@Override
public int getLiquidId() {
return result.liquidId;
}
@Override
public int getSizeInventory() {
return 0;
@ -412,22 +353,8 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
}
}
@Override
public void openChest() {
}
@Override
public void closeChest() {
}
@Override
public LiquidSlot[] getLiquidSlots() {
return new LiquidSlot[] { new LiquidSlot(slot1.liquidId, slot1.quantity, LIQUID_PER_SLOT),
new LiquidSlot(slot2.liquidId, slot2.quantity, LIQUID_PER_SLOT),
new LiquidSlot(result.liquidId, result.quantity, LIQUID_PER_SLOT) };
}
@Override public void openChest() {}
@Override public void closeChest() {}
public void setFilter(int number, int liquidId) {
filters[number] = liquidId;
@ -459,4 +386,146 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
iCrafting.updateCraftingInventoryInfo(container, 1, filters[1]);
}
/* ILIQUIDCONTAINER */
@Override
public int fill(Orientations from, int quantity, int id, boolean doFill) {
int used = 0;
if (filters[0] != 0 || filters[1] != 0) {
if (filters[0] == id) {
used += slot1.fill(from, quantity, id, doFill);
}
if (filters[1] == id) {
used += slot2.fill(from, quantity - used, id, doFill);
}
} else {
used += slot1.fill(from, quantity, id, doFill);
used += slot2.fill(from, quantity - used, id, doFill);
}
if (doFill && used > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return used;
}
@Override
public int empty(int quantityMax, boolean doEmpty) {
int res = 0;
if (result.quantity >= quantityMax) {
res = quantityMax;
if (doEmpty) {
result.quantity -= quantityMax;
}
} else {
res = result.quantity;
if (doEmpty) {
result.quantity = 0;
}
}
if (doEmpty && res > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return res;
}
@Override
public int getLiquidQuantity() {
return result.quantity;
}
@Override
public int getLiquidId() {
return result.liquidId;
}
@Override
public LiquidSlot[] getLiquidSlots() {
return new LiquidSlot[] { new LiquidSlot(slot1.liquidId, slot1.quantity, LIQUID_PER_SLOT),
new LiquidSlot(slot2.liquidId, slot2.quantity, LIQUID_PER_SLOT),
new LiquidSlot(result.liquidId, result.quantity, LIQUID_PER_SLOT) };
}
/* ITANKCONTAINER */
@Override
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
int used = 0;
if (filters[0] != 0 || filters[1] != 0) {
if (filters[0] == resource.itemID) {
used += slot1.fill(from, resource.amount, resource.itemID, doFill);
}
if (filters[1] == resource.itemID) {
used += slot2.fill(from, resource.amount - used, resource.itemID, doFill);
}
} else {
used += slot1.fill(from, resource.amount, resource.itemID, doFill);
used += slot2.fill(from, resource.amount - used, resource.itemID, doFill);
}
if (doFill && used > 0) {
updateNetworkTime.markTime(worldObj);
sendNetworkUpdate();
}
return used;
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
/// FIXME: TileRefinery.Slot must die!
return 0;
}
@Override
public LiquidStack drain(Orientations from, int maxEmpty, boolean doDrain) {
return drain(2, maxEmpty, doDrain);
}
@Override
public LiquidStack drain(int tankIndex, int maxEmpty, boolean doDrain) {
int res = 0;
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);
}
@Override
public LiquidTank[] getTanks() {
return new LiquidTank[] {
new LiquidTank(slot1.liquidId, slot1.quantity, LIQUID_PER_SLOT),
new LiquidTank(slot2.liquidId, slot2.quantity, LIQUID_PER_SLOT),
new LiquidTank(result.liquidId, result.quantity, LIQUID_PER_SLOT),
};
}
}

View file

@ -20,10 +20,13 @@ import net.minecraft.src.buildcraft.api.LiquidSlot;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.api.liquids.LiquidTank;
import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.TileBuildCraft;
public class TileTank extends TileBuildCraft implements ILiquidContainer {
public class TileTank extends TileBuildCraft implements ILiquidContainer, ITankContainer {
public @TileNetworkData
int stored = 0;
@ -210,6 +213,35 @@ public class TileTank extends TileBuildCraft implements ILiquidContainer {
@Override
public LiquidSlot[] getLiquidSlots() {
LiquidTank tank = getTanks()[0];
return new LiquidSlot[] { new LiquidSlot(tank.getLiquid().itemID, tank.getLiquid().amount, tank.getCapacity()) };
}
/* ITANKCONTAINER */
@Override
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
return getBottomTank().actualFill(from, resource.amount, resource.itemID, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
return getBottomTank().actualFill(Orientations.YPos, resource.amount, resource.itemID, doFill);
}
@Override
public LiquidStack drain(Orientations from, int maxEmpty, boolean doDrain) {
int drained = getBottomTank().actualEmtpy(maxEmpty, doDrain);
return new LiquidStack(liquidId, drained);
}
@Override
public LiquidStack drain(int tankIndex, int maxEmpty, boolean doDrain) {
int drained = getBottomTank().actualEmtpy(maxEmpty, doDrain);
return new LiquidStack(liquidId, drained);
}
@Override
public LiquidTank[] getTanks() {
int resultLiquidId = 0;
int resultLiquidQty = 0;
int resultCapacity = 0;
@ -251,7 +283,7 @@ public class TileTank extends TileBuildCraft implements ILiquidContainer {
resultCapacity += tank.getTankCapacity();
}
return new LiquidSlot[] { new LiquidSlot(resultLiquidId, resultLiquidQty, resultCapacity) };
return new LiquidTank[] { new LiquidTank(resultLiquidId, resultLiquidQty, resultCapacity) };
}
}