forked from ValkyrienSkies/Valkyrien-Skies-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a81efdf
commit 531403e
Showing
12 changed files
with
487 additions
and
525 deletions.
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
...n/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinSpeakerPosition.java
This file was deleted.
Oops, something went wrong.
228 changes: 115 additions & 113 deletions
228
.../main/java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleBrain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,117 @@ | ||
package org.valkyrienskies.mod.fabric.mixin.compat.cc_restitched; | ||
|
||
//import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; | ||
//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.common.config.VSGameConfig; | ||
//import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; | ||
// | ||
//@Pseudo | ||
//@Mixin(TurtleBrain.class) | ||
//public abstract class MixinTurtleBrain { | ||
// @Shadow | ||
// public abstract TurtleBlockEntity getOwner(); | ||
// | ||
// @Shadow | ||
// public abstract void setOwner(TurtleBlockEntity owner); | ||
// | ||
// @Shadow | ||
// public abstract Level getLevel(); | ||
// | ||
// @ModifyVariable( | ||
// method = "Ldan200/computercraft/shared/turtle/core/TurtleBrain;teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", | ||
// at = @At(value = "HEAD"), | ||
// index = 2 | ||
// ) | ||
// private BlockPos ValkyrienSkies2$teleportToBlockPos(final BlockPos pos) { | ||
// final TurtleBlockEntity currentOwner = getOwner(); | ||
// final BlockPos oldPos = currentOwner.getBlockPos(); | ||
// final Level world = getLevel(); | ||
// | ||
// final Ship ship = VSGameUtilsKt.getShipManagingPos(world, oldPos); | ||
// if (ship != null) { | ||
// // THERE IS A SHIP | ||
// final Direction d = getNewDirection(ship, currentOwner.getDirection()); | ||
// if (!doesShipContainPoint(ship, pos)) { | ||
// // POSITION IS OUTSIDE THE SHIP'S AABB | ||
// | ||
// currentOwner.setDirection(d); | ||
// setOwner(currentOwner); | ||
// | ||
// if (!isShipScaled(ship)) { | ||
// // SHIP IS NOT SCALED | ||
// | ||
// return getWorldPosFromShipPos(ship, pos); | ||
// } else if (turtlesLeaveScaledShips()) { | ||
// // SHIP IS SCALED AND TURTLES CAN LEAVE SCALED SHIPS | ||
// | ||
// return getWorldPosFromShipPos(ship, 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 = BlockPos.containing(tPos.x, tPos.y, tPos.z); | ||
// return newPos; | ||
// } | ||
//} | ||
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; | ||
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.common.config.VSGameConfig; | ||
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; | ||
|
||
@Pseudo | ||
@Mixin(TurtleBrain.class) | ||
public abstract class MixinTurtleBrain { | ||
@Shadow(remap = false) | ||
public abstract TurtleBlockEntity getOwner(); | ||
|
||
@Shadow(remap = false) | ||
public abstract void setOwner(TurtleBlockEntity owner); | ||
|
||
@Shadow | ||
public abstract Level getLevel(); | ||
|
||
@ModifyVariable( | ||
method = "teleportTo(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", | ||
at = @At(value = "HEAD"), | ||
index = 2, | ||
argsOnly = true, | ||
remap = false | ||
) | ||
private BlockPos ValkyrienSkies2$teleportToBlockPos(final BlockPos pos) { | ||
final TurtleBlockEntity currentOwner = getOwner(); | ||
final BlockPos oldPos = currentOwner.getAccess().getPosition(); | ||
final Level world = getLevel(); | ||
|
||
final Ship ship = VSGameUtilsKt.getShipManagingPos(world, oldPos); | ||
if (ship != null) { | ||
// THERE IS A SHIP | ||
final Direction d = getNewDirection(ship, currentOwner.getDirection()); | ||
if (!doesShipContainPoint(ship, pos)) { | ||
// POSITION IS OUTSIDE THE SHIP'S AABB | ||
|
||
currentOwner.setDirection(d); | ||
setOwner(currentOwner); | ||
|
||
if (!isShipScaled(ship)) { | ||
// SHIP IS NOT SCALED | ||
|
||
return getWorldPosFromShipPos(ship, pos); | ||
} else if (turtlesLeaveScaledShips()) { | ||
// SHIP IS SCALED AND TURTLES CAN LEAVE SCALED SHIPS | ||
|
||
return getWorldPosFromShipPos(ship, 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 = BlockPos.containing(tPos); | ||
return newPos; | ||
} | ||
} |
109 changes: 53 additions & 56 deletions
109
...java/org/valkyrienskies/mod/fabric/mixin/compat/cc_restitched/MixinTurtleMoveCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,56 @@ | ||
package org.valkyrienskies.mod.fabric.mixin.compat.cc_restitched; | ||
|
||
// | ||
//import dan200.computercraft.api.turtle.TurtleCommandResult; | ||
//import dan200.computercraft.shared.turtle.core.TurtleMoveCommand; | ||
//import dan200.computercraft.shared.turtle.core.TurtlePlayer; | ||
//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.Level; | ||
//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; | ||
//import org.valkyrienskies.core.api.ships.Ship; | ||
//import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
// | ||
//@Pseudo | ||
//@Mixin(TurtleMoveCommand.class) | ||
//public abstract class MixinTurtleMoveCommand { | ||
// @Inject(method = "canEnter", at = @At("RETURN"), cancellable = true) | ||
// private static void ValkyrienSkies2$canEnter( | ||
// TurtlePlayer turtlePlayer, ServerLevel world, BlockPos position, | ||
// CallbackInfoReturnable<TurtleCommandResult> cir) { | ||
// if (cir.getReturnValue().isSuccess()) { | ||
// final Ship ship = VSGameUtilsKt.getShipManagingPos(world, position); | ||
// if (ship == null) { | ||
// final Ship iShip = VSGameUtilsKt.getShipManagingPos(world, getShipPosFromWorldPos(world, position)); | ||
// if (iShip != null) { | ||
// cir.setReturnValue(TurtleCommandResult.failure("ship")); | ||
// } | ||
// } else { | ||
// final ChunkPos chunk = world.getChunkAt(position).getPos(); | ||
// if (!ship.getChunkClaim().contains(chunk.x, chunk.z)) { | ||
// cir.setReturnValue(TurtleCommandResult.failure("out of ship")); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// | ||
// //CUSTOM METHODS | ||
// @Unique | ||
// private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos position) { | ||
// final List<Vector3d> 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()); | ||
// } | ||
//} | ||
import dan200.computercraft.api.turtle.TurtleCommandResult; | ||
import dan200.computercraft.shared.turtle.core.TurtleMoveCommand; | ||
import dan200.computercraft.shared.turtle.core.TurtlePlayer; | ||
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.Level; | ||
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; | ||
import org.valkyrienskies.core.api.ships.Ship; | ||
import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
|
||
@Pseudo | ||
@Mixin(TurtleMoveCommand.class) | ||
public abstract class MixinTurtleMoveCommand { | ||
@Inject(method = "canEnter", at = @At("RETURN"), remap = false, cancellable = true) | ||
private static void ValkyrienSkies2$canEnter( | ||
final TurtlePlayer turtlePlayer, final ServerLevel world, final BlockPos position, final CallbackInfoReturnable<TurtleCommandResult> cir) { | ||
if (cir.getReturnValue().isSuccess()) { | ||
final Ship ship = VSGameUtilsKt.getShipManagingPos(world, position); | ||
if (ship == null) { | ||
final Ship iShip = VSGameUtilsKt.getShipManagingPos(world, getShipPosFromWorldPos(world, position)); | ||
if (iShip != null) { | ||
cir.setReturnValue(TurtleCommandResult.failure("ship")); | ||
} | ||
} else { | ||
final ChunkPos chunk = world.getChunkAt(position).getPos(); | ||
if (!ship.getChunkClaim().contains(chunk.x, chunk.z)) { | ||
cir.setReturnValue(TurtleCommandResult.failure("out of ship")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
//CUSTOM METHODS | ||
@Unique | ||
private static Vector3d getShipPosFromWorldPos(final Level world, final BlockPos position) { | ||
final List<Vector3d> 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()); | ||
} | ||
} |
Oops, something went wrong.