Skip to content

Commit 70025b9

Browse files
mixins are way too op pls nerf
1 parent 35089a6 commit 70025b9

File tree

6 files changed

+189
-96
lines changed

6 files changed

+189
-96
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.gregtechceu.gtceu.client;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import net.minecraftforge.eventbus.api.Cancelable;
6+
import net.minecraftforge.eventbus.api.Event;
7+
8+
@AllArgsConstructor
9+
@Getter
10+
@Cancelable
11+
public class CharTypedEvent extends Event {
12+
private final char codepoint;
13+
private final int modifiers;
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.gregtechceu.gtceu.client;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import net.minecraftforge.eventbus.api.Cancelable;
6+
import net.minecraftforge.eventbus.api.Event;
7+
8+
@AllArgsConstructor
9+
@Getter
10+
@Cancelable
11+
public class EarlyKeyPressEvent extends Event {
12+
private final int key;
13+
private final int scanCode;
14+
private final int action;
15+
private final int modifiers;
16+
}

src/main/java/com/gregtechceu/gtceu/client/mui/screen/ClientScreenHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private static boolean doAction(@Nullable ModularScreen muiScreen, Predicate<Mod
313313
/**
314314
* This replicates vanilla behavior while also injecting custom behavior for consistency
315315
*/
316-
private static boolean handleKeyboardInput(@Nullable ModularScreen muiScreen, Screen mcScreen,
316+
public static boolean handleKeyboardInput(@Nullable ModularScreen muiScreen, Screen mcScreen,
317317
boolean isPress, InputPhase inputPhase,
318318
int keyCode, int scanCode, int modifiers) {
319319
if (isPress) {
@@ -681,7 +681,7 @@ public static GuiContext getBestContext() {
681681
return defaultContext;
682682
}
683683

684-
private enum InputPhase {
684+
public enum InputPhase {
685685

686686
// for mui interactions
687687
EARLY,

src/main/java/com/gregtechceu/gtceu/client/renderer/monitor/MonitorGuiRenderer.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.gregtechceu.gtceu.api.mui.factory.GuiManager;
1010
import com.gregtechceu.gtceu.api.mui.factory.PosGuiData;
1111
import com.gregtechceu.gtceu.api.mui.widgets.SlotGroupWidget;
12+
import com.gregtechceu.gtceu.client.CharTypedEvent;
13+
import com.gregtechceu.gtceu.client.EarlyKeyPressEvent;
1214
import com.gregtechceu.gtceu.client.mui.screen.*;
1315
import com.gregtechceu.gtceu.common.machine.multiblock.electric.CentralMonitorMachine;
1416
import com.gregtechceu.gtceu.common.machine.multiblock.electric.monitor.MonitorGroup;
@@ -18,6 +20,7 @@
1820
import com.gregtechceu.gtceu.core.mixins.client.GuiGraphicsAccessor;
1921
import com.gregtechceu.gtceu.utils.GTUtil;
2022

23+
import com.mojang.blaze3d.platform.InputConstants;
2124
import net.minecraft.client.gui.GuiGraphics;
2225
import net.minecraft.client.gui.screens.Screen;
2326
import net.minecraft.client.renderer.MultiBufferSource;
@@ -40,6 +43,7 @@ public class MonitorGuiRenderer implements IMonitorRenderer {
4043
private ModularScreen screen;
4144
private Screen vanillaScreen;
4245
private int width = 200, height = 200;
46+
private int mouseX = -1, mouseY = -1;
4347
private final Level targetLevel;
4448
private final BlockPos targetPos;
4549

@@ -83,6 +87,27 @@ public void openClientInWorldUI(InWorldMUIOpenEvent event) {
8387
}
8488
}
8589

90+
@SubscribeEvent
91+
public void keyPressedEvent(EarlyKeyPressEvent event) {
92+
if (mouseX < 0 || mouseX > width || mouseY < 0 || mouseY > height || MCHelper.getCurrentScreen() != null) return;
93+
screen.getContext().updateLatestKey(event.getKey(), event.getScanCode(), event.getModifiers());
94+
boolean early = ClientScreenHandler.handleKeyboardInput(screen, vanillaScreen, event.getAction() == InputConstants.PRESS,
95+
ClientScreenHandler.InputPhase.EARLY, event.getKey(), event.getScanCode(), event.getModifiers());
96+
if (early) event.setCanceled(true);
97+
else {
98+
boolean late = ClientScreenHandler.handleKeyboardInput(screen, vanillaScreen, event.getAction() == InputConstants.PRESS,
99+
ClientScreenHandler.InputPhase.LATE, event.getKey(), event.getScanCode(), event.getModifiers());
100+
if (late) event.setCanceled(true);
101+
}
102+
}
103+
104+
@SubscribeEvent
105+
public void charTyped(CharTypedEvent event) {
106+
if (mouseX < 0 || mouseX > width || mouseY < 0 || mouseY > height || MCHelper.getCurrentScreen() != null) return;
107+
screen.getContext().updateLatestTypedChar(event.getCodepoint(), event.getModifiers());
108+
if (screen.charTyped(event.getCodepoint(), event.getModifiers())) event.setCanceled(true);
109+
}
110+
86111
public void renderGui(int maxWidth, int maxHeight, PoseStack poseStack, MultiBufferSource buffer,
87112
float partialTick, int mouseX, int mouseY) {
88113
GuiGraphics guiGraphics = new GuiGraphics(MCHelper.getMc(), (MultiBufferSource.BufferSource) buffer);
@@ -128,13 +153,15 @@ public void render(CentralMonitorMachine machine, MonitorGroup group, float part
128153
if (monitor instanceof AdvancedMonitorPartMachine advancedMonitor && mouseX >= 0 && mouseY >= 0 &&
129154
mouseX <= width && mouseY <= height) {
130155
if (advancedMonitor.isClickedThisFrame()) {
131-
this.screen.onMousePressed(mouseX, mouseY, GLFW.GLFW_MOUSE_BUTTON_LEFT);
132-
this.vanillaScreen.mouseClicked(mouseX, mouseY, GLFW.GLFW_MOUSE_BUTTON_LEFT);
156+
this.screen.onMousePressed(mouseX * 256, mouseY * 256, GLFW.GLFW_MOUSE_BUTTON_LEFT);
157+
this.vanillaScreen.mouseClicked(mouseX * 256, mouseY * 256, GLFW.GLFW_MOUSE_BUTTON_LEFT);
133158
advancedMonitor.setClickedThisFrame(false);
134159
}
135160
}
136161
}
137162
}
163+
this.mouseX = (int) (mouseX * 256);
164+
this.mouseY = (int) (mouseY * 256);
138165
renderGui(size.getX(), size.getY(), poseStack, buffer, partialTick, (int) (mouseX * 256), (int) (mouseY * 256));
139166
}
140167
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.gregtechceu.gtceu.core.mixins;
2+
3+
import com.gregtechceu.gtceu.client.CharTypedEvent;
4+
import com.gregtechceu.gtceu.client.EarlyKeyPressEvent;
5+
import net.minecraft.client.KeyboardHandler;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraftforge.common.MinecraftForge;
8+
import org.spongepowered.asm.mixin.Final;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14+
15+
@Mixin(KeyboardHandler.class)
16+
public class KeyboardHandlerMixin {
17+
@Shadow
18+
@Final
19+
private Minecraft minecraft;
20+
21+
@Inject(method = "charTyped", at = @At(value = "HEAD"), cancellable = true)
22+
private void onCharTyped(long windowPointer, int codePoint, int modifiers, CallbackInfo ci) {
23+
if (windowPointer == this.minecraft.getWindow().getWindow()) {
24+
CharTypedEvent event = new CharTypedEvent((char) codePoint, modifiers);
25+
if (MinecraftForge.EVENT_BUS.post(event)) ci.cancel();
26+
}
27+
}
28+
29+
@Inject(method = "keyPress", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;onKeyInput(IIII)V"), cancellable = true)
30+
private void onKeyPressed(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) {
31+
if (MinecraftForge.EVENT_BUS.post(new EarlyKeyPressEvent(key, scanCode, action, modifiers))) {
32+
ci.cancel();
33+
}
34+
}
35+
}
Lines changed: 93 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,95 @@
11
{
2-
"required": true,
3-
"minVersion": "0.8",
4-
"refmap": "gtceu.refmap.json",
5-
"package": "com.gregtechceu.gtceu.core.mixins",
6-
"compatibilityLevel": "JAVA_17",
7-
"plugin": "com.gregtechceu.gtceu.core.mixins.GTMixinPlugin",
8-
"client": [
9-
"client.AbstractClientPlayerAccessor",
10-
"client.AbstractContainerScreenAccessor",
11-
"client.AbstractContainerScreenMixin",
12-
"client.AbstractWidgetMixin",
13-
"client.BakedQuadMixin",
14-
"client.BiomeColorsMixin",
15-
"client.BlockModelMixin",
16-
"client.ClientLevelAccessor",
17-
"client.FaceBakeryMixin",
18-
"client.GuiGraphicsAccessor",
19-
"client.GuiGraphicsMixin",
20-
"client.GuiHeartTypeMixin",
21-
"client.HumanoidArmorLayerMixin",
22-
"client.KeyMappingAccessor",
23-
"client.LevelRendererMixin",
24-
"client.MinecraftMixin",
25-
"client.ModelManagerMixin",
26-
"client.MultiPlayerGameModeMixin",
27-
"client.PlayerInfoAccessor",
28-
"client.ScreenAccessor",
29-
"client.StringSplitterAccessor",
30-
"client.VariantDeserializerMixin",
31-
"ftbchunks.FTBChunksClientMixin",
32-
"ftbchunks.LargeMapScreenMixin",
33-
"ftbchunks.RegionMapPanelMixin",
34-
"ldlib.ModularWrapperWidgetMixin",
35-
"rei.FluidEntryRendererMixin",
36-
"xaerominimap.HighlighterRegistryMixin",
37-
"xaerominimap.MinimapFBORendererMixin",
38-
"xaeroworldmap.GuiMapMixin",
39-
"xaeroworldmap.MapElementRenderHandlerBuilderMixin",
40-
"xaeroworldmap.WorldMapSessionMixin"
41-
],
42-
"mixins": [
43-
"AnvilMenuMixin",
44-
"BlockBehaviourAccessor",
45-
"BlockMixin",
46-
"BlockPropertiesAccessor",
47-
"ChunkGeneratorMixin",
48-
"EntityMixin",
49-
"GrowingPlantBlockAccessor",
50-
"IngredientAccessor",
51-
"IntegerPropertyAccessor",
52-
"InventoryMixin",
53-
"ItemValueAccessor",
54-
"LevelMixin",
55-
"LootDataManagerMixin",
56-
"LootPoolAccessor",
57-
"OreConfigurationMixin",
58-
"OreVeinifierMixin",
59-
"PotionBrewingAccessor",
60-
"PrimedTntAccessor",
61-
"RecipeManagerMixin",
62-
"RepairItemRecipeMixin",
63-
"ServerChunkProviderMixin",
64-
"ServerGamePacketListenerImplAccessor",
65-
"ShapedRecipeAccessor",
66-
"SidedRedstoneConnectivityMixin",
67-
"TagLoaderMixin",
68-
"TagManagerMixin",
69-
"TagValueAccessor",
70-
"TransientCraftingContainerAccessor",
71-
"client.AbstractContainerMenuAccessor",
72-
"client.ItemEntityMixin",
73-
"client.SlotAccessor",
74-
"emi.EmiRecipeFillerMixin",
75-
"emi.FillRecipePacketMixin",
76-
"emi.FluidEmiStackMixin",
77-
"forge.ConfiguredModelBuilderAccessor",
78-
"forge.ConfiguredModelListAccessor",
79-
"forge.IntersectionIngredientAccessor",
80-
"forge.PartialNBTIngredientAccessor",
81-
"forge.StrictNBTIngredientAccessor",
82-
"jei.FluidHelperMixin",
83-
"ldlib.SyncUtilsMixin",
84-
"registrate.AbstractRegistrateAccessor",
85-
"registrate.RegistrateDataProviderAccessor",
86-
"rei.InputSlotCrafterMixin",
87-
"rei.RecipeFinderMixin",
88-
"top.ConfigMixin"
89-
],
90-
"injectors": {
91-
"defaultRequire": 1,
92-
"maxShiftBy": 5
93-
}
2+
"required": true,
3+
"minVersion": "0.8",
4+
"refmap": "gtceu.refmap.json",
5+
"package": "com.gregtechceu.gtceu.core.mixins",
6+
"compatibilityLevel": "JAVA_17",
7+
"plugin": "com.gregtechceu.gtceu.core.mixins.GTMixinPlugin",
8+
"client": [
9+
"KeyboardHandlerMixin",
10+
"client.AbstractClientPlayerAccessor",
11+
"client.AbstractContainerScreenAccessor",
12+
"client.AbstractContainerScreenMixin",
13+
"client.AbstractWidgetMixin",
14+
"client.BakedQuadMixin",
15+
"client.BiomeColorsMixin",
16+
"client.BlockModelMixin",
17+
"client.ClientLevelAccessor",
18+
"client.FaceBakeryMixin",
19+
"client.GuiGraphicsAccessor",
20+
"client.GuiGraphicsMixin",
21+
"client.GuiHeartTypeMixin",
22+
"client.HumanoidArmorLayerMixin",
23+
"client.KeyMappingAccessor",
24+
"client.LevelRendererMixin",
25+
"client.MinecraftMixin",
26+
"client.ModelManagerMixin",
27+
"client.MultiPlayerGameModeMixin",
28+
"client.PlayerInfoAccessor",
29+
"client.ScreenAccessor",
30+
"client.StringSplitterAccessor",
31+
"client.VariantDeserializerMixin",
32+
"ftbchunks.FTBChunksClientMixin",
33+
"ftbchunks.LargeMapScreenMixin",
34+
"ftbchunks.RegionMapPanelMixin",
35+
"ldlib.ModularWrapperWidgetMixin",
36+
"rei.FluidEntryRendererMixin",
37+
"xaerominimap.HighlighterRegistryMixin",
38+
"xaerominimap.MinimapFBORendererMixin",
39+
"xaeroworldmap.GuiMapMixin",
40+
"xaeroworldmap.MapElementRenderHandlerBuilderMixin",
41+
"xaeroworldmap.WorldMapSessionMixin"
42+
],
43+
"mixins": [
44+
"AnvilMenuMixin",
45+
"BlockBehaviourAccessor",
46+
"BlockMixin",
47+
"BlockPropertiesAccessor",
48+
"ChunkGeneratorMixin",
49+
"EntityMixin",
50+
"GrowingPlantBlockAccessor",
51+
"IngredientAccessor",
52+
"IntegerPropertyAccessor",
53+
"InventoryMixin",
54+
"ItemValueAccessor",
55+
"LevelMixin",
56+
"LootDataManagerMixin",
57+
"LootPoolAccessor",
58+
"OreConfigurationMixin",
59+
"OreVeinifierMixin",
60+
"PotionBrewingAccessor",
61+
"PrimedTntAccessor",
62+
"RecipeManagerMixin",
63+
"RepairItemRecipeMixin",
64+
"ServerChunkProviderMixin",
65+
"ServerGamePacketListenerImplAccessor",
66+
"ShapedRecipeAccessor",
67+
"SidedRedstoneConnectivityMixin",
68+
"TagLoaderMixin",
69+
"TagManagerMixin",
70+
"TagValueAccessor",
71+
"TransientCraftingContainerAccessor",
72+
"client.AbstractContainerMenuAccessor",
73+
"client.ItemEntityMixin",
74+
"client.SlotAccessor",
75+
"emi.EmiRecipeFillerMixin",
76+
"emi.FillRecipePacketMixin",
77+
"emi.FluidEmiStackMixin",
78+
"forge.ConfiguredModelBuilderAccessor",
79+
"forge.ConfiguredModelListAccessor",
80+
"forge.IntersectionIngredientAccessor",
81+
"forge.PartialNBTIngredientAccessor",
82+
"forge.StrictNBTIngredientAccessor",
83+
"jei.FluidHelperMixin",
84+
"ldlib.SyncUtilsMixin",
85+
"registrate.AbstractRegistrateAccessor",
86+
"registrate.RegistrateDataProviderAccessor",
87+
"rei.InputSlotCrafterMixin",
88+
"rei.RecipeFinderMixin",
89+
"top.ConfigMixin"
90+
],
91+
"injectors": {
92+
"defaultRequire": 1,
93+
"maxShiftBy": 5
94+
}
9495
}

0 commit comments

Comments
 (0)