Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting CC: Tweaked Mixins in Common #1046

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ dependencies {
// Weather2 1.20.1
modCompileOnly("curse.maven:weather-storms-tornadoes-237746:5244118")

// CC: Tweaked
modCompileOnly("maven.modrinth:cc-tweaked:${cc_tweaked_version}")

//Common create compat,
//We just use a version from a platform and hope the classes exist on both versions and mixins apply correctly
modCompileOnly("com.simibubi.create:create-fabric-${minecraft_version}:${create_fabric_version}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.valkyrienskies.mod.forge.mixin.compat.cc_tweaked;
package org.valkyrienskies.mod.mixin.mod_compat.cc_tweaked;

import dan200.computercraft.client.sound.SpeakerSound;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
Expand All @@ -16,8 +16,8 @@
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;

@Mixin(SpeakerSound.class)
public abstract class MixinSpeakerSound extends AbstractSoundInstance implements VelocityTickableSoundInstance {
Expand All @@ -35,9 +35,9 @@ protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2, RandomSource
)
private void isOnShip(SpeakerPosition position, 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());
Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
Expand All @@ -50,7 +50,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());
Vec3 worldPos = ValkyrienSkies.positionToWorld(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.valkyrienskies.mod.mixin.mod_compat.cc_tweaked;

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.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
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.Ship;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import org.valkyrienskies.mod.common.config.VSGameConfig;

@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.getBlockPos();
final Level world = getLevel();

final Ship ship = ValkyrienSkies.getShipManagingBlock(world, oldPos);
if (ship != null) {
// THERE IS A SHIP

final Vector3d transformedDirection = ship.getShipToWorld().transformDirection(
ValkyrienSkies.toJOMLd(currentOwner.getDirection().getNormal())
);
if (!ship.getShipAABB().containsPoint(ValkyrienSkies.toJOML(pos))) {
// POSITION IS OUTSIDE THE SHIP'S AABB

currentOwner.setDirection(
Direction.getNearest(transformedDirection.x, transformedDirection.y, transformedDirection.z));
setOwner(currentOwner);

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 BlockPos.containing(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
} else {
// SHIP ISNT SCALED

return BlockPos.containing(ValkyrienSkies.positionToWorld(ship, Vec3.atCenterOf(pos)));
}
}
}
return pos;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.valkyrienskies.mod.mixin.mod_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 net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
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.api.ValkyrienSkies;

@Pseudo
@Mixin(TurtleMoveCommand.class)
public abstract class MixinTurtleMoveCommand {
@Inject(method = "canEnter", at = @At("RETURN"), remap = false, cancellable = true)
private static void ValkyrienSkies2$canEnter(
TurtlePlayer turtlePlayer, ServerLevel world, BlockPos position,
CallbackInfoReturnable<TurtleCommandResult> cir) {
if (cir.getReturnValue().isSuccess()) {
final Ship ship = ValkyrienSkies.getShipManagingBlock(world, position);
Vector3d testPosition = ValkyrienSkies.toJOML(position.getCenter());

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"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.valkyrienskies.mod.forge.mixin.compat.cc_tweaked;
package org.valkyrienskies.mod.mixin.mod_compat.cc_tweaked;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
Expand All @@ -7,7 +7,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;

@Pseudo
@Mixin(WirelessModemPeripheral.class)
Expand All @@ -20,6 +20,6 @@ public abstract class MixinWirelessModemPeripheral {
)
)
public Vec3 ValkyrienSkies$getPosition(WirelessModemPeripheral instance, Operation<Vec3> original){
return VSGameUtilsKt.toWorldCoordinates(instance.getLevel(), original.call(instance));
return ValkyrienSkies.positionToWorld(instance.getLevel(), original.call(instance));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.valkyrienskies.mod.forge.mixin.compat.cc_tweaked;
package org.valkyrienskies.mod.mixin.mod_compat.cc_tweaked;

import dan200.computercraft.api.network.Packet;
import dan200.computercraft.api.network.PacketReceiver;
import dan200.computercraft.api.network.PacketSender;
import dan200.computercraft.api.network.Packet;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -12,7 +12,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)
Expand All @@ -30,7 +30,7 @@ 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);
}

Expand Down
6 changes: 6 additions & 0 deletions common/src/main/resources/valkyrienskies-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"mod_compat.bluemap.MixinBmMap",
"mod_compat.bluemap.MixinHiresModelManager",
"mod_compat.bluemap.MixinWorld",
"mod_compat.cc_tweaked.MixinTurtleBrain",
"mod_compat.cc_tweaked.MixinTurtleMoveCommand",
"mod_compat.cc_tweaked.MixinWirelessModemPeripheral",
"mod_compat.cc_tweaked.MixinWirelessNetwork",
"mod_compat.cc_tweaked.MixinSpeakerSound",
"mod_compat.create.IMixinDeployerHandler",
"mod_compat.create.IMixinDeployerMovementBehaviour",
"mod_compat.create.MixinAirCurrent",
Expand Down Expand Up @@ -152,6 +157,7 @@
"feature.transform_particles.MixinLevelRenderer",
"feature.transform_particles.MixinParticle",
"feature.vs2_alpha_hud.MixinGui",
"mod_compat.cc_tweaked.MixinSpeakerSound",
"mod_compat.create.client.MixinAABBOutline",
"mod_compat.create.client.MixinBlockClusterOutline",
"mod_compat.create.client.MixinCarriageContraptionInstance",
Expand Down
3 changes: 0 additions & 3 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ dependencies {
include("com.fasterxml:classmate:1.5.1")
implementation("com.fasterxml:classmate:1.5.1")

// CC Restitched
modCompileOnly("maven.modrinth:cc-tweaked:${cc_tweaked_version}")

// EMF compat
modCompileOnly("curse.maven:entity-model-features-844662:5696901")
modCompileOnly("curse.maven:entity-texture-features-fabric-568563:5697084")
Expand Down
3 changes: 0 additions & 3 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ no_indium_version=1.1.0+1.20
#https://modrinth.com/mod/sodium/versions
sodium_version = mc1.20.1-0.5.8

# https://modrinth.com/mod/cc-tweaked/version/Zoo9N9Dv
cc_tweaked_version = 1.113.1-fabric

kotlin_fabric_version = 1.10.10+kotlin.1.9.10

# https://modrinth.com/mod/indium/version/1.0.9+mc1.19.2
Expand Down

This file was deleted.

Loading
Loading