From 9f3e8f676db5aa30f73fd88897e5c2fad7a4ea28 Mon Sep 17 00:00:00 2001 From: hashalite Date: Sun, 27 Feb 2022 17:56:51 -0500 Subject: [PATCH] - Fixed OptiFabric crash - Mod no longer uses ModifyArgs mixins --- gradle.properties | 2 +- .../mixins/ClientPlayerEntityMixin.java | 13 ---------- .../freecam/mixins/EntityRendererMixin.java | 26 +++++++++++++++++++ .../freecam/mixins/GameRendererMixin.java | 21 --------------- .../freecam/mixins/LivingEntityMixin.java | 20 ++++++++++++++ .../net/xolt/freecam/util/FreeCamera.java | 4 +-- src/main/resources/freecam.mixins.json | 3 ++- 7 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 src/main/java/net/xolt/freecam/mixins/EntityRendererMixin.java delete mode 100644 src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java create mode 100644 src/main/java/net/xolt/freecam/mixins/LivingEntityMixin.java diff --git a/gradle.properties b/gradle.properties index be456c6e..ef4111fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.18.1 yarn_mappings=1.18.1+build.22 loader_version=0.13.1 # Mod Properties -mod_version=0.4.6 +mod_version=0.4.7 maven_group=net.xolt archives_base_name=freecam # Dependencies diff --git a/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java b/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java index af0b65e8..2be7d28c 100644 --- a/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java +++ b/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java @@ -2,14 +2,10 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.xolt.freecam.Freecam; -import net.xolt.freecam.config.ModConfig; -import net.xolt.freecam.util.FreeCamera; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import static net.xolt.freecam.Freecam.MC; @@ -22,13 +18,4 @@ private void onIsCamera(CallbackInfoReturnable cir) { cir.setReturnValue(true); } } - - @ModifyArgs(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;add(DDD)Lnet/minecraft/util/math/Vec3d;")) - private void onTickMovement(Args args) { - if (Freecam.isEnabled() && ModConfig.INSTANCE.flightMode.equals(ModConfig.FlightMode.CREATIVE) && this.equals(Freecam.getFreeCamera())) { - FreeCamera freeCamera = Freecam.getFreeCamera(); - int verticalMovement = (freeCamera.input.jumping ? 1 : 0) - (freeCamera.input.sneaking ? 1 : 0); - args.set(1, (float) verticalMovement * (ModConfig.INSTANCE.verticalSpeed / 10) * 3.0F); - } - } } diff --git a/src/main/java/net/xolt/freecam/mixins/EntityRendererMixin.java b/src/main/java/net/xolt/freecam/mixins/EntityRendererMixin.java new file mode 100644 index 00000000..6a031573 --- /dev/null +++ b/src/main/java/net/xolt/freecam/mixins/EntityRendererMixin.java @@ -0,0 +1,26 @@ +package net.xolt.freecam.mixins; + +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; +import net.xolt.freecam.Freecam; +import net.xolt.freecam.config.ModConfig; +import net.xolt.freecam.util.FreeCamera; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import static net.xolt.freecam.Freecam.MC; + +@Mixin(EntityRenderer.class) +public class EntityRendererMixin { + + @Inject(method = "getLight", at = @At("HEAD"), cancellable = true) + private void onGetLight(Entity entity, float tickDelta, CallbackInfoReturnable cir) { + if (Freecam.isEnabled() && ModConfig.INSTANCE.showHand && entity.equals(MC.player)) { + FreeCamera freeCamera = Freecam.getFreeCamera(); + EntityRenderer entityRenderer = MC.getEntityRenderDispatcher().getRenderer(freeCamera); + cir.setReturnValue(entityRenderer.getLight(freeCamera, tickDelta)); + } + } +} diff --git a/src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java b/src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java deleted file mode 100644 index 7c450e7b..00000000 --- a/src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.xolt.freecam.mixins; - -import net.minecraft.client.render.GameRenderer; -import net.minecraft.entity.Entity; -import net.xolt.freecam.Freecam; -import net.xolt.freecam.config.ModConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -@Mixin(GameRenderer.class) -public class GameRendererMixin { - - @ModifyArg(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;getLight(Lnet/minecraft/entity/Entity;F)I")) - private Entity onRenderHand(Entity entity) { - if (Freecam.isEnabled() && ModConfig.INSTANCE.showHand) { - return Freecam.getFreeCamera(); - } - return entity; - } -} diff --git a/src/main/java/net/xolt/freecam/mixins/LivingEntityMixin.java b/src/main/java/net/xolt/freecam/mixins/LivingEntityMixin.java new file mode 100644 index 00000000..7d7a3c4e --- /dev/null +++ b/src/main/java/net/xolt/freecam/mixins/LivingEntityMixin.java @@ -0,0 +1,20 @@ +package net.xolt.freecam.mixins; + +import net.minecraft.entity.LivingEntity; +import net.xolt.freecam.Freecam; +import net.xolt.freecam.config.ModConfig; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin { + + @Inject(method = "getMovementSpeed(F)F", at = @At("HEAD"), cancellable = true) + private void onGetMovementSpeed(CallbackInfoReturnable cir) { + if (Freecam.isEnabled() && ModConfig.INSTANCE.flightMode.equals(ModConfig.FlightMode.CREATIVE) && this.equals(Freecam.getFreeCamera())) { + cir.setReturnValue((float) (ModConfig.INSTANCE.horizontalSpeed / 10) * (Freecam.getFreeCamera().isSprinting() ? 2 : 1)); + } + } +} diff --git a/src/main/java/net/xolt/freecam/util/FreeCamera.java b/src/main/java/net/xolt/freecam/util/FreeCamera.java index d8987148..b599b2fc 100644 --- a/src/main/java/net/xolt/freecam/util/FreeCamera.java +++ b/src/main/java/net/xolt/freecam/util/FreeCamera.java @@ -24,6 +24,7 @@ public FreeCamera() { super(MC, MC.world, NETWORK_HANDLER, MC.player.getStatHandler(), MC.player.getRecipeBook(), false, false); copyPositionAndRotation(MC.player); + this.getAbilities().flying = true; this.getAbilities().allowModifyWorld = ModConfig.INSTANCE.allowBlockBreak; this.noClip = true; this.input = new KeyboardInput(MC.options); @@ -47,8 +48,7 @@ public void tickMovement() { input.tick(false); Motion.doMotion(this, ModConfig.INSTANCE.horizontalSpeed, ModConfig.INSTANCE.verticalSpeed); } else { - this.getAbilities().flying = true; - this.getAbilities().setFlySpeed((float) ModConfig.INSTANCE.horizontalSpeed / 10); + this.getAbilities().setFlySpeed((float) ModConfig.INSTANCE.verticalSpeed / 10); super.tickMovement(); } } diff --git a/src/main/resources/freecam.mixins.json b/src/main/resources/freecam.mixins.json index 05646bc6..201686ff 100644 --- a/src/main/resources/freecam.mixins.json +++ b/src/main/resources/freecam.mixins.json @@ -9,9 +9,10 @@ "ClientPlayerEntityMixin", "ClientPlayerInteractionManagerMixin", "EntityMixin", + "EntityRendererMixin", "GameOptionsMixin", - "GameRendererMixin", "InGameHudMixin", + "LivingEntityMixin", "MinecraftClientMixin", "PlayerEntityMixin" ],