Skip to content

Commit

Permalink
Fixed both Turtles ability to leave Ships and re-implemented Turtles…
Browse files Browse the repository at this point in the history
… ability to collide with Ships and pass through their empty spaces
  • Loading branch information
TechTastic committed Jan 20, 2025
1 parent 87c03d3 commit d7a5d83
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ public abstract class MixinTurtleBrain {
Direction.getNearest(transformedDirection.x, transformedDirection.y, transformedDirection.z));
setOwner(currentOwner);

if (ship.getTransform().getShipToWorldScaling().equals(1.000E+0, 1.000E+0, 1.000E+0) &&
VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips()) {
// SHIP IS SCALED AND TURTLES CAN LEAVE SCALED SHIPS
final boolean isShipScaled = !ship.getTransform().getShipToWorldScaling().equals(1.000E+0, 1.000E+0, 1.000E+0);

if (isShipScaled) {
// SHIP IS SCALED

if (VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips()) {
// TURTLES CAN LEAVE SCALED SHIPS

return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
} else {
// SHIP ISNT SCALED

return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
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 java.util.stream.Stream;
import javax.annotation.Nonnull;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
Expand All @@ -15,7 +13,6 @@
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -32,14 +29,17 @@ public abstract class MixinTurtleMoveCommand {
if (cir.getReturnValue().isSuccess()) {
final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position);
if (ship == null) {
final boolean notInAir = Streams
.stream(ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1))
.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))))
final List<Vector3d> nearbyShips = Streams.stream(ValkyrienSkies.positionToNearbyShips(world,
position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1)).toList();

final boolean inAir = nearbyShips.isEmpty() || nearbyShips
.stream()
.map(ValkyrienSkies::toMinecraft)
.map(BlockPos::new)
.map(world::getBlockState)
.anyMatch(BlockState::isAir);

if (notInAir) {
if (!inAir) {
cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship"));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ public abstract class MixinTurtleBrain {
Direction.getNearest(transformedDirection.x, transformedDirection.y, transformedDirection.z));
setOwner(currentOwner);

if (ship.getTransform().getShipToWorldScaling().equals(1.000E+0, 1.000E+0, 1.000E+0) &&
VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips()) {
// SHIP IS SCALED AND TURTLES CAN LEAVE SCALED SHIPS
final boolean isShipScaled = !ship.getTransform().getShipToWorldScaling().equals(1.000E+0, 1.000E+0, 1.000E+0);

if (isShipScaled) {
// SHIP IS SCALED

if (VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips()) {
// TURTLES CAN LEAVE SCALED SHIPS

return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
} else {
// SHIP ISNT SCALED

return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
Expand All @@ -14,7 +13,6 @@
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -31,14 +29,17 @@ public abstract class MixinTurtleMoveCommand {
if (cir.getReturnValue().isSuccess()) {
final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position);
if (ship == null) {
final boolean notInAir = Streams
.stream(ValkyrienSkies.positionToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1))
.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))))
final List<Vector3d> nearbyShips = Streams.stream(ValkyrienSkies.positionToNearbyShips(world,
position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, 0.1)).toList();

final boolean inAir = nearbyShips.isEmpty() || nearbyShips
.stream()
.map(ValkyrienSkies::toMinecraft)
.map(BlockPos::new)
.map(world::getBlockState)
.anyMatch(BlockState::isAir);

if (notInAir) {
if (!inAir) {
cir.setReturnValue(TurtleCommandResult.failure("Movement obstructed by ship"));
}
} else {
Expand Down

0 comments on commit d7a5d83

Please sign in to comment.