Skip to content

Commit

Permalink
let tent block forward sleep related interaction to main block
Browse files Browse the repository at this point in the history
close #1363
  • Loading branch information
Cheaterpaul committed Jun 2, 2024
1 parent 7354baf commit f04752a
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/main/java/de/teamlapen/vampirism/blocks/TentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f04752a

Please sign in to comment.