Fixed fluid containers emptying giving you back nothing

Closes #401
This commit is contained in:
Ellpeck 2016-11-23 17:16:43 +01:00
parent e745ebdc28
commit ded8ceb529
6 changed files with 20 additions and 11 deletions

View file

@ -56,7 +56,7 @@ public class BlockCanolaPress extends BlockContainerBase{
if(!world.isRemote){ if(!world.isRemote){
TileEntityCanolaPress press = (TileEntityCanolaPress)world.getTileEntity(pos); TileEntityCanolaPress press = (TileEntityCanolaPress)world.getTileEntity(pos);
if(press != null){ if(press != null){
if(this.checkFailUseItemOnTank(player, player.getHeldItem(hand), press.tank)){ if(!this.tryUseItemOnTank(player, hand, press.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.CANOLA_PRESS.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.CANOLA_PRESS.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }

View file

@ -67,7 +67,7 @@ public class BlockCoffeeMachine extends BlockContainerBase{
if(!world.isRemote){ if(!world.isRemote){
TileEntityCoffeeMachine machine = (TileEntityCoffeeMachine)world.getTileEntity(pos); TileEntityCoffeeMachine machine = (TileEntityCoffeeMachine)world.getTileEntity(pos);
if(machine != null){ if(machine != null){
if(this.checkFailUseItemOnTank(player, player.getHeldItem(hand), machine.tank)){ if(!this.tryUseItemOnTank(player, hand, machine.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.COFFEE_MACHINE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.COFFEE_MACHINE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }

View file

@ -59,11 +59,10 @@ public class BlockFermentingBarrel extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
ItemStack heldItem = player.getHeldItem(hand);
if(!world.isRemote){ if(!world.isRemote){
TileEntityFermentingBarrel press = (TileEntityFermentingBarrel)world.getTileEntity(pos); TileEntityFermentingBarrel press = (TileEntityFermentingBarrel)world.getTileEntity(pos);
if(press != null){ if(press != null){
if(this.checkFailUseItemOnTank(player, heldItem, press.canolaTank) && this.checkFailUseItemOnTank(player, heldItem, press.oilTank)){ if(!this.tryUseItemOnTank(player, hand, press.canolaTank) && !this.tryUseItemOnTank(player, hand, press.oilTank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FERMENTING_BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FERMENTING_BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }

View file

@ -56,14 +56,13 @@ public class BlockFluidCollector extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
ItemStack stack = player.getHeldItem(hand);
if(this.tryToggleRedstone(world, pos, player)){ if(this.tryToggleRedstone(world, pos, player)){
return true; return true;
} }
if(!world.isRemote){ if(!world.isRemote){
TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(pos); TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(pos);
if(collector != null){ if(collector != null){
if(this.checkFailUseItemOnTank(player, stack, collector.tank)){ if(!this.tryUseItemOnTank(player, hand, collector.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FLUID_COLLECTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FLUID_COLLECTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }

View file

@ -77,12 +77,11 @@ public class BlockOilGenerator extends BlockContainerBase{
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ItemStack stack = player.getHeldItem(hand);
ItemStack stack = player.getHeldItem(hand);
if(!world.isRemote){ if(!world.isRemote){
TileEntityOilGenerator generator = (TileEntityOilGenerator)world.getTileEntity(pos); TileEntityOilGenerator generator = (TileEntityOilGenerator)world.getTileEntity(pos);
if(generator != null){ if(generator != null){
if(this.checkFailUseItemOnTank(player, stack, generator.tank)){ if(!this.tryUseItemOnTank(player, hand, generator.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.OIL_GENERATOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.OIL_GENERATOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }

View file

@ -34,6 +34,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -191,8 +193,18 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
} }
protected boolean checkFailUseItemOnTank(EntityPlayer player, ItemStack heldItem, FluidTank tank){ protected boolean tryUseItemOnTank(EntityPlayer player, EnumHand hand, FluidTank tank){
return !StackUtil.isValid(heldItem) || !FluidUtil.interactWithFluidHandler(heldItem, tank, player).isSuccess(); ItemStack heldItem = player.getHeldItem(hand);
if(StackUtil.isValid(heldItem)){
FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, tank, player);
if(result.isSuccess()){
player.setHeldItem(hand, result.getResult());
return true;
}
}
return false;
} }
@Override @Override