Skip to content

Commit

Permalink
- Fixed OptiFabric crash
Browse files Browse the repository at this point in the history
- Mod no longer uses ModifyArgs mixins
  • Loading branch information
hashalite committed Feb 27, 2022
1 parent 359d4ed commit 9f3e8f6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,13 +18,4 @@ private void onIsCamera(CallbackInfoReturnable<Boolean> 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);
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/net/xolt/freecam/mixins/EntityRendererMixin.java
Original file line number Diff line number Diff line change
@@ -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<Integer> cir) {
if (Freecam.isEnabled() && ModConfig.INSTANCE.showHand && entity.equals(MC.player)) {
FreeCamera freeCamera = Freecam.getFreeCamera();
EntityRenderer<? super FreeCamera> entityRenderer = MC.getEntityRenderDispatcher().getRenderer(freeCamera);
cir.setReturnValue(entityRenderer.getLight(freeCamera, tickDelta));
}
}
}
21 changes: 0 additions & 21 deletions src/main/java/net/xolt/freecam/mixins/GameRendererMixin.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/net/xolt/freecam/mixins/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -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<Float> 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));
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/xolt/freecam/util/FreeCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/freecam.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerMixin",
"EntityMixin",
"EntityRendererMixin",
"GameOptionsMixin",
"GameRendererMixin",
"InGameHudMixin",
"LivingEntityMixin",
"MinecraftClientMixin",
"PlayerEntityMixin"
],
Expand Down

0 comments on commit 9f3e8f6

Please sign in to comment.