Skip to content

Commit

Permalink
Casting lecterns drop books when broken by non-players
Browse files Browse the repository at this point in the history
  • Loading branch information
ssblur committed Aug 12, 2024
1 parent 727a689 commit 8abe79d
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ public ItemInteractionResult useItemOn(ItemStack itemStack, BlockState blockStat
return ItemInteractionResult.CONSUME;
}

@Override
public BlockState playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) {
var result = super.playerWillDestroy(level, blockPos, blockState, player);
if(level.getBlockEntity(blockPos) instanceof CastingLecternBlockEntity lectern) {
for(var item: lectern.getItems()) {
var entity = new ItemEntity(level, blockPos.getX() + 0.5f, blockPos.getY() + 0.5f, blockPos.getZ() + 0.5f, item);
level.addFreshEntity(entity);
}
}
return result;
}

public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
return this.defaultBlockState().setValue(FACING, blockPlaceContext.getHorizontalDirection().getOpposite());
}
Expand Down Expand Up @@ -109,4 +97,17 @@ public <T extends BlockEntity> GameEventListener getListener(ServerLevel serverL
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return Shapes.box(0.0625, 0, 0.0625, 0.875, 0.9375, 0.875);
}

@Override
protected void onRemove(BlockState blockState, Level level, BlockPos blockPos, BlockState blockState2, boolean bl) {
if(!level.isClientSide) {
if(level.getBlockEntity(blockPos) instanceof CastingLecternBlockEntity lectern) {
for (var item : lectern.getItems()) {
var entity = new ItemEntity(level, blockPos.getX() + 0.5f, blockPos.getY() + 0.5f, blockPos.getZ() + 0.5f, item);
level.addFreshEntity(entity);
}
}
}
super.onRemove(blockState, level, blockPos, blockState2, bl);
}
}

0 comments on commit 8abe79d

Please sign in to comment.