From 13e565002169cd813d2f5ae0bf40f486598d9b0a Mon Sep 17 00:00:00 2001 From: Up Date: Fri, 31 Jan 2025 06:51:55 +0100 Subject: [PATCH] fix interaction bug with pocket dimension exit --- .../common/blocks/SpatialRiftExitBlock.java | 14 +++++++++----- .../components/level/PocketDimensionComponent.java | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/cammiescorner/arcanuscontinuum/common/blocks/SpatialRiftExitBlock.java b/src/main/java/dev/cammiescorner/arcanuscontinuum/common/blocks/SpatialRiftExitBlock.java index bc87d3df..b600b40a 100644 --- a/src/main/java/dev/cammiescorner/arcanuscontinuum/common/blocks/SpatialRiftExitBlock.java +++ b/src/main/java/dev/cammiescorner/arcanuscontinuum/common/blocks/SpatialRiftExitBlock.java @@ -3,6 +3,7 @@ import dev.cammiescorner.arcanuscontinuum.common.blocks.entities.SpatialRiftExitBlockEntity; import dev.cammiescorner.arcanuscontinuum.common.components.level.PocketDimensionComponent; import dev.cammiescorner.arcanuscontinuum.common.registry.ArcanusBlocks; +import dev.upcraft.sparkweave.api.util.scheduler.Tasks; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -28,11 +29,14 @@ public SpatialRiftExitBlock() { } @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if(!world.isClientSide() && !PocketDimensionComponent.get(world).teleportOutOfPocketDimension(player)) - return InteractionResult.FAIL; - - return InteractionResult.sidedSuccess(world.isClientSide()); + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if(!level.isClientSide()) { + // the game assumes that at the end of the right click, the player is still in the same dimension. + // therefore we need to schedule the teleportation at some later point + Tasks.scheduleEphemeral(() -> PocketDimensionComponent.get(level).teleportOutOfPocketDimension(player), 0L); + } + + return InteractionResult.sidedSuccess(level.isClientSide()); } @Override diff --git a/src/main/java/dev/cammiescorner/arcanuscontinuum/common/components/level/PocketDimensionComponent.java b/src/main/java/dev/cammiescorner/arcanuscontinuum/common/components/level/PocketDimensionComponent.java index f96aa3e4..7a8678c0 100644 --- a/src/main/java/dev/cammiescorner/arcanuscontinuum/common/components/level/PocketDimensionComponent.java +++ b/src/main/java/dev/cammiescorner/arcanuscontinuum/common/components/level/PocketDimensionComponent.java @@ -146,7 +146,7 @@ else if(!chunksExist(plot, pocketDim)) { } public boolean teleportOutOfPocketDimension(Entity entity) { - if((entity instanceof Player player && FakePlayerHelper.isFakePlayer(player)) || entity.level().isClientSide() || entity.level().dimension() != ArcanusDimensions.POCKET_DIMENSION) + if((entity instanceof Player player && FakePlayerHelper.isFakePlayer(player)) || entity.level().dimension() != ArcanusDimensions.POCKET_DIMENSION) return false; UUID ownerId = existingPlots.values().stream().filter(plot -> entity.getBoundingBox().intersects(AABB.of(plot.getBounds()))).map(PocketDimensionPlot::ownerId).findFirst().orElse(null);