Skip to content

Commit

Permalink
make velocity affect explosion knockback and make initial velocity be…
Browse files Browse the repository at this point in the history
… mantained

reported in #21
  • Loading branch information
DaMatrix committed Aug 5, 2021
1 parent 1a464ee commit d68cd15
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
package net.daporkchop.pepsimod.asm.core.client.network;

import net.daporkchop.pepsimod.module.impl.misc.AnnouncerMod;
import net.daporkchop.pepsimod.module.impl.movement.VelocityMod;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.network.play.server.SPacketExplosion;
import net.minecraft.network.play.server.SPacketPlayerListItem;
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.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Map;
Expand Down Expand Up @@ -67,4 +70,25 @@ public void preHandlePlayerListItem(SPacketPlayerListItem listItem, CallbackInfo
} catch (NullPointerException e) {
}
}

@Redirect(method = "Lnet/minecraft/client/network/NetHandlerPlayClient;handleExplosion(Lnet/minecraft/network/play/server/SPacketExplosion;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/play/server/SPacketExplosion;getMotionX()F"))
private float pepsimod_handleExplosion_adjustMotionX(SPacketExplosion packet) {
return packet.getMotionX() * VelocityMod.INSTANCE.getVelocity();
}

@Redirect(method = "Lnet/minecraft/client/network/NetHandlerPlayClient;handleExplosion(Lnet/minecraft/network/play/server/SPacketExplosion;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/play/server/SPacketExplosion;getMotionY()F"))
private float pepsimod_handleExplosion_adjustMotionY(SPacketExplosion packet) {
return packet.getMotionY() * VelocityMod.INSTANCE.getVelocity();
}

@Redirect(method = "Lnet/minecraft/client/network/NetHandlerPlayClient;handleExplosion(Lnet/minecraft/network/play/server/SPacketExplosion;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/play/server/SPacketExplosion;getMotionZ()F"))
private float pepsimod_handleExplosion_adjustMotionZ(SPacketExplosion packet) {
return packet.getMotionZ() * VelocityMod.INSTANCE.getVelocity();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Adapted from The MIT License (MIT)
*
* Copyright (c) 2016-2020 DaPorkchop_
* Copyright (c) 2016-2021 DaPorkchop_
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
Expand Down Expand Up @@ -59,16 +59,15 @@ public abstract class MixinEntity {
@Inject(
method = "Lnet/minecraft/entity/Entity;setVelocity(DDD)V",
at = @At("HEAD"),
cancellable = true
)
cancellable = true)
public void preSetVelocity(double x, double y, double z, CallbackInfo callbackInfo) {
float strength = 1.0f;
if (Entity.class.cast(this) == mc.player) {
if ((Object) this == mc.player) {
strength = VelocityMod.INSTANCE.getVelocity();
}
this.motionX = x * strength;
this.motionY = y * strength;
this.motionZ = z * strength;
this.motionX = this.motionX * (1.0f - strength) + x * strength;
this.motionY = this.motionY * (1.0f - strength) + y * strength;
this.motionZ = this.motionZ * (1.0f - strength) + z * strength;
callbackInfo.cancel();
}

Expand Down

0 comments on commit d68cd15

Please sign in to comment.