-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMinecraftClientMixin.java
More file actions
221 lines (190 loc) · 9 KB
/
MinecraftClientMixin.java
File metadata and controls
221 lines (190 loc) · 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
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lambda.mixin;
import com.lambda.core.TimerManager;
import com.lambda.event.EventFlow;
import com.lambda.event.events.ClientEvent;
import com.lambda.event.events.InventoryEvent;
import com.lambda.event.events.TickEvent;
import com.lambda.gui.DearImGui;
import com.lambda.gui.components.ClickGuiLayout;
import com.lambda.module.modules.movement.BetterFirework;
import com.lambda.module.modules.player.Interact;
import com.lambda.module.modules.player.InventoryMove;
import com.lambda.module.modules.player.PacketMine;
import com.lambda.util.WindowUtils;
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.thread.ThreadExecutor;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = MinecraftClient.class, priority = Integer.MAX_VALUE)
public class MinecraftClientMixin {
@Shadow
@Nullable
public Screen currentScreen;
@Shadow
@Nullable
public HitResult crosshairTarget;
@Shadow
public int itemUseCooldown;
@Unique
private boolean lambda$inputHandledThisTick;
@Inject(method = "close", at = @At("HEAD"))
void closeImGui(CallbackInfo ci) {
DearImGui.INSTANCE.destroy();
}
@WrapMethod(method = "render")
void onLoopTick(boolean tick, Operation<Void> original) {
EventFlow.post(TickEvent.Render.Pre.INSTANCE);
original.call(tick);
EventFlow.post(TickEvent.Render.Post.INSTANCE);
}
@WrapMethod(method = "tick")
void onTick(Operation<Void> original) {
this.lambda$inputHandledThisTick = false;
EventFlow.post(TickEvent.Pre.INSTANCE);
original.call();
EventFlow.post(TickEvent.Post.INSTANCE);
}
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;tick()V"))
void onNetwork(ClientPlayerInteractionManager instance, Operation<Void> original) {
EventFlow.post(TickEvent.Network.Pre.INSTANCE);
original.call(instance);
EventFlow.post(TickEvent.Network.Post.INSTANCE);
}
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;handleInputEvents()V"))
void onInput(MinecraftClient instance, Operation<Void> original) {
EventFlow.post(TickEvent.Input.Pre.INSTANCE);
original.call(instance);
EventFlow.post(TickEvent.Input.Post.INSTANCE);
this.lambda$inputHandledThisTick = true;
}
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;tick()V"))
void onWorldRenderer(WorldRenderer instance, Operation<Void> original) {
if (!this.lambda$inputHandledThisTick) {
EventFlow.post(TickEvent.Input.Pre.INSTANCE);
EventFlow.post(TickEvent.Input.Post.INSTANCE);
this.lambda$inputHandledThisTick = true;
}
EventFlow.post(TickEvent.WorldRender.Pre.INSTANCE);
original.call(instance);
EventFlow.post(TickEvent.WorldRender.Post.INSTANCE);
}
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundManager;tick(Z)V"))
void onSound(SoundManager instance, boolean paused, Operation<Void> original) {
EventFlow.post(TickEvent.Sound.Pre.INSTANCE);
original.call(instance, paused);
EventFlow.post(TickEvent.Sound.Post.INSTANCE);
}
@Inject(at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;)V", shift = At.Shift.AFTER, remap = false), method = "stop")
private void onShutdown(CallbackInfo ci) {
EventFlow.post(new ClientEvent.Shutdown());
}
/**
* Inject after the thread field is set so that {@link ThreadExecutor#getThread} is available
*/
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0), method = "run")
private void onStartup(CallbackInfo ci) {
EventFlow.post(new ClientEvent.Startup());
}
@Inject(method = "setScreen", at = @At("HEAD"))
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
if (screen == null) return;
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
EventFlow.post(new InventoryEvent.Open(handledScreen.getScreenHandler()));
}
}
@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;removed()V", shift = At.Shift.AFTER))
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
if (currentScreen == null) return;
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
EventFlow.post(new InventoryEvent.Close(handledScreen.getScreenHandler()));
}
}
@Redirect(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
private void redirectUnPressAll() {
if (!InventoryMove.getShouldMove()) {
KeyBinding.unpressAll();
return;
}
KeyBinding.KEYS_BY_ID.values().forEach(bind -> {
if (!InventoryMove.isKeyMovementRelated(bind.boundKey.getCode())) {
bind.reset();
}
});
}
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
if (this.crosshairTarget == null) return;
if (this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled()) {
instance.swingHand(hand);
}
}
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
if (instance == null) return true;
if (Interact.INSTANCE.isEnabled() && Interact.getMultiAction()) return false;
return instance.isBreakingBlock();
}
@Inject(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isRiding()Z"))
void injectFastPlace(CallbackInfo ci) {
if (!Interact.INSTANCE.isEnabled()) return;
itemUseCooldown = Interact.getPlaceDelay();
}
@WrapMethod(method = "doItemUse")
void injectItemUse(Operation<Void> original) {
if (BetterFirework.INSTANCE.isDisabled() || !BetterFirework.onInteract())
original.call();
}
@WrapMethod(method = "doItemPick")
void injectItemPick(Operation<Void> original) {
if (BetterFirework.INSTANCE.isDisabled() || !BetterFirework.onPick())
original.call();
}
@WrapMethod(method = "getTargetMillisPerTick")
float getTargetMillisPerTick(float millis, Operation<Float> original) {
var length = TimerManager.INSTANCE.getLength();
if (length == TimerManager.DEFAULT_LENGTH)
return original.call(millis);
else
return (float) TimerManager.INSTANCE.getLength();
}
@Inject(method = "updateWindowTitle", at = @At("HEAD"), cancellable = true)
void updateWindowTitle(CallbackInfo ci) {
if (!ClickGuiLayout.getSetLambdaWindowTitle()) return;
WindowUtils.setLambdaTitle();
ci.cancel();
}
}