Fix #2197 and add ability to withdraw via right click [only bucket/cell]
This commit is contained in:
parent
ef775af6b8
commit
80049c8c62
1 changed files with 36 additions and 10 deletions
|
@ -28,6 +28,7 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
|
import net.minecraft.item.BucketItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
|
@ -45,6 +46,7 @@ import reborncore.common.util.Tank;
|
||||||
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
|
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
|
||||||
import techreborn.client.GuiType;
|
import techreborn.client.GuiType;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
|
import techreborn.items.DynamicCellItem;
|
||||||
|
|
||||||
public class TankUnitBlock extends BlockMachineBase {
|
public class TankUnitBlock extends BlockMachineBase {
|
||||||
|
|
||||||
|
@ -71,7 +73,11 @@ public class TankUnitBlock extends BlockMachineBase {
|
||||||
Item itemInHand = stackInHand.getItem();
|
Item itemInHand = stackInHand.getItem();
|
||||||
|
|
||||||
// Assuming ItemFluidInfo is 1 BUCKET, for now only allow exact amount or less
|
// Assuming ItemFluidInfo is 1 BUCKET, for now only allow exact amount or less
|
||||||
if (tankUnitEntity != null && itemInHand instanceof ItemFluidInfo) {
|
// I am only going to trust cells or buckets, they are known to be 1 BUCKET size, too suss of other items not abiding by that.
|
||||||
|
if ((itemInHand instanceof DynamicCellItem || itemInHand instanceof BucketItem)
|
||||||
|
&& tankUnitEntity != null && itemInHand instanceof ItemFluidInfo) {
|
||||||
|
|
||||||
|
// Get fluid information from item
|
||||||
ItemFluidInfo itemFluid = (ItemFluidInfo) itemInHand;
|
ItemFluidInfo itemFluid = (ItemFluidInfo) itemInHand;
|
||||||
Fluid fluid = itemFluid.getFluid(stackInHand);
|
Fluid fluid = itemFluid.getFluid(stackInHand);
|
||||||
int amount = stackInHand.getCount();
|
int amount = stackInHand.getCount();
|
||||||
|
@ -79,16 +85,36 @@ public class TankUnitBlock extends BlockMachineBase {
|
||||||
FluidValue fluidValue = FluidValue.BUCKET.multiply(amount);
|
FluidValue fluidValue = FluidValue.BUCKET.multiply(amount);
|
||||||
Tank tankInstance = tankUnitEntity.getTank();
|
Tank tankInstance = tankUnitEntity.getTank();
|
||||||
|
|
||||||
if (tankInstance.canFit(fluid, fluidValue)) {
|
if(new FluidInstance(fluid).isEmptyFluid()){
|
||||||
if (tankInstance.getFluidInstance().isEmptyFluid()) {
|
|
||||||
tankInstance.setFluidInstance(new FluidInstance(fluid, fluidValue));
|
|
||||||
} else {
|
|
||||||
tankInstance.getFluidInstance().addAmount(fluidValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack returnStack = itemFluid.getEmpty();
|
FluidValue fluidValueAmount = FluidValue.BUCKET.multiply(amount);
|
||||||
returnStack.setCount(amount);
|
// If tank has content, fill up user's inventory
|
||||||
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
|
if(tankInstance.getFluidInstance().getAmount().equalOrMoreThan(fluidValueAmount)){
|
||||||
|
|
||||||
|
// Add to player inventory
|
||||||
|
ItemStack returnStack = itemFluid.getFull(tankInstance.getFluid());
|
||||||
|
returnStack.setCount(amount);
|
||||||
|
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
|
||||||
|
|
||||||
|
// Remove from tank
|
||||||
|
tankInstance.getFluidInstance().setAmount(tankInstance.getFluidAmount().subtract(fluidValueAmount));
|
||||||
|
}else{
|
||||||
|
return ActionResult.FAIL;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// If tank can fit fluid and amount, add it
|
||||||
|
if (tankInstance.canFit(fluid, fluidValue)) {
|
||||||
|
if (tankInstance.getFluidInstance().isEmpty()) {
|
||||||
|
tankInstance.setFluidInstance(new FluidInstance(fluid, fluidValue));
|
||||||
|
} else {
|
||||||
|
tankInstance.getFluidInstance().addAmount(fluidValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give players the empty stuff back
|
||||||
|
ItemStack returnStack = itemFluid.getEmpty();
|
||||||
|
returnStack.setCount(amount);
|
||||||
|
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
|
|
Loading…
Add table
Reference in a new issue