From ba5d6ea5f39b268415318d00cbc6d087879b990f Mon Sep 17 00:00:00 2001 From: XyperCode Date: Sun, 31 Mar 2024 06:59:06 +0200 Subject: [PATCH] Fix paper block drops --- .../com/ultreon/devices/block/PaperBlock.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/com/ultreon/devices/block/PaperBlock.java b/common/src/main/java/com/ultreon/devices/block/PaperBlock.java index 6faf1938..282aea90 100644 --- a/common/src/main/java/com/ultreon/devices/block/PaperBlock.java +++ b/common/src/main/java/com/ultreon/devices/block/PaperBlock.java @@ -6,7 +6,6 @@ import net.minecraft.core.Direction; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -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; @@ -18,15 +17,14 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; @SuppressWarnings("NullableProblems") @@ -61,7 +59,7 @@ public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, @Override public BlockState getStateForPlacement(BlockPlaceContext pContext) { BlockState state = super.getStateForPlacement(pContext); - return state != null ? state.setValue(FACING, pContext.getHorizontalDirection()) : null; + return state != null ? state.setValue(FACING, pContext.getHorizontalDirection().getClockWise()) : null; } @Override @@ -77,19 +75,14 @@ public InteractionResult use(BlockState pState, Level level, BlockPos pPos, Play @Override public List getDrops(BlockState pState, LootParams.Builder pBuilder) { - return new ArrayList<>(); - } + BlockEntity blockEntity = pBuilder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); - @Override - public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) { - if (!level.isClientSide) { - BlockEntity tileEntity = level.getBlockEntity(pos); - if (tileEntity instanceof PaperBlockEntity paper) { - ItemStack drop = IPrint.generateItem(paper.getPrint()); - level.addFreshEntity(new ItemEntity(level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop)); - } + if (blockEntity instanceof PaperBlockEntity paper) { + ItemStack drop = IPrint.generateItem(paper.getPrint()); + return List.of(drop); } - super.onRemove(state, level, pos, newState, isMoving); + + return super.getDrops(pState, pBuilder); } @Override