From 33cfa947dc56e614c80288cee3476fd144ac5068 Mon Sep 17 00:00:00 2001 From: TechTastic <74630543+TechTastic@users.noreply.github.com> Date: Sun, 29 Dec 2024 15:30:00 -0600 Subject: [PATCH] Cleaning up Old Mixins (#1040) * And updated CC depndencies * Updated CC Mixins to new API * Switched `VectorConversionMCKt` calls to `ValkyrienSkies` and implemented PR [#1035](https://github.com/ValkyrienSkies/Valkyrien-Skies-2/pull/1035) to both Forge and Fabric `MixinTurtleMoveCommand` * Removed unnecessary method from both `MixinTurtleMoveCommand` mixins * Fixed `Iterable` -> `Stream` jank --- .../cc_restitched/MixinSpeakerSound.java | 14 ++-- .../cc_restitched/MixinTurtleBrain.java | 74 +++-------------- .../cc_restitched/MixinTurtleMoveCommand.java | 36 ++++----- .../cc_restitched/MixinWirelessNetwork.java | 10 +-- forge/build.gradle | 2 +- .../compat/cc_tweaked/MixinSpeakerSound.java | 16 ++-- .../compat/cc_tweaked/MixinTurtleBrain.java | 79 ++++--------------- .../cc_tweaked/MixinTurtleMoveCommand.java | 35 ++++---- .../cc_tweaked/MixinWirelessNetwork.java | 7 +- 9 files changed, 81 insertions(+), 192 deletions(-) diff --git a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinSpeakerSound.java b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinSpeakerSound.java index 1244e4b49..c47346d46 100644 --- a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinSpeakerSound.java +++ b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinSpeakerSound.java @@ -10,20 +10,22 @@ import org.joml.Vector3d; import org.joml.Vector3dc; 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.CallbackInfo; import org.valkyrienskies.core.api.ships.Ship; +import org.valkyrienskies.mod.api.ValkyrienSkies; import org.valkyrienskies.mod.client.audio.VelocityTickableSoundInstance; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +@Pseudo @Mixin(SpeakerSound.class) public abstract class MixinSpeakerSound extends AbstractSoundInstance implements VelocityTickableSoundInstance { @Unique private SpeakerPosition speakerPosition; @Unique private Ship ship; - protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) { + protected MixinSpeakerSound(final ResourceLocation arg, final SoundSource arg2) { super(arg, arg2); } @@ -32,11 +34,11 @@ protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) { at = @At("RETURN"), remap = false ) - private void isOnShip(SpeakerPosition position, CallbackInfo ci) { + private void isOnShip(final SpeakerPosition position, final CallbackInfo ci) { this.speakerPosition = position; - this.ship = VSGameUtilsKt.getShipManagingPos(position.level(), position.position()); + this.ship = ValkyrienSkies.getShipManagingBlock(position.level(), position.position()); if (this.ship != null) { - Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position()); + final Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position()); x = worldPos.x; y = worldPos.y; z = worldPos.z; @@ -49,7 +51,7 @@ private void isOnShip(SpeakerPosition position, CallbackInfo ci) { ) private void updateWorldPos(CallbackInfo ci) { if (this.ship != null) { - Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position()); + final Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position()); x = worldPos.x; y = worldPos.y; z = worldPos.z; 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 654235c89..a1ac5a15c 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 @@ -4,22 +4,16 @@ import dan200.computercraft.shared.turtle.core.TurtleBrain; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import org.joml.Matrix4dc; import org.joml.Vector3d; -import org.joml.Vector3dc; -import org.joml.primitives.AABBic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.valkyrienskies.core.api.ships.Ship; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; import org.valkyrienskies.mod.common.config.VSGameConfig; import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; @@ -36,7 +30,7 @@ public abstract class MixinTurtleBrain { public abstract Level getLevel(); @ModifyVariable( - method = "Ldan200/computercraft/shared/turtle/core/TurtleBrain;teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", + method = "teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", at = @At(value = "HEAD"), index = 2 ) @@ -45,71 +39,27 @@ public abstract class MixinTurtleBrain { final BlockPos oldPos = currentOwner.getBlockPos(); final Level world = getLevel(); - final Ship ship = VSGameUtilsKt.getShipManagingPos(world, oldPos); + final Ship ship = ValkyrienSkies.getShipManagingBlock(world, oldPos); if (ship != null) { // THERE IS A SHIP - final Direction d = getNewDirection(ship, currentOwner.getDirection()); - if (!doesShipContainPoint(ship, pos)) { + final Vector3d transformedDirection = ship.getShipToWorld().transformDirection( + ValkyrienSkies.toJOMLd(currentOwner.getDirection().getNormal()) + ); + if (!ship.getShipAABB().containsPoint(VectorConversionsMCKt.toJOML(pos))) { // POSITION IS OUTSIDE THE SHIP'S AABB - currentOwner.setDirection(d); + currentOwner.setDirection( + Direction.getNearest(transformedDirection.x, transformedDirection.y, transformedDirection.z)); setOwner(currentOwner); - if (!isShipScaled(ship)) { - // SHIP IS NOT SCALED - - return getWorldPosFromShipPos(ship, pos); - } else if (turtlesLeaveScaledShips()) { + 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 - return getWorldPosFromShipPos(ship, pos); + return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos))); } } } return pos; } - - // CUSTOM METHODS - - @Unique - private static Direction getNewDirection(final Ship ship, final Direction direction) { - final Matrix4dc matrix = ship.getShipToWorld(); - final Vec3i turtleDirectionVector = direction.getNormal(); - final Vector3d directionVec = - matrix.transformDirection(turtleDirectionVector.getX(), turtleDirectionVector.getY(), - turtleDirectionVector.getZ(), new Vector3d()); - final Direction dir = Direction.getNearest(directionVec.x, directionVec.y, directionVec.z); - - return dir; - } - - @Unique - private static boolean turtlesLeaveScaledShips() { - return VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips(); - } - - @Unique - private static boolean isShipScaled(final Ship ship) { - final Vector3dc scale = ship.getTransform().getShipToWorldScaling(); - final Vector3dc normalScale = new Vector3d(1.000E+0, 1.000E+0, 1.000E+0); - return !scale.equals(normalScale); - } - - @Unique - private static boolean doesShipContainPoint(final Ship ship, final BlockPos pos) { - final AABBic shipAABB = ship.getShipAABB(); - - final AABB t = new AABB(shipAABB.maxX(), shipAABB.maxY(), shipAABB.maxZ(), shipAABB.minX(), shipAABB.minY(), - shipAABB.minZ()); - return t.intersects(new AABB(pos)); - } - - @Unique - private static BlockPos getWorldPosFromShipPos(final Ship ship, final BlockPos pos) { - final Vec3 tPos = VectorConversionsMCKt.toMinecraft( - VSGameUtilsKt.toWorldCoordinates(ship, pos.getX() + 0.5, pos.getY() + 0.5, - pos.getZ() + 0.5)); - final BlockPos newPos = new BlockPos(tPos.x, tPos.y, tPos.z); - return newPos; - } } 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 7e44efd49..52135e8a0 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 @@ -1,13 +1,17 @@ package org.valkyrienskies.mod.fabric.mixin.compat.cc_restitched; +import com.google.common.collect.Streams; 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; 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 +20,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.valkyrienskies.core.api.ships.Ship; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; @Pseudo @Mixin(TurtleMoveCommand.class) @@ -26,32 +30,24 @@ public abstract class MixinTurtleMoveCommand { final TurtlePlayer turtlePlayer, final Level world, @Nonnull final BlockPos position, final CallbackInfoReturnable cir) { if (cir.getReturnValue().isSuccess()) { - final Ship ship = VSGameUtilsKt.getShipManagingPos(world, position); + final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position); if (ship == null) { - final Ship iShip = VSGameUtilsKt.getShipManagingPos(world, getShipPosFromWorldPos(world, position)); - if (iShip != null) { - cir.setReturnValue(TurtleCommandResult.failure("ship")); + 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)))) + .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")); } } } } - - //CUSTOM METHODS - @Unique - private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos position) { - final List detectedShips = - VSGameUtilsKt.transformToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, - position.getZ() + 0.5, 0.1); - for (final Vector3d vec : detectedShips) { - if (vec != null) { - return vec; - } - } - return new Vector3d(position.getX(), position.getY(), position.getZ()); - } } diff --git a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinWirelessNetwork.java b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinWirelessNetwork.java index 62dbb0c1c..e9d26d177 100644 --- a/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinWirelessNetwork.java +++ b/fabric/src/main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinWirelessNetwork.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; @Pseudo @Mixin(WirelessNetwork.class) @@ -28,12 +28,8 @@ public class MixinWirelessNetwork { final Vec3 posOnShip = shipReceiver.getPosition(); final Vec3 posInWorld = shipSender.getPosition(); - final double distance = - VSGameUtilsKt.squaredDistanceBetweenInclShips(shipReceiver.getLevel(), - posOnShip.x, posOnShip.y, posOnShip.z, - posInWorld.x, posInWorld.y, posInWorld.z); - - return distance; + return ValkyrienSkies.distanceSquared(shipReceiver.getLevel(), + posOnShip.x, posOnShip.y, posOnShip.z, posInWorld.x, posInWorld.y, posInWorld.z); } @Inject(at = @At("HEAD"), method = "tryTransmit", remap = false) diff --git a/forge/build.gradle b/forge/build.gradle index d1dd8d959..58cbe9e1d 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -76,7 +76,7 @@ dependencies { modImplementation("curse.maven:coroutil-237749:5008370") // CC Tweaked - modCompileOnly("curse.maven:cc-tweaked-282001:4061947") + modCompileOnly("curse.maven:cc-tweaked-282001:4630521") // TIS-3d modCompileOnly("curse.maven:tis3d-238603:3738437") diff --git a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinSpeakerSound.java b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinSpeakerSound.java index 3a3fa4244..e26978181 100644 --- a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinSpeakerSound.java +++ b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinSpeakerSound.java @@ -10,20 +10,22 @@ import org.joml.Vector3d; import org.joml.Vector3dc; 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.CallbackInfo; import org.valkyrienskies.core.api.ships.Ship; +import org.valkyrienskies.mod.api.ValkyrienSkies; import org.valkyrienskies.mod.client.audio.VelocityTickableSoundInstance; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +@Pseudo @Mixin(SpeakerSound.class) public abstract class MixinSpeakerSound extends AbstractSoundInstance implements VelocityTickableSoundInstance { @Unique private SpeakerPosition speakerPosition; @Unique private Ship ship; - protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) { + protected MixinSpeakerSound(final ResourceLocation arg, final SoundSource arg2) { super(arg, arg2); } @@ -32,11 +34,11 @@ protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) { at = @At("RETURN"), remap = false ) - private void isOnShip(SpeakerPosition position, CallbackInfo ci) { + private void isOnShip(final SpeakerPosition position, final CallbackInfo ci) { this.speakerPosition = position; - this.ship = VSGameUtilsKt.getShipManagingPos(position.level(), position.position()); + this.ship = ValkyrienSkies.getShipManagingBlock(position.level(), position.position()); if (this.ship != null) { - Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position()); + final Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position()); x = worldPos.x; y = worldPos.y; z = worldPos.z; @@ -47,9 +49,9 @@ private void isOnShip(SpeakerPosition position, CallbackInfo ci) { method = "tick", at = @At("HEAD") ) - private void updateWorldPos(CallbackInfo ci) { + private void updateWorldPos(final CallbackInfo ci) { if (this.ship != null) { - Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position()); + final Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position()); x = worldPos.x; y = worldPos.y; z = worldPos.z; 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 a5ca0bd71..17f12ecdc 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 @@ -4,22 +4,16 @@ import dan200.computercraft.shared.turtle.core.TurtleBrain; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import org.joml.Matrix4dc; import org.joml.Vector3d; -import org.joml.Vector3dc; -import org.joml.primitives.AABBic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.valkyrienskies.core.api.ships.Ship; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; import org.valkyrienskies.mod.common.config.VSGameConfig; import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; @@ -36,81 +30,36 @@ public abstract class MixinTurtleBrain { public abstract Level getLevel(); @ModifyVariable( - method = "Ldan200/computercraft/shared/turtle/core/TurtleBrain;teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", + method = "teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", at = @At(value = "HEAD"), - index = 2, - remap = false + index = 2 ) private BlockPos ValkyrienSkies2$teleportToBlockPos(final BlockPos pos) { final TileTurtle currentOwner = getOwner(); - final BlockPos oldPos = currentOwner.getAccess().getPosition(); + final BlockPos oldPos = currentOwner.getBlockPos(); final Level world = getLevel(); - final Ship ship = VSGameUtilsKt.getShipManagingPos(world, oldPos); + final Ship ship = ValkyrienSkies.getShipManagingBlock(world, oldPos); if (ship != null) { // THERE IS A SHIP - final Direction d = getNewDirection(ship, currentOwner.getDirection()); - if (!doesShipContainPoint(ship, pos)) { + final Vector3d transformedDirection = ship.getShipToWorld().transformDirection( + ValkyrienSkies.toJOMLd(currentOwner.getDirection().getNormal()) + ); + if (!ship.getShipAABB().containsPoint(VectorConversionsMCKt.toJOML(pos))) { // POSITION IS OUTSIDE THE SHIP'S AABB - currentOwner.setDirection(d); + currentOwner.setDirection( + Direction.getNearest(transformedDirection.x, transformedDirection.y, transformedDirection.z)); setOwner(currentOwner); - if (!isShipScaled(ship)) { - // SHIP IS NOT SCALED - - return getWorldPosFromShipPos(ship, pos); - } else if (turtlesLeaveScaledShips()) { + 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 - return getWorldPosFromShipPos(ship, pos); + return new BlockPos(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos))); } } } return pos; } - - // CUSTOM METHODS - - @Unique - private static Direction getNewDirection(final Ship ship, final Direction direction) { - final Matrix4dc matrix = ship.getShipToWorld(); - final Vec3i turtleDirectionVector = direction.getNormal(); - final Vector3d directionVec = - matrix.transformDirection(turtleDirectionVector.getX(), turtleDirectionVector.getY(), - turtleDirectionVector.getZ(), new Vector3d()); - final Direction dir = Direction.getNearest(directionVec.x, directionVec.y, directionVec.z); - - return dir; - } - - @Unique - private static boolean turtlesLeaveScaledShips() { - return VSGameConfig.SERVER.getComputerCraft().getCanTurtlesLeaveScaledShips(); - } - - @Unique - private static boolean isShipScaled(final Ship ship) { - final Vector3dc scale = ship.getTransform().getShipToWorldScaling(); - final Vector3dc normalScale = new Vector3d(1.000E+0, 1.000E+0, 1.000E+0); - return !scale.equals(normalScale); - } - - @Unique - private static boolean doesShipContainPoint(final Ship ship, final BlockPos pos) { - final AABBic shipAABB = ship.getShipAABB(); - - final AABB t = new AABB(shipAABB.maxX(), shipAABB.maxY(), shipAABB.maxZ(), shipAABB.minX(), shipAABB.minY(), - shipAABB.minZ()); - return t.intersects(new AABB(pos)); - } - - @Unique - private static BlockPos getWorldPosFromShipPos(final Ship ship, final BlockPos pos) { - final Vec3 tPos = VectorConversionsMCKt.toMinecraft( - VSGameUtilsKt.toWorldCoordinates(ship, pos.getX() + 0.5, pos.getY() + 0.5, - pos.getZ() + 0.5)); - final BlockPos newPos = new BlockPos(tPos.x, tPos.y, tPos.z); - return newPos; - } } 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 4798d7249..4de46e927 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 @@ -1,13 +1,16 @@ package org.valkyrienskies.mod.forge.mixin.compat.cc_tweaked; +import com.google.common.collect.Streams; 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,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.valkyrienskies.core.api.ships.Ship; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; @Pseudo @Mixin(TurtleMoveCommand.class) @@ -26,32 +29,24 @@ public abstract class MixinTurtleMoveCommand { final TurtlePlayer turtlePlayer, final Level world, @Nonnull final BlockPos position, final CallbackInfoReturnable cir) { if (cir.getReturnValue().isSuccess()) { - final Ship ship = VSGameUtilsKt.getShipManagingPos(world, position); + final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position); if (ship == null) { - final Ship iShip = VSGameUtilsKt.getShipManagingPos(world, getShipPosFromWorldPos(world, position)); - if (iShip != null) { - cir.setReturnValue(TurtleCommandResult.failure("ship")); + 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)))) + .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")); } } } } - - //CUSTOM METHODS - @Unique - private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos position) { - final List detectedShips = - VSGameUtilsKt.transformToNearbyShipsAndWorld(world, position.getX() + 0.5, position.getY() + 0.5, - position.getZ() + 0.5, 0.1); - for (final Vector3d vec : detectedShips) { - if (vec != null) { - return vec; - } - } - return new Vector3d(position.getX(), position.getY(), position.getZ()); - } } diff --git a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinWirelessNetwork.java b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinWirelessNetwork.java index f623cc254..cbac1f18d 100644 --- a/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinWirelessNetwork.java +++ b/forge/src/main/java/org/valkyrienskies/mod/forge/mixin/compat/cc_tweaked/MixinWirelessNetwork.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.api.ValkyrienSkies; @Pseudo @Mixin(WirelessNetwork.class) @@ -27,14 +27,13 @@ public class MixinWirelessNetwork { ) ) private static double ValkyrienSkies$distanceToSqr(final Vec3 instance, final Vec3 d) { - return VSGameUtilsKt.squaredDistanceBetweenInclShips(shipReceiver.getLevel(), instance.x, instance.y, + return ValkyrienSkies.distanceSquared(shipReceiver.getLevel(), instance.x, instance.y, instance.z, d.x, d.y, d.z); } @Inject(at = @At("HEAD"), method = "tryTransmit", remap = false) private static void ValkyrienSkies2$tryTransmit(final IPacketReceiver receiver, final Packet packet, - final double range, - final boolean interdimensional, final CallbackInfo ci) { + final double range, final boolean interdimensional, final CallbackInfo ci) { shipReceiver = receiver; shipSender = packet.sender(); }