diff --git a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleBrain.java b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleBrain.java index 9c93176e..a1ac5a15 100644 --- a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleBrain.java +++ b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleBrain.java @@ -43,7 +43,7 @@ public abstract class MixinTurtleBrain { if (ship != null) { // THERE IS A SHIP final Vector3d transformedDirection = ship.getShipToWorld().transformDirection( - VectorConversionsMCKt.toJOMLD(currentOwner.getDirection().getNormal()) + ValkyrienSkies.toJOMLd(currentOwner.getDirection().getNormal()) ); if (!ship.getShipAABB().containsPoint(VectorConversionsMCKt.toJOML(pos))) { // POSITION IS OUTSIDE THE SHIP'S AABB diff --git a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleMoveCommand.java b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleMoveCommand.java index 1b6f01e2..58344115 100644 --- a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleMoveCommand.java +++ b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleMoveCommand.java @@ -3,10 +3,13 @@ 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 javax.annotation.Nonnull; import net.minecraft.core.BlockPos; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import org.joml.Vector3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -16,7 +19,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.valkyrienskies.core.api.ships.Ship; import org.valkyrienskies.mod.api.ValkyrienSkies; -import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; @Pseudo @Mixin(TurtleMoveCommand.class) @@ -28,14 +30,23 @@ public abstract class MixinTurtleMoveCommand { if (cir.getReturnValue().isSuccess()) { final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position); if (ship == null) { - final Ship iShip = ValkyrienSkies.getShipManagingBlock(world, getShipPosFromWorldPos(world, position)); - if (iShip != null) { - cir.setReturnValue(TurtleCommandResult.failure("ship")); + final Iterable nearbyPositions = ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1); + final List nearbyBlocks = new ArrayList<>(); + nearbyPositions.forEach(nearbyBlocks::add); + + final boolean notInAir = nearbyBlocks.stream() + .map(pos -> ValkyrienSkies.getShipManagingBlock(world, pos)) + .map(s -> ValkyrienSkies.positionToShip(s, new Vector3d(position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5))) + .map(pos -> world.getBlockState(new BlockPos(ValkyrienSkies.toMinecraft(pos)))) + .anyMatch(BlockState::isAir); + + if (notInAir) { + cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship")); } } else { final ChunkPos chunk = world.getChunkAt(position).getPos(); if (!ship.getChunkClaim().contains(chunk.x, chunk.z)) { - cir.setReturnValue(TurtleCommandResult.failure("out of ship")); + cir.setReturnValue(TurtleCommandResult.failure("Out of ship chunk")); } } } @@ -54,6 +65,6 @@ private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos } } - return VectorConversionsMCKt.toJOMLD(position); + return ValkyrienSkies.toJOMLd(position); } } diff --git a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleBrain.java b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleBrain.java index 034d952a..17f12ecd 100644 --- a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleBrain.java +++ b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleBrain.java @@ -12,10 +12,8 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.valkyrienskies.core.api.ships.LoadedShip; import org.valkyrienskies.core.api.ships.Ship; import org.valkyrienskies.mod.api.ValkyrienSkies; -import org.valkyrienskies.mod.common.VSGameUtilsKt; import org.valkyrienskies.mod.common.config.VSGameConfig; import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; @@ -45,7 +43,7 @@ public abstract class MixinTurtleBrain { if (ship != null) { // THERE IS A SHIP final Vector3d transformedDirection = ship.getShipToWorld().transformDirection( - VectorConversionsMCKt.toJOMLD(currentOwner.getDirection().getNormal()) + ValkyrienSkies.toJOMLd(currentOwner.getDirection().getNormal()) ); if (!ship.getShipAABB().containsPoint(VectorConversionsMCKt.toJOML(pos))) { // POSITION IS OUTSIDE THE SHIP'S AABB diff --git a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleMoveCommand.java b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleMoveCommand.java index 0d2b236e..d96ea1e1 100644 --- a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleMoveCommand.java +++ b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinTurtleMoveCommand.java @@ -3,10 +3,13 @@ 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 javax.annotation.Nonnull; import net.minecraft.core.BlockPos; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import org.joml.Vector3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -16,7 +19,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.valkyrienskies.core.api.ships.Ship; import org.valkyrienskies.mod.api.ValkyrienSkies; -import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; @Pseudo @Mixin(TurtleMoveCommand.class) @@ -28,14 +30,23 @@ public abstract class MixinTurtleMoveCommand { if (cir.getReturnValue().isSuccess()) { final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position); if (ship == null) { - final Ship iShip = ValkyrienSkies.getShipManagingBlock(world, getShipPosFromWorldPos(world, position)); - if (iShip != null) { - cir.setReturnValue(TurtleCommandResult.failure("ship")); + final Iterable nearbyPositions = ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1); + final List nearbyBlocks = new ArrayList<>(); + nearbyPositions.forEach(nearbyBlocks::add); + + final boolean notInAir = nearbyBlocks.stream() + .map(pos -> ValkyrienSkies.getShipManagingBlock(world, pos)) + .map(s -> ValkyrienSkies.positionToShip(s, new Vector3d(position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5))) + .map(pos -> world.getBlockState(new BlockPos(ValkyrienSkies.toMinecraft(pos)))) + .anyMatch(BlockState::isAir); + + if (notInAir) { + cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship")); } } else { final ChunkPos chunk = world.getChunkAt(position).getPos(); if (!ship.getChunkClaim().contains(chunk.x, chunk.z)) { - cir.setReturnValue(TurtleCommandResult.failure("out of ship")); + cir.setReturnValue(TurtleCommandResult.failure("Out of ship chunk")); } } } @@ -54,6 +65,6 @@ private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos } } - return VectorConversionsMCKt.toJOMLD(position); + return ValkyrienSkies.toJOMLd(position); } }