Skip to content

Commit

Permalink
Switched VectorConversionMCKt calls to ValkyrienSkies and impleme…
Browse files Browse the repository at this point in the history
…nted PR [#1035](#1035) to both Forge and Fabric `MixinTurtleMoveCommand`
  • Loading branch information
TechTastic committed Dec 29, 2024
1 parent be9e247 commit afa7652
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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<Vector3d> nearbyPositions = ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1);
final List<Vector3d> 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"));
}
}
}
Expand All @@ -54,6 +65,6 @@ private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos
}
}

return VectorConversionsMCKt.toJOMLD(position);
return ValkyrienSkies.toJOMLd(position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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<Vector3d> nearbyPositions = ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1);
final List<Vector3d> 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"));
}
}
}
Expand All @@ -54,6 +65,6 @@ private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos
}
}

return VectorConversionsMCKt.toJOMLD(position);
return ValkyrienSkies.toJOMLd(position);
}
}

0 comments on commit afa7652

Please sign in to comment.