From 371c1fe21bc8dd5886985ea322b63165083c1375 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 18 Oct 2019 19:52:21 +0100 Subject: [PATCH] Fix #1859 --- src/main/java/techreborn/items/ItemDynamicCell.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/techreborn/items/ItemDynamicCell.java b/src/main/java/techreborn/items/ItemDynamicCell.java index f6f4bbe50..1cbbbf21e 100644 --- a/src/main/java/techreborn/items/ItemDynamicCell.java +++ b/src/main/java/techreborn/items/ItemDynamicCell.java @@ -133,7 +133,7 @@ public class ItemDynamicCell extends Item implements ItemFluidInfo { FluidState fluidState = usageContext.getWorld().getFluidState(pos); if(fluidState.getFluid() != Fluids.EMPTY && fluidState.isStill()){ stack.decrement(1); - usageContext.getPlayer().inventory.insertStack(getCellWithFluid(fluidState.getFluid(), 1)); + insertOrDropStack(usageContext.getPlayer(), getCellWithFluid(fluidState.getFluid(), 1)); usageContext.getWorld().setBlockState(pos, Blocks.AIR.getDefaultState()); playEmptyingSound(usageContext.getPlayer(), usageContext.getWorld(), pos, fluidState.getFluid()); } @@ -141,13 +141,19 @@ public class ItemDynamicCell extends Item implements ItemFluidInfo { if(blockState.canReplace(new ItemPlacementContext(usageContext))){ usageContext.getWorld().setBlockState(pos, containedFluid.getDefaultState().getBlockState()); stack.decrement(1); - usageContext.getPlayer().inventory.insertStack(getEmpty()); + insertOrDropStack(usageContext.getPlayer(), getEmpty()); playEmptyingSound(usageContext.getPlayer(), usageContext.getWorld(), pos, containedFluid); } } return super.useOnBlock(usageContext); } + private void insertOrDropStack(PlayerEntity playerEntity, ItemStack stack){ + if(!playerEntity.inventory.insertStack(stack)){ + playerEntity.dropStack(stack); + } + } + //Thanks vanilla :) private void playEmptyingSound(@Nullable PlayerEntity playerEntity, IWorld world, BlockPos blockPos, Fluid fluid) { SoundEvent soundEvent = fluid.matches(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;