Skip to content

Commit

Permalink
[24w11a] Drop coffee machine in creative mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMCLoveMan committed Mar 21, 2024
1 parent 6cf7ce5 commit 9105400
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
Expand Down Expand Up @@ -98,6 +100,25 @@ public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos
return InteractionResult.sidedSuccess(level.isClientSide);
}

@Override
public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) {
if (!level.isClientSide && player.isCreative() && level.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
if (level.getBlockEntity(pos) instanceof CoffeeMachineBlockEntity blockEntity) {
if (!blockEntity.isEmpty() ||
!blockEntity.tankHandler.getWaterTank().isEmpty() ||
!blockEntity.tankHandler.getMilkTank().isEmpty()) {
ItemStack stack = new ItemStack(this);
stack.applyComponents(blockEntity.collectComponents());
ItemEntity itemEntity = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), stack);
itemEntity.setDefaultPickUpDelay();
level.addFreshEntity(itemEntity);
}
}
}

return super.playerWillDestroy(level, pos, state, player);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE;
Expand Down

0 comments on commit 9105400

Please sign in to comment.