-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
NoFallHack.java
96 lines (81 loc) · 2.68 KB
/
NoFallHack.java
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.OnGroundOnly;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.CheckboxSetting;
@SearchTags({"no fall"})
public final class NoFallHack extends Hack implements UpdateListener
{
private final CheckboxSetting allowElytra = new CheckboxSetting(
"Allow elytra",
"Also tries to prevent fall damage while you are flying with an elytra.\n\n"
+ "\u00a7c\u00a7lWARNING:\u00a7r This can sometimes cause you to"
+ " stop flying unexpectedly.",
false);
public NoFallHack()
{
super("NoFall");
setCategory(Category.MOVEMENT);
addSetting(allowElytra);
}
@Override
public String getRenderName()
{
ClientPlayerEntity player = MC.player;
if(player == null)
return getName();
if(player.isFallFlying() && !allowElytra.isChecked())
return getName() + " (paused)";
if(player.isCreative())
return getName() + " (paused)";
return getName();
}
@Override
protected void onEnable()
{
EVENTS.add(UpdateListener.class, this);
}
@Override
protected void onDisable()
{
EVENTS.remove(UpdateListener.class, this);
}
@Override
public void onUpdate()
{
// do nothing in creative mode, since there is no fall damage anyway
ClientPlayerEntity player = MC.player;
if(player.isCreative())
return;
// pause when flying with elytra, unless allowed
boolean fallFlying = player.isFallFlying();
if(fallFlying && !allowElytra.isChecked())
return;
// ignore small falls that can't cause damage,
// unless CreativeFlight is enabled in survival mode
boolean creativeFlying = WURST.getHax().creativeFlightHack.isEnabled()
&& player.getAbilities().flying;
if(!creativeFlying && player.fallDistance <= (fallFlying ? 1 : 2))
return;
// attempt to fix elytra weirdness, if allowed
if(fallFlying && player.isSneaking()
&& !isFallingFastEnoughToCauseDamage(player))
return;
// send packet to stop fall damage
player.networkHandler.sendPacket(new OnGroundOnly(true));
}
private boolean isFallingFastEnoughToCauseDamage(ClientPlayerEntity player)
{
return player.getVelocity().y < -0.5;
}
}