Skip to content

Commit

Permalink
Made the Jump event actually cancel jump + A Verus fly improvement. (C…
Browse files Browse the repository at this point in the history
…CBlueX#621)

* Fixed canceled Jump event giving boosts when trying to jump + A Verus fly improvement.

* Added a fluid block check, we don't need to cause Jesus checks

* Fixed Jump event not detecting leaping potions.
  • Loading branch information
mems01 authored Oct 17, 2021
1 parent 6b80723 commit e342002
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ protected static Vec3d movementInputToVelocity(Vec3d movementInput, float speed,

@Shadow public abstract double getZ();

@Shadow public abstract float getYaw();

/**
* Hook entity margin modification event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoJumpDelay;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoPush;
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleAntiBlind;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -45,6 +47,9 @@
@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends MixinEntity {

@Shadow
private int jumpingCooldown;

@Shadow
protected abstract float getJumpVelocity();

Expand All @@ -59,7 +64,7 @@ public abstract class MixinLivingEntity extends MixinEntity {
public abstract ItemStack getMainHandStack();

@Shadow
private int jumpingCooldown;
public abstract double getJumpBoostVelocityModifier();

@Shadow protected abstract void jump();

Expand Down Expand Up @@ -87,19 +92,26 @@ private void hookAntiNausea(StatusEffect effect, CallbackInfoReturnable<Boolean>
}
}

@Redirect(method = "jump", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getJumpVelocity()F"))
private float hookJumpEvent(LivingEntity entity) {
// Check if entity is client user
if ((Object) this == MinecraftClient.getInstance().player) {
// Hook player jump event
final PlayerJumpEvent jumpEvent = new PlayerJumpEvent(getJumpVelocity());
EventManager.INSTANCE.callEvent(jumpEvent);
if (jumpEvent.isCancelled()) {
return 0f;
}
return jumpEvent.getMotion();
/**
* @author mems01
*/
@Overwrite
public void jump() {
final PlayerJumpEvent jumpEvent = new PlayerJumpEvent(getJumpVelocity());
EventManager.INSTANCE.callEvent(jumpEvent);
if (jumpEvent.isCancelled()) {
return;
}

double d = jumpEvent.getMotion() + getJumpBoostVelocityModifier();
Vec3d vec3d = this.getVelocity();
this.setVelocity(vec3d.x, d, vec3d.z);
if (this.isSprinting()) {
float f = this.getYaw() * 0.017453292F;
this.setVelocity(this.getVelocity().add(-MathHelper.sin(f) * 0.2F, 0.0D, MathHelper.cos(f) * 0.2F));
}
return getJumpVelocity();

this.velocityDirty = true;
}

@Inject(method = "pushAwayFrom", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.entity.strafe
import net.minecraft.block.Blocks
import net.minecraft.block.FluidBlock
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket
import net.minecraft.util.shape.VoxelShapes

Expand Down Expand Up @@ -93,7 +94,7 @@ object ModuleFly : Module("Fly", Category.MOVEMENT) {
}
}
val shapeHandler = handler<BlockShapeEvent> { event ->
if (event.state.block == Blocks.AIR && event.pos.y < player.y) {
if (event.state.block !is FluidBlock && event.pos.y < player.y) {
event.shape = VoxelShapes.fullCube()
}
}
Expand Down

0 comments on commit e342002

Please sign in to comment.