Fixed incorrect bucket registrations, liquid container handling. Closes #105

This commit is contained in:
SirSengir 2012-07-15 22:23:40 +02:00
parent 8b8471fca2
commit 45a4449c1c
4 changed files with 29 additions and 15 deletions

View file

@ -14,9 +14,11 @@ import java.util.TreeMap;
import net.minecraft.src.buildcraft.api.Action;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.LiquidData;
import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.Trigger;
import net.minecraft.src.buildcraft.api.liquids.LiquidData;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.core.ActionMachineControl;
import net.minecraft.src.buildcraft.core.ActionMachineControl.Mode;
import net.minecraft.src.buildcraft.core.ActionRedstoneOutput;
@ -208,8 +210,8 @@ public class BuildCraftCore {
wrenchItem = (new ItemWrench(Integer.parseInt(wrenchId.value))).setIconIndex(0 * 16 + 2).setItemName("wrenchItem");
CoreProxy.addName(wrenchItem, "Wrench");
BuildCraftAPI.liquids.add(new LiquidData(Block.waterStill.blockID, Block.waterMoving.blockID, Item.bucketWater));
BuildCraftAPI.liquids.add(new LiquidData(Block.lavaStill.blockID, Block.lavaMoving.blockID, Item.bucketLava));
LiquidManager.liquids.add(new LiquidData(new LiquidStack(Block.waterStill, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(Block.waterMoving, BuildCraftAPI.BUCKET_VOLUME), new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
LiquidManager.liquids.add(new LiquidData(new LiquidStack(Block.lavaStill, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(Block.lavaMoving, BuildCraftAPI.BUCKET_VOLUME), new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
BuildCraftAPI.softBlocks[Block.tallGrass.blockID] = true;
BuildCraftAPI.softBlocks[Block.snow.blockID] = true;

View file

@ -134,8 +134,8 @@ public class BuildCraftEnergy {
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 2, 10000));
IronEngineFuel.fuels.add(new IronEngineFuel(fuel.shiftedIndex, 5, 50000));
LiquidManager.liquids.add(new LiquidData(oilStill.blockID, oilMoving.blockID, bucketOil));
LiquidManager.liquids.add(new LiquidData(fuel.shiftedIndex, 0, bucketFuel));
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)));
BuildCraftAPI.softBlocks[oilMoving.blockID] = true;
BuildCraftAPI.softBlocks[oilStill.blockID] = true;

View file

@ -36,13 +36,14 @@ public class LiquidManager {
return null;
}
public static ItemStack fillLiquidContainer(int liquidId, ItemStack emptyContainer) {
return fillLiquidContainer(new LiquidStack(liquidId, 1, 0), emptyContainer);
public static ItemStack fillLiquidContainer(int liquidId, int quantity, ItemStack emptyContainer) {
return fillLiquidContainer(new LiquidStack(liquidId, quantity, 0), emptyContainer);
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
for(LiquidData data : liquids)
if(data.stillLiquid.isLiquidEqual(liquid) && data.container.isItemEqual(emptyContainer))
if(liquid.containsLiquid(data.stillLiquid)
&& data.container.isItemEqual(emptyContainer))
return data.filled.copy();
return null;
}

View file

@ -97,6 +97,7 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k);
// Handle filled containers
if (liquid != null) {
int qty = tank.fill(Orientations.Unknown, liquid.amount, liquid.itemID, true);
@ -106,18 +107,28 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
}
return true;
} else {
ItemStack filled = LiquidManager.fillLiquidContainer(tank.getLiquidId(), current);
int qty = tank.empty(BuildCraftAPI.BUCKET_VOLUME, false);
// Handle empty containers
} else {
ItemStack filled = LiquidManager.fillLiquidContainer(new LiquidStack(tank.getLiquidId(),
tank.empty(BuildCraftAPI.BUCKET_VOLUME, false)), current);
liquid = LiquidManager.getLiquidForFilledItem(filled);
if(liquid != null && qty >= liquid.amount){
if(current.stackSize > 1 && !entityplayer.inventory.addItemStackToInventory(filled)){
return false;
if(liquid != null) {
if(current.stackSize > 1) {
if(!entityplayer.inventory.addItemStackToInventory(filled))
return false;
else
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(current));
} else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
}
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(current));
tank.empty(liquid.amount, true);
return true;
}