diff --git a/src/main/java/de/teamlapen/vampirism/blocks/TentBlock.java b/src/main/java/de/teamlapen/vampirism/blocks/TentBlock.java index 94190ebeff..7c6177b5ab 100644 --- a/src/main/java/de/teamlapen/vampirism/blocks/TentBlock.java +++ b/src/main/java/de/teamlapen/vampirism/blocks/TentBlock.java @@ -246,6 +246,19 @@ public boolean isBed(BlockState state, BlockGetter world, BlockPos pos, @Nullabl @Override public @NotNull Direction getBedDirection(@NotNull BlockState state, LevelReader world, BlockPos pos) { + Direction thisFacing = state.getValue(FACING); + int thisPos = state.getValue(POSITION); + if (thisPos != 0) { + BlockPos main = switch (thisPos) { + case 1 -> pos.relative(thisFacing.getClockWise()); + case 2 -> pos.relative(thisFacing.getOpposite()).relative(thisFacing.getClockWise()); + case 3 -> pos.relative(thisFacing); + default -> null; + }; + if (main != null) { + state = world.getBlockState(main); + } + } return switch (state.getValue(POSITION)) { case 0, 3 -> state.getValue(HORIZONTAL_FACING).getOpposite(); default -> state.getValue(HORIZONTAL_FACING); @@ -332,13 +345,31 @@ public InteractionResult use(@NotNull BlockState blockState, @NotNull Level worl player.displayClientMessage(Component.translatable("text.vampirism.tent.occupied"), true); return InteractionResult.SUCCESS; } else { - player.startSleepInBed(pos).ifLeft(sleepResult1 -> { + BlockState targetState = blockState; + BlockPos targetPos = pos; + Direction thisFacing = blockState.getValue(FACING); + int thisPos = blockState.getValue(POSITION); + if (thisPos != 0) { + BlockPos main = switch (thisPos) { + case 1 -> pos.relative(thisFacing.getClockWise()); + case 2 -> pos.relative(thisFacing.getOpposite()).relative(thisFacing.getClockWise()); + case 3 -> pos.relative(thisFacing); + default -> null; + }; + if (main != null) { + targetState = world.getBlockState(main); + targetPos = main; + } + } + BlockState finalTargetState = targetState; + BlockPos finalTargetPos = targetPos; + player.startSleepInBed(finalTargetPos).ifLeft(sleepResult1 -> { if (sleepResult1 != null) { player.displayClientMessage(sleepResults.getOrDefault(sleepResult1, sleepResult1.getMessage()), true); } }).ifRight(u -> { - this.setBedOccupied(blockState, world, pos, null, true); - setTentSleepPosition(player, pos, player.level().getBlockState(pos).getValue(POSITION), player.level().getBlockState(pos).getValue(HORIZONTAL_FACING)); + this.setBedOccupied(finalTargetState, world, finalTargetPos, null, true); + setTentSleepPosition(player, finalTargetPos, finalTargetState.getValue(POSITION), finalTargetState.getValue(HORIZONTAL_FACING)); }); return InteractionResult.SUCCESS; }