aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java
blob: 7f69197dc2fc930ae2451627394b8446838bef94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ftbsc.bscv.modules.self;

import ftbsc.bscv.ICommons;
import ftbsc.bscv.events.PacketEvent;
import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.client.CEntityActionPacket;
import net.minecraft.network.play.client.CPlayerPacket;
import net.minecraft.network.play.client.CEntityActionPacket.Action;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class AntiHunger extends AbstractModule implements ICommons {
   @Override
   public String getName() {
      return "AntiHunger";
   }

   @Override
   public Group getGroup() {
      return Group.SELF;
   }

   public final ForgeConfigSpec.ConfigValue<Boolean> sprint;
   public final ForgeConfigSpec.ConfigValue<Boolean> hover;

   public AntiHunger() {
      super();

      this.sprint = Setting.Bool.builder()
         .fallback(true)
         .name("sprint")
         .comment("mask sprint toggle packets")
         .build(this);

      this.hover = Setting.Bool.builder()
         .name("hover")
         .comment("mark as not on-ground while walking")
         .fallback(true)
         .build(this);
   }

   @SubscribeEvent
   public void onPacket(PacketEvent event) {
      if (!event.outgoing) return;
      if (this.sprint.get() && event.packet instanceof CEntityActionPacket) {
         CEntityActionPacket packet = (CEntityActionPacket) event.packet;
         if (
            packet.getAction() == Action.START_SPRINTING ||
            packet.getAction() == Action.STOP_SPRINTING
         ) {
            event.setCanceled(true);
         }
      }

      if (
         this.hover.get()
         && event.packet instanceof CPlayerPacket
         && MC.player != null
         && MC.player.fallDistance <= 0.f
         && !MC.gameMode.isDestroying()
      ) {
         CPlayerPacket packet = (CPlayerPacket) event.packet;
         packet.onGround = false; // ACCESSTRANSFORMER public net.minecraft.network.play.client.CPlayerPacket field_149474_g
      }
   }
}