-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMinecraftClientMixin.java
More file actions
123 lines (107 loc) · 4.96 KB
/
MinecraftClientMixin.java
File metadata and controls
123 lines (107 loc) · 4.96 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
/*
* Copyright 2024 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.Lambda;
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.module.modules.player.Interact;
import com.lambda.module.modules.player.InventoryMove;
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.ClientPlayerInteractionManager;
import net.minecraft.client.option.KeyBinding;
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.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(MinecraftClient.class)
public class MinecraftClientMixin {
@Shadow
@Nullable
public Screen currentScreen;
@Inject(method = "tick", at = @At("HEAD"))
void onTickPre(CallbackInfo ci) {
EventFlow.post(new TickEvent.Pre());
}
@Inject(method = "tick", at = @At("RETURN"))
void onTickPost(CallbackInfo ci) {
EventFlow.post(new TickEvent.Post());
}
@Inject(method = "render", at = @At("HEAD"))
void onLoopTickPre(CallbackInfo ci) {
EventFlow.post(new TickEvent.Render.Pre());
}
@Inject(method = "render", at = @At("RETURN"))
void onLoopTickPost(CallbackInfo ci) {
EventFlow.post(new TickEvent.Render.Post());
}
@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.INSTANCE.isDisabled() || InventoryMove.hasInputOrNull(currentScreen)) {
KeyBinding.unpressAll();
return;
}
KeyBinding.KEYS_BY_ID.values().forEach(bind -> {
if (!InventoryMove.isKeyMovementRelated(bind.boundKey.getCode())) {
bind.reset();
}
});
}
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
boolean injectMultiActon(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;
Lambda.getMc().itemUseCooldown = Interact.getPlaceDelay();
}
}