| 1 | package com.jellypudding.offlineclient.mixin;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.OfflineClient;
|
| 4 | import com.jellypudding.offlineclient.modules.combat.Hitboxes;
|
| 5 | import com.jellypudding.offlineclient.modules.movement.AntiPush;
|
| 6 | import com.jellypudding.offlineclient.modules.movement.Flight;
|
| 7 | import com.jellypudding.offlineclient.modules.movement.NoSlowdown;
|
| 8 | import com.jellypudding.offlineclient.modules.movement.NoFall;
|
| 9 | import com.jellypudding.offlineclient.modules.movement.Step;
|
| 10 | import com.jellypudding.offlineclient.modules.render.NoRender;
|
| 11 | import com.jellypudding.offlineclient.util.Modules;
|
| 12 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
| 13 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
| 14 | import net.minecraft.core.Direction;
|
| 15 | import net.minecraft.world.entity.Entity;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 | import org.spongepowered.asm.mixin.Mixin;
|
| 18 | import org.spongepowered.asm.mixin.Shadow;
|
| 19 | import org.spongepowered.asm.mixin.injection.At;
|
| 20 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 21 | import org.spongepowered.asm.mixin.injection.ModifyArg;
|
| 22 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 23 |
|
| 24 | @Mixin(Entity.class)
|
| 25 | public abstract class EntityMixin {
|
| 26 |
|
| 27 | @Shadow
|
| 28 | public boolean verticalCollisionBelow;
|
| 29 |
|
| 30 | // The pick radius inflates the box the crosshair tests against.
|
| 31 | @Inject(method = "getPickRadius", at = @At("HEAD"), cancellable = true)
|
| 32 | private void onGetPickRadius(CallbackInfoReturnable<Float> cir) {
|
| 33 | Hitboxes hitboxes = Modules.get(Hitboxes.class);
|
| 34 | if (hitboxes == null) {
|
| 35 | return;
|
| 36 | }
|
| 37 | double extra = hitboxes.expansionFor((Entity) (Object) this);
|
| 38 | if (extra > 0) {
|
| 39 | cir.setReturnValue((float) extra);
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | @Inject(method = "isCurrentlyGlowing()Z", at = @At("HEAD"), cancellable = true)
|
| 44 | private void onIsCurrentlyGlowing(CallbackInfoReturnable<Boolean> cir) {
|
| 45 | NoRender noRender = Modules.get(NoRender.class);
|
| 46 | if (noRender != null && noRender.hidesGlowing()) {
|
| 47 | cir.setReturnValue(false);
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | // Flight through fluids and NoSlowdown fluid drag. The local player is never in
|
| 52 | // water or lava as far as the physics and the swimming pose are concerned.
|
| 53 | @Inject(method = {"isInWater()Z", "isInLava()Z", "isUnderWater()Z"},
|
| 54 | at = @At("HEAD"), cancellable = true)
|
| 55 | private void onFluidCheck(CallbackInfoReturnable<Boolean> cir) {
|
| 56 | if ((Object) this != OfflineClient.MC.player) {
|
| 57 | return;
|
| 58 | }
|
| 59 | Flight flight = Modules.active(Flight.class);
|
| 60 | NoSlowdown noSlowdown = Modules.get(NoSlowdown.class);
|
| 61 | if ((flight != null && flight.throughFluids())
|
| 62 | || (noSlowdown != null && noSlowdown.skipsFluidDrag())) {
|
| 63 | cir.setReturnValue(false);
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | // Slime and beds ask this before they bounce. NoFall answers yes to every landing.
|
| 68 | @Inject(method = "isSuppressingBounce()Z", at = @At("HEAD"), cancellable = true)
|
| 69 | private void onIsSuppressingBounce(CallbackInfoReturnable<Boolean> cir) {
|
| 70 | if ((Object) this != OfflineClient.MC.player) {
|
| 71 | return;
|
| 72 | }
|
| 73 | NoFall noFall = Modules.get(NoFall.class);
|
| 74 | if (noFall != null && noFall.suppressesBounce()) {
|
| 75 | cir.setReturnValue(true);
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | // A crowd shove reaches the player only through this call. AntiPush keeps a share of it.
|
| 80 | @WrapOperation(method = "push(Lnet/minecraft/world/entity/Entity;)V",
|
| 81 | at = @At(value = "INVOKE",
|
| 82 | target = "Lnet/minecraft/world/entity/Entity;push(DDD)V"))
|
| 83 | private void onPushedByEntity(Entity pushed, double x, double y, double z,
|
| 84 | Operation<Void> original) {
|
| 85 | AntiPush antiPush = pushed == OfflineClient.MC.player ? Modules.get(AntiPush.class) : null;
|
| 86 | double scale = antiPush == null ? 1 : antiPush.entityPushScale();
|
| 87 | original.call(pushed, x * scale, y, z * scale);
|
| 88 | }
|
| 89 |
|
| 90 | // Step raising the step height makes a stepped landing look like a big collision.
|
| 91 | // That would launch the player off slime or a bed. The y component is zeroed here.
|
| 92 | @ModifyArg(method = "move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V",
|
| 93 | at = @At(value = "INVOKE",
|
| 94 | target = "Lnet/minecraft/world/entity/Entity;restituteMovementAfterCollisions(Lnet/minecraft/world/level/block/state/BlockState;ZZLnet/minecraft/world/phys/Vec3;)V"),
|
| 95 | index = 3)
|
| 96 | private Vec3 flattenSteppedLanding(Vec3 collided) {
|
| 97 | if ((Object) this != OfflineClient.MC.player || !verticalCollisionBelow || collided.y <= 0) {
|
| 98 | return collided;
|
| 99 | }
|
| 100 | Step step = Modules.get(Step.class);
|
| 101 | if (step == null || !step.raisesStepHeight()) {
|
| 102 | return collided;
|
| 103 | }
|
| 104 | return collided.with(Direction.Axis.Y, 0);
|
| 105 | }
|
| 106 | }
|
| 107 |
|