Skip to content

Commit

Permalink
Fix the bed duplication glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
alikindsys committed Mar 31, 2024
1 parent 5788b65 commit 77c3850
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ private static Direction getDirectionTowardsOtherPart(BedPart part, Direction di

@Redirect(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/HorizontalFacingBlock;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"))
public void onBreak(HorizontalFacingBlock instance, World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
var bedPart = blockState.get(BedBlock.PART);
var otherPartDirection = getDirectionTowardsOtherPart(bedPart, blockState.get(HorizontalFacingBlock.FACING));
var otherPart = blockPos.offset(otherPartDirection);
var otherBlock = world.getBlockState(otherPart);
var headPart = bedPart == BedPart.FOOT ? otherBlock : blockState;
var footPart = bedPart == BedPart.FOOT ? blockState : otherBlock;
var footPos = bedPart == BedPart.FOOT ? blockPos : otherPart;

if (Settings.carefulBreak && playerEntity.isInSneakingPose()) {
var bedPart = blockState.get(BedBlock.PART);
var otherPartDirection = getDirectionTowardsOtherPart(bedPart, blockState.get(HorizontalFacingBlock.FACING));
var otherPart = blockPos.offset(otherPartDirection);
var headPart = bedPart == BedPart.FOOT ? world.getBlockState(otherPart) : blockState;
var stack = headPart.getBlock().asItem().getDefaultStack();

putItem(headPart, world, (bedPart == BedPart.FOOT ? otherPart : blockPos), null, playerEntity, stack);
world.setBlockState(bedPart == BedPart.FOOT ? otherPart : blockPos, Blocks.AIR.getDefaultState(), 35);
world.syncWorldEvent(playerEntity, 2001, bedPart == BedPart.FOOT ? otherPart : blockPos, Block.getRawIdFromState(blockState));
} else {
Block.dropStacks(blockState, world, blockPos);
Block.dropStacks(footPart, world, footPos);
}
}
}

0 comments on commit 77c3850

Please sign in to comment.