Skip to content
Draft
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
1 change: 1 addition & 0 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {
compileOnly("maven.modrinth:jade-addons-forge:${project.jade_addons_version}+neoforge") { transitive = false }
compileOnly("maven.modrinth:moonlight:${project.moonlight_version}-neoforge")
compileOnly("curse.maven:vista-1368607:$vista_version")
compileOnly("maven.modrinth:shoulder-surfing-reloaded:${minecraft_version}-${project.shouldersurfing_version}+neoforge") { transitive = false }
}

// Declare capabilities on the outgoing configurations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CameraTypeMixin {

@Invoker(value = "<init>")
private static CameraType create(final String name, final int ordinal, final boolean firstPerson, final boolean mirrored) {
throw new IllegalStateException("Unreachable");
throw new AssertionError("Unreachable");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.ryanhcode.sable.mixin.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.api.util.EntityHelper;
import com.llamalad7.mixinextras.sugar.Local;
import dev.ryanhcode.sable.Sable;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(EntityHelper.class)
public class EntityHelperMixin {

@ModifyVariable(method = "lookAtTarget", at = @At("HEAD"), index = 1, argsOnly = true)
private static Vec3 modifyTarget(final Vec3 original, @Local(argsOnly = true) final LocalPlayer player) {
return Sable.HELPER.projectOutOfSubLevel(player.level(), original);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.ryanhcode.sable.mixin.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.api.model.PickContext;
import com.github.exopandora.shouldersurfing.client.ObjectPicker;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import dev.ryanhcode.sable.Sable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ObjectPicker.class)
public class ObjectPickerMixin {

@Redirect(method = "pick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;distanceTo(Lnet/minecraft/world/phys/Vec3;)D"))
public double distanceTo(final Vec3 instance, final Vec3 vec, @Local(argsOnly = true) final Player player) {
return Math.sqrt(Sable.HELPER.distanceSquaredWithSubLevels(player.level(), instance, vec));
}

@Redirect(method = "pickEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D"))
public double distanceToSq(final Vec3 instance, final Vec3 vec, @Local(argsOnly = true) final PickContext context) {
return Sable.HELPER.distanceSquaredWithSubLevels(context.entity().level(), instance, vec);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package dev.ryanhcode.sable.mixin.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.api.client.IClientConfig;
import com.github.exopandora.shouldersurfing.api.model.CrosshairVisibility;
import com.github.exopandora.shouldersurfing.api.model.Perspective;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.lib.apache.commons.ArrayUtils;
import com.llamalad7.mixinextras.sugar.Local;
import dev.ryanhcode.sable.mixinhelpers.camera.new_camera_types.SableCameraTypes;
import dev.ryanhcode.sable.mixinhelpers.compatibility.shouldersurfing.SablePerspectives;
import net.minecraft.client.CameraType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Perspective.class)
public class PerspectiveMixin {

@Shadow
@Final
@Mutable
private static Perspective[] $VALUES;

static {
final var subLevelView = create("SUB_LEVEL_VIEW", $VALUES.length, SableCameraTypes.SUB_LEVEL_VIEW, CrosshairVisibility.NEVER);

$VALUES = ArrayUtils.add($VALUES, subLevelView);

final var subLevelViewUnlocked = create("SUB_LEVEL_VIEW_UNLOCKED", $VALUES.length, SableCameraTypes.SUB_LEVEL_VIEW_UNLOCKED, CrosshairVisibility.NEVER);

$VALUES = ArrayUtils.add($VALUES, subLevelViewUnlocked);
}

@SuppressWarnings("SameParameterValue")
@Invoker(value = "<init>")
private static Perspective create(final String name, final int ordinal, final CameraType cameraType, final CrosshairVisibility defaultCrosshairVisibility) {
throw new AssertionError("Unreachable");
}

@SuppressWarnings("ConstantValue")
@WrapOperation(method = "next", at = @At(value = "INVOKE", target = "Lcom/github/exopandora/shouldersurfing/api/client/IClientConfig;replaceDefaultPerspective()Z"))
public boolean nextPerspective(final IClientConfig instance, final Operation<Boolean> original) {
if ((Object) this == SablePerspectives.SUB_LEVEL_VIEW || (Object) this == SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED) {
return false;
}
return original.call(instance);
}

@ModifyVariable(method = "next", at = @At(value = "STORE"), name = "next")
public Perspective next(final Perspective next, @Local(argsOnly = true) final IClientConfig config) {
if (config.replaceDefaultPerspective()) {
if ((Object) this == Perspective.SHOULDER_SURFING) {
return SablePerspectives.SUB_LEVEL_VIEW;
}
} else {
// The normal logic will try to wrap around to our new values, but the next one should be first person
if ((Object) this == Perspective.SHOULDER_SURFING) {
return Perspective.FIRST_PERSON;
}

if ((Object) this == Perspective.THIRD_PERSON_BACK) {
return SablePerspectives.SUB_LEVEL_VIEW;
}
}

if ((Object) this == SablePerspectives.SUB_LEVEL_VIEW) {
return SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED;
}
if ((Object) this == SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED) {
return Perspective.THIRD_PERSON_FRONT;
}

return next;
}

@Inject(method = "next", at = @At("TAIL"), cancellable = true)
public void getNext(final CallbackInfoReturnable<Perspective> cir, @Local(name = "next") final Perspective next) {
if (next == SablePerspectives.SUB_LEVEL_VIEW) {
cir.setReturnValue(SablePerspectives.SUB_LEVEL_VIEW);
}
if (next == SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED) {
cir.setReturnValue(SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED);
}
}

@SuppressWarnings("ConstantValue")
@Inject(method = "isEnabled", at = @At("HEAD"), cancellable = true)
public void isEnabled(final CallbackInfoReturnable<Boolean> cir) {
if ((Object) this == SablePerspectives.SUB_LEVEL_VIEW || (Object) this == SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED) {
cir.setReturnValue(true);
}
}

@Inject(method = "of", at = @At("HEAD"), cancellable = true)
private static void of(final CameraType cameraType, final boolean shoulderSurfing, final CallbackInfoReturnable<Perspective> cir) {
if (cameraType == SableCameraTypes.SUB_LEVEL_VIEW) {
cir.setReturnValue(SablePerspectives.SUB_LEVEL_VIEW);
}
if (cameraType == SableCameraTypes.SUB_LEVEL_VIEW_UNLOCKED) {
cir.setReturnValue(SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.ryanhcode.sable.mixin.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.client.ShoulderSurfingCamera;
import com.llamalad7.mixinextras.sugar.Local;
import dev.ryanhcode.sable.Sable;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ShoulderSurfingCamera.class)
public class ShoulderSurfingCameraMixin {

@Redirect(method = "maxZoom", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;distanceTo(Lnet/minecraft/world/phys/Vec3;)D"))
private static double distanceTo(final Vec3 instance, final Vec3 vec, @Local(argsOnly = true) final BlockGetter level) {
return level instanceof Level ? Math.sqrt(Sable.HELPER.distanceSquaredWithSubLevels((Level) level, instance, vec)) : instance.distanceTo(vec);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.ryanhcode.sable.mixin.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.api.client.IClientConfig;
import com.github.exopandora.shouldersurfing.api.model.Perspective;
import com.github.exopandora.shouldersurfing.client.ShoulderSurfingImpl;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.ryanhcode.sable.Sable;
import dev.ryanhcode.sable.mixinhelpers.compatibility.shouldersurfing.SablePerspectives;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ShoulderSurfingImpl.class)
public class ShoulderSurfingImplMixin {

@WrapOperation(method = "togglePerspective", at = @At(value = "INVOKE", target = "Lcom/github/exopandora/shouldersurfing/api/model/Perspective;next(Lcom/github/exopandora/shouldersurfing/api/client/IClientConfig;)Lcom/github/exopandora/shouldersurfing/api/model/Perspective;"))
public Perspective next(final Perspective instance, final IClientConfig config, final Operation<Perspective> original) {
final Entity cameraEntity = Minecraft.getInstance().cameraEntity;

Perspective next = original.call(instance, config);
while (next == SablePerspectives.SUB_LEVEL_VIEW || next == SablePerspectives.SUB_LEVEL_VIEW_UNLOCKED) {
if (cameraEntity != null && Sable.HELPER.getVehicleSubLevel(cameraEntity) != null) {
break;
}
next = original.call(next, config);
}
return next;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import net.minecraft.client.CameraType;

public class SableCameraTypes {
public final class SableCameraTypes {

public static final CameraType SUB_LEVEL_VIEW = Enum.valueOf(CameraType.class, "SUB_LEVEL_VIEW");
public static final CameraType SUB_LEVEL_VIEW_UNLOCKED = Enum.valueOf(CameraType.class, "SUB_LEVEL_VIEW_UNLOCKED");

private SableCameraTypes() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.ryanhcode.sable.mixinhelpers.compatibility.shouldersurfing;

import com.github.exopandora.shouldersurfing.api.model.Perspective;

public class SablePerspectives {

public static final Perspective SUB_LEVEL_VIEW = Enum.valueOf(Perspective.class, "SUB_LEVEL_VIEW");
public static final Perspective SUB_LEVEL_VIEW_UNLOCKED = Enum.valueOf(Perspective.class, "SUB_LEVEL_VIEW_UNLOCKED");

private SablePerspectives() {
}
}
5 changes: 5 additions & 0 deletions common/src/main/resources/sable.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"clip_overwrite.ClientLevelMixin",
"clip_overwrite.GameRendererMixin",
"compatibility.iris.ExtendedShaderMixin",
"compatibility.shouldersurfing.ObjectPickerMixin",
"config.GameRendererAccessor",
"debug_render.DebugRendererMixin",
"debug_render.DebugScreenOverlayMixin",
Expand Down Expand Up @@ -102,6 +103,10 @@
"compatibility.jade.BlockAccessorImplMixin",
"compatibility.jade.RayTracingMixin",
"compatibility.jadeaddons.CreatePluginMixin",
"compatibility.shouldersurfing.EntityHelperMixin",
"compatibility.shouldersurfing.PerspectiveMixin",
"compatibility.shouldersurfing.ShoulderSurfingCameraMixin",
"compatibility.shouldersurfing.ShoulderSurfingImplMixin",
"compatibility.vista.LODMixin",
"compatibility.vista.ViewFinderAccessMixin",
"compatibility.vista.ViewFinderControllerMixin",
Expand Down
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
modCompileOnly "net.caffeinemc:sodium-fabric:${rootProject.sodium_version}"
modCompileOnly "maven.modrinth:distanthorizons:${rootProject.distant_horizons_version}"
modCompileOnly "maven.modrinth:sodium-extras:fabric-${minecraft_version}-$sodiumextras_version"
modCompileOnly "maven.modrinth:shoulder-surfing-reloaded:${minecraft_version}-${project.shouldersurfing_version}+fabric"

include(modApi("foundry.veil:veil-fabric-${project.minecraft_version}:${project.veil_version}"))
modCompileOnly("foundry.imguimc:imguimc-fabric-${project.minecraft_version}:${project.imguimc_version}")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ iris_version=1.8.12+1.21.1-neoforge
distant_horizons_version=2.2.1-a-1.21.1
nml_version=1.4.3
sodiumextras_version=1.0.8
shouldersurfing_version=4.22.10

loom.ignoreDependencyLoomVersionValidation=true

Expand Down
3 changes: 2 additions & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ dependencies {
implementation("com.tterrag.registrate:Registrate:${registrate_version}")

compileOnly("maven.modrinth:protomanlys-weather:${pmweather_version}")
compileOnly("io.github.mortuusars.exposure:exposure-${minecraft_version}-neoforge:${exposure_version}") { transitive = false }
compileOnly("io.github.mortuusars.exposure:exposure-${minecraft_version}-neoforge:${project.exposure_version}") { transitive = false }
compileOnly("maven.modrinth:jade:${project.jade_version}+neoforge") { transitive = false }
compileOnly("maven.modrinth:jade-addons-forge:${project.jade_addons_version}+neoforge") { transitive = false }
compileOnly("maven.modrinth:shoulder-surfing-reloaded:${minecraft_version}-${project.shouldersurfing_version}+neoforge") { transitive = false }

compileOnly "net.caffeinemc:sodium-neoforge-mod:${sodium_version}"
compileOnly("maven.modrinth:iris:$iris_version") { transitive = false }
Expand Down