Skip to content

Commit

Permalink
Actually fix explosion knockback
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaider10 committed Oct 19, 2021
1 parent 4bb6066 commit 3a22b0c
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package me.andrew.gravitychanger.mixin.client;

import me.andrew.gravitychanger.accessor.EntityAccessor;
import me.andrew.gravitychanger.util.RotationUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Shadow @Final private MinecraftClient client;

@Redirect(
method = "onGameStateChange",
at = @At(
Expand Down Expand Up @@ -60,4 +68,21 @@ private double redirect_onGameStateChange_getZ_0(PlayerEntity playerEntity) {

return playerEntity.getEyePos().z;
}

@Redirect(
method = "onExplosion",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/util/math/Vec3d;add(DDD)Lnet/minecraft/util/math/Vec3d;",
ordinal = 0
)
)
private Vec3d redirect_onExplosion_add_0(Vec3d vec3d, double x, double y, double z) {
Direction gravityDirection = ((EntityAccessor) this.client.player).gravitychanger$getAppliedGravityDirection();
if(gravityDirection == Direction.DOWN) {
return vec3d.add(x, y, z);
}

return vec3d.add(RotationUtil.vecWorldToPlayer(x, y, z, gravityDirection));
}
}

0 comments on commit 3a22b0c

Please sign in to comment.