forked from MeteorDevelopment/meteor-client
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMinecraftClientMixin.java
More file actions
288 lines (237 loc) · 11.9 KB
/
Copy pathMinecraftClientMixin.java
File metadata and controls
288 lines (237 loc) · 11.9 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/
package meteordevelopment.meteorclient.mixin;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent;
import meteordevelopment.meteorclient.events.game.GameLeftEvent;
import meteordevelopment.meteorclient.events.game.OpenScreenEvent;
import meteordevelopment.meteorclient.events.game.ResolutionChangedEvent;
import meteordevelopment.meteorclient.events.game.ResourcePacksReloadedEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.gui.WidgetScreen;
import meteordevelopment.meteorclient.mixininterface.IMinecraftClient;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.movement.GUIMove;
import meteordevelopment.meteorclient.systems.modules.player.FastUse;
import meteordevelopment.meteorclient.systems.modules.player.Multitask;
import meteordevelopment.meteorclient.systems.modules.render.ESP;
import meteordevelopment.meteorclient.systems.modules.world.HighwayBuilder;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.CPSUtils;
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
import meteordevelopment.meteorclient.utils.network.OnlinePlayers;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.Window;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.ReloadableResourceManagerImpl;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.profiler.Profilers;
import org.jetbrains.annotations.Nullable;
import org.meteordev.starscript.Script;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.concurrent.CompletableFuture;
@Mixin(value = MinecraftClient.class, priority = 1001)
public abstract class MinecraftClientMixin implements IMinecraftClient {
@Unique private boolean doItemUseCalled;
@Unique private boolean rightClick;
@Unique private long lastTime;
@Unique private boolean firstFrame;
@Shadow public ClientWorld world;
@Shadow @Final public Mouse mouse;
@Shadow @Final private Window window;
@Shadow public Screen currentScreen;
@Shadow @Final public GameOptions options;
@Shadow protected abstract void doItemUse();
@Shadow
@Nullable
public ClientPlayerInteractionManager interactionManager;
@Shadow
private int itemUseCooldown;
@Shadow
@Nullable
public ClientPlayerEntity player;
@Shadow
@Final
private ReloadableResourceManagerImpl resourceManager;
@Shadow
@Final
@Mutable
private Framebuffer framebuffer;
@Inject(method = "<init>", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
MeteorClient.INSTANCE.onInitializeClient();
firstFrame = true;
}
@Inject(at = @At("HEAD"), method = "tick")
private void onPreTick(CallbackInfo info) {
OnlinePlayers.update();
doItemUseCalled = false;
Profilers.get().push(MeteorClient.MOD_ID + "_pre_update");
MeteorClient.EVENT_BUS.post(TickEvent.Pre.get());
Profilers.get().pop();
if (rightClick && !doItemUseCalled && interactionManager != null) doItemUse();
rightClick = false;
}
@Inject(at = @At("TAIL"), method = "tick")
private void onTick(CallbackInfo info) {
Profilers.get().push(MeteorClient.MOD_ID + "_post_update");
MeteorClient.EVENT_BUS.post(TickEvent.Post.get());
Profilers.get().pop();
}
@Inject(method = "doAttack", at = @At("HEAD"))
private void onAttack(CallbackInfoReturnable<Boolean> cir) {
CPSUtils.onAttack();
}
@Inject(method = "doItemUse", at = @At("HEAD"))
private void onDoItemUse(CallbackInfo info) {
doItemUseCalled = true;
}
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At("HEAD"))
private void onDisconnect(Screen screen, boolean transferring, CallbackInfo info) {
if (world != null) {
MeteorClient.EVENT_BUS.post(GameLeftEvent.get());
}
}
@Inject(method = "setScreen", at = @At("HEAD"), cancellable = true)
private void onSetScreen(Screen screen, CallbackInfo info) {
if (screen instanceof WidgetScreen) screen.mouseMoved(mouse.getX() * window.getScaleFactor(), mouse.getY() * window.getScaleFactor());
OpenScreenEvent event = OpenScreenEvent.get(screen);
MeteorClient.EVENT_BUS.post(event);
if (event.isCancelled()) info.cancel();
}
@WrapOperation(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
private void onSetScreenKeyBindingUnpressAll(Operation<Void> op) {
Modules modules = Modules.get();
if (modules == null) {
op.call();
return;
}
GUIMove guimove = modules.get(GUIMove.class);
if (guimove == null || !guimove.isActive() || guimove.skip()) {
op.call();
return;
}
GameOptions options = MeteorClient.mc.options;
for (KeyBinding kb : KeyBindingAccessor.getKeysById().values()) {
if (kb == options.forwardKey) continue;
if (kb == options.leftKey) continue;
if (kb == options.rightKey) continue;
if (kb == options.backKey) continue;
if (guimove.sneak.get() && kb == options.sneakKey) continue;
if (guimove.sprint.get() && kb == options.sprintKey) continue;
if (guimove.jump.get() && kb == options.jumpKey) continue;
((KeyBindingAccessor) kb).meteor$invokeReset();
}
}
@Inject(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isItemEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z"))
private void onDoItemUseHand(CallbackInfo ci, @Local ItemStack itemStack) {
FastUse fastUse = Modules.get().get(FastUse.class);
if (fastUse.isActive()) {
itemUseCooldown = fastUse.getItemUseCooldown(itemStack);
}
}
@ModifyExpressionValue(method = "doItemUse", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;", ordinal = 1))
private HitResult doItemUseMinecraftClientCrosshairTargetProxy(HitResult original) {
return MeteorClient.EVENT_BUS.post(ItemUseCrosshairTargetEvent.get(original)).target;
}
@ModifyReturnValue(method = "reloadResources(ZLnet/minecraft/client/MinecraftClient$LoadingContext;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"))
private CompletableFuture<Void> onReloadResourcesNewCompletableFuture(CompletableFuture<Void> original) {
return original.thenRun(() -> MeteorClient.EVENT_BUS.post(ResourcePacksReloadedEvent.get()));
}
@ModifyArg(method = "updateWindowTitle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;setTitle(Ljava/lang/String;)V"))
private String setTitle(String original) {
if (Config.get() == null || !Config.get().customWindowTitle.get()) return original;
String customTitle = Config.get().customWindowTitleText.get();
Script script = MeteorStarscript.compile(customTitle);
if (script != null) {
String title = MeteorStarscript.run(script);
if (title != null) customTitle = title;
}
return customTitle;
}
// Have to add this condition if we want to draw back a bow using packets, without it getting cancelled by vanilla code
@WrapWithCondition(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;stopUsingItem(Lnet/minecraft/entity/player/PlayerEntity;)V"))
private boolean wrapStopUsing(ClientPlayerInteractionManager instance, PlayerEntity player) {
return HB$stopUsingItem();
}
@Unique
private boolean HB$stopUsingItem() {
HighwayBuilder b = Modules.get().get(HighwayBuilder.class);
return !b.isActive() || !b.drawingBow;
}
@Inject(method = "onResolutionChanged", at = @At("TAIL"))
private void onResolutionChanged(CallbackInfo info) {
MeteorClient.EVENT_BUS.post(ResolutionChangedEvent.get());
}
// Time delta
@Inject(method = "render", at = @At("HEAD"))
private void onRender(CallbackInfo info) {
long time = System.currentTimeMillis();
if (firstFrame) {
lastTime = time;
firstFrame = false;
}
Utils.frameTime = (time - lastTime) / 1000.0;
lastTime = time;
}
// Multitask
@ModifyExpressionValue(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
private boolean doItemUseModifyIsBreakingBlock(boolean original) {
return !Modules.get().isActive(Multitask.class) && original;
}
@ModifyExpressionValue(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
private boolean handleBlockBreakingModifyIsUsingItem(boolean original) {
return !Modules.get().isActive(Multitask.class) && original;
}
@ModifyExpressionValue(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z", ordinal = 0))
private boolean handleInputEventsModifyIsUsingItem(boolean original) {
return !Modules.get().get(Multitask.class).attackingEntities() && original;
}
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z", ordinal = 0, shift = At.Shift.BEFORE))
private void handleInputEventsInjectStopUsingItem(CallbackInfo info) {
if (Modules.get().get(Multitask.class).attackingEntities() && player.isUsingItem()) {
if (!options.useKey.isPressed() && HB$stopUsingItem()) interactionManager.stopUsingItem(player);
while (options.useKey.wasPressed());
}
}
// Glow esp
@ModifyReturnValue(method = "hasOutline", at = @At("RETURN"))
private boolean hasOutlineModifyIsOutline(boolean original, Entity entity) {
if (ESP.get() == null) return original;
if (!ESP.isGlow() || ESP.shouldSkip(entity)) return original;
return ESP.getColor(entity) != null || original;
}
// Interface
@Override
public void meteor$rightClick() {
rightClick = true;
}
@Override
public void meteor$setFramebuffer(Framebuffer framebuffer) {
this.framebuffer = framebuffer;
}
}