Added filling of generic containers to Tank

This commit is contained in:
CovertJaguar 2012-07-11 03:37:24 -07:00
parent 685310fd79
commit 785c51660f
3 changed files with 20 additions and 48 deletions

View file

@ -24,7 +24,6 @@ import net.minecraft.src.buildcraft.factory.BptBlockFrame;
import net.minecraft.src.buildcraft.factory.BptBlockRefinery; import net.minecraft.src.buildcraft.factory.BptBlockRefinery;
import net.minecraft.src.buildcraft.factory.BptBlockTank; import net.minecraft.src.buildcraft.factory.BptBlockTank;
import net.minecraft.src.buildcraft.factory.GuiHandler; import net.minecraft.src.buildcraft.factory.GuiHandler;
import net.minecraft.src.buildcraft.factory.TankBucketHandler;
import net.minecraft.src.buildcraft.factory.TileAssemblyTable; import net.minecraft.src.buildcraft.factory.TileAssemblyTable;
import net.minecraft.src.buildcraft.factory.TileAutoWorkbench; import net.minecraft.src.buildcraft.factory.TileAutoWorkbench;
import net.minecraft.src.buildcraft.factory.TileHopper; import net.minecraft.src.buildcraft.factory.TileHopper;
@ -99,8 +98,6 @@ public class BuildCraftFactory {
BuildCraftCore.mainConfiguration.save(); BuildCraftCore.mainConfiguration.save();
MinecraftForge.registerCustomBucketHandler(new TankBucketHandler());
miningWellBlock = new BlockMiningWell(Integer.parseInt(minigWellId.value)); miningWellBlock = new BlockMiningWell(Integer.parseInt(minigWellId.value));
CoreProxy.registerBlock(miningWellBlock.setBlockName("miningWellBlock")); CoreProxy.registerBlock(miningWellBlock.setBlockName("miningWellBlock"));
CoreProxy.addName(miningWellBlock, "Mining Well"); CoreProxy.addName(miningWellBlock, "Mining Well");

View file

@ -20,6 +20,7 @@ import net.minecraft.src.Material;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.World; import net.minecraft.src.World;
import net.minecraft.src.buildcraft.api.BuildCraftAPI; import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.Orientations; import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.core.DefaultProps; import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.Utils; import net.minecraft.src.buildcraft.core.Utils;
@ -88,8 +89,10 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
@Override @Override
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) { public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {
if (entityplayer.getCurrentEquippedItem() != null) { ItemStack current = entityplayer.inventory.getCurrentItem();
int liquidId = BuildCraftAPI.getLiquidForFilledItem(entityplayer.getCurrentEquippedItem()); if (current != null) {
int liquidId = LiquidManager.getLiquidForFilledItem(current);
TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k); TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k);
@ -98,10 +101,24 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
if (qty != 0 && !BuildCraftCore.debugMode) { if (qty != 0 && !BuildCraftCore.debugMode) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(entityplayer.inventory.getCurrentItem())); Utils.consumeItem(current));
} }
return true; return true;
} else {
ItemStack filled = LiquidManager.fillLiquidContainer(tank.getLiquidId(), current);
int qty = tank.empty(BuildCraftAPI.BUCKET_VOLUME, false);
if(filled != null && qty >= BuildCraftAPI.BUCKET_VOLUME){
if(current.stacksize > 1 && !entityplayer.inventory.addItemStackToInventory(filled)){
return false;
}
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
Utils.consumeItem(current));
tank.empty(BuildCraftAPI.BUCKET_VOLUME, true);
return true;
}
} }
} }

View file

@ -1,42 +0,0 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package net.minecraft.src.buildcraft.factory;
import net.minecraft.src.BuildCraftFactory;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.forge.IBucketHandler;
public class TankBucketHandler implements IBucketHandler {
@Override
public ItemStack fillCustomBucket(World w, int i, int j, int k) {
if (w.getBlockId(i, j, k) == BuildCraftFactory.tankBlock.blockID) {
TileTank tank = (TileTank) w.getBlockTileEntity(i, j, k);
int qty = tank.empty(BuildCraftAPI.BUCKET_VOLUME, false);
ItemStack filledBucket = LiquidManager.fillLiquidContainer(tank.getLiquidId(), new ItemStack(Item.bucketEmpty));
if (qty >= BuildCraftAPI.BUCKET_VOLUME && filledBucket != null) {
tank.empty(BuildCraftAPI.BUCKET_VOLUME, true);
return filledBucket;
}
}
return null;
}
}