From 5a39340c681e9a5aae0505a4f3b56e4f992f698b Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:40:22 +0200 Subject: [PATCH] Improve bed obstruction tweak Account for blockstates without EnumFacing property --- .../mixin/UTBedObstructionMixin.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/bedobstruction/mixin/UTBedObstructionMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/bedobstruction/mixin/UTBedObstructionMixin.java index 0102dfc1..b9c5e180 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/bedobstruction/mixin/UTBedObstructionMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/bedobstruction/mixin/UTBedObstructionMixin.java @@ -22,24 +22,24 @@ public class UTBedObstructionMixin { @Inject(at = @At("HEAD"), method = "getBedSpawnLocation(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Z)Lnet/minecraft/util/math/BlockPos;", cancellable = true) - private static void utBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable callback) + private static void utBedSpawnLocation(World world, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable cir) { if (!UTConfigTweaks.BLOCKS.utBedObstructionToggle) return; if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTBedObstruction ::: Get bed spawn location"); - IBlockState state = worldIn.getBlockState(bedLocation); + IBlockState state = world.getBlockState(bedLocation); Block block = state.getBlock(); - if (!block.isBed(state, worldIn, bedLocation, null)) + if (!block.isBed(state, world, bedLocation, null)) { - if (!forceSpawn) callback.setReturnValue(null); - else callback.setReturnValue(iterateSpawnPoint(worldIn, bedLocation)); + if (!forceSpawn) cir.setReturnValue(null); + else cir.setReturnValue(ut$iterateSpawnPoint(world, bedLocation)); } - else callback.setReturnValue(iterateBedPoint(worldIn, bedLocation)); + else cir.setReturnValue(ut$iterateBedPoint(world, bedLocation)); } @Unique - private static BlockPos iterateSpawnPoint(World world, BlockPos pos) + private static BlockPos ut$iterateSpawnPoint(World world, BlockPos pos) { - if (isValidSpawnPos(world, pos, false)) return pos; + if (ut$isValidSpawnPos(world, pos, false)) return pos; int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); @@ -48,16 +48,17 @@ private static BlockPos iterateSpawnPoint(World world, BlockPos pos) for (int zIter = z - 1; zIter <= z + 1; ++zIter) { BlockPos blockPos = new BlockPos(xIter, y, zIter); - if (isValidSpawnPos(world, blockPos, false)) return blockPos; + if (ut$isValidSpawnPos(world, blockPos, false)) return blockPos; } } return null; } @Unique - private static BlockPos iterateBedPoint(World world, BlockPos pos) + private static BlockPos ut$iterateBedPoint(World world, BlockPos pos) { - EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockHorizontal.FACING); + IBlockState blockState = world.getBlockState(pos); + EnumFacing enumFacing = blockState.getPropertyKeys().contains(BlockHorizontal.FACING) ? blockState.getValue(BlockHorizontal.FACING) : EnumFacing.NORTH; int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); @@ -65,14 +66,14 @@ private static BlockPos iterateBedPoint(World world, BlockPos pos) { for (int facingOffset = 0; facingOffset <= 1; ++facingOffset) { - int xOffset = x - enumfacing.getXOffset() * facingOffset; - int zOffset = z - enumfacing.getZOffset() * facingOffset; + int xOffset = x - enumFacing.getXOffset() * facingOffset; + int zOffset = z - enumFacing.getZOffset() * facingOffset; for (int xIter = xOffset - 1; xIter <= xOffset + 1; ++xIter) { for (int zIter = zOffset - 1; zIter <= zOffset + 1; ++zIter) { BlockPos blockPos = new BlockPos(xIter, y + yOffset, zIter); - if (isValidSpawnPos(world, blockPos, true)) return blockPos; + if (ut$isValidSpawnPos(world, blockPos, true)) return blockPos; } } } @@ -81,7 +82,7 @@ private static BlockPos iterateBedPoint(World world, BlockPos pos) } @Unique - private static boolean isValidSpawnPos(World worldIn, BlockPos blockPos, boolean requireFloor) + private static boolean ut$isValidSpawnPos(World worldIn, BlockPos blockPos, boolean requireFloor) { return (worldIn.getBlockState(blockPos.down()).getMaterial().isSolid() || !requireFloor) && worldIn.getBlockState(blockPos).getBlock().canSpawnInBlock() && worldIn.getBlockState(blockPos.up()).getBlock().canSpawnInBlock(); }