diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/cc_tweaked/MixinTurtleMoveCommand.java b/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/cc_tweaked/MixinTurtleMoveCommand.java index 3d1d763a..2b4218fa 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/cc_tweaked/MixinTurtleMoveCommand.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/cc_tweaked/MixinTurtleMoveCommand.java @@ -4,11 +4,11 @@ import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.shared.turtle.core.TurtleMoveCommand; import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import java.util.ArrayList; import java.util.List; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.block.state.BlockState; import org.joml.Vector3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -27,25 +27,30 @@ public abstract class MixinTurtleMoveCommand { CallbackInfoReturnable cir) { if (cir.getReturnValue().isSuccess()) { final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position); - if (ship == null) { - final List nearbyShips = Streams.stream(ValkyrienSkies.positionToNearbyShips(world, - position.getCenter().x, position.getCenter().y, position.getCenter().z, 0.1)).toList(); + Vector3d testPosition = ValkyrienSkies.toJOML(position.getCenter()); - final boolean inAir = nearbyShips.isEmpty() || nearbyShips - .stream() - .map(ValkyrienSkies::toMinecraft) - .map(BlockPos::containing) - .map(world::getBlockState) - .anyMatch(BlockState::isAir); - - if (!inAir) { - cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship")); - } - } else { + if (ship != null) { final ChunkPos chunk = world.getChunkAt(position).getPos(); if (!ship.getChunkClaim().contains(chunk.x, chunk.z)) { cir.setReturnValue(TurtleCommandResult.failure("Out of ship chunk")); } + + testPosition = ValkyrienSkies.positionToWorld(ship, testPosition); + } + + final List nearbyShips = + new ArrayList<>(Streams.stream(ValkyrienSkies.positionToNearbyShips(world, + testPosition.x, testPosition.y, testPosition.z, 0.1)).toList()); + + final boolean notInAir = !nearbyShips.isEmpty() && nearbyShips + .stream() + .map(ValkyrienSkies::toMinecraft) + .map(BlockPos::containing) + .map(world::getBlockState) + .anyMatch(state -> !state.isAir()); + + if (notInAir) { + cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship")); } } }