Skip to content

Commit

Permalink
Ship-On-Ship Action (Turtles can not pass through and detect Ships wh…
Browse files Browse the repository at this point in the history
…ile on other Ships
  • Loading branch information
TechTastic committed Jan 20, 2025
1 parent a8d338f commit d8eaa63
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,25 +27,30 @@ public abstract class MixinTurtleMoveCommand {
CallbackInfoReturnable<TurtleCommandResult> cir) {
if (cir.getReturnValue().isSuccess()) {
final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position);
if (ship == null) {
final List<Vector3d> 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<Vector3d> 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"));
}
}
}
Expand Down

0 comments on commit d8eaa63

Please sign in to comment.