Skip to content

Commit 8ad0f11

Browse files
committed
Update to mc1.21.10
1 parent b75e4c3 commit 8ad0f11

22 files changed

Lines changed: 155 additions & 152 deletions

File tree

common/build.gradle

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ import util.PropUtil
22

33
plugins {
44
id("multiloader-common")
5-
id("net.neoforged.moddev")
5+
id("fabric-loom")
66
}
77

88
// Configure common dependencies
99
dependencies {
10+
// Minecraft
11+
minecraft("com.mojang:minecraft:${minecraft_version}")
12+
13+
// Mappings
14+
mappings(loom.layered {
15+
officialMojangMappings()
16+
parchment("org.parchmentmc.data:parchment-${parchment_minecraft_version}:${parchment_version}@zip")
17+
})
18+
1019
// Mixin
1120
compileOnly("org.spongepowered:mixin:${mixin_version}")
1221

@@ -20,13 +29,13 @@ dependencies {
2029
return annotationProcessor(dep)
2130
break
2231
case "api": //noinspection DependencyNotationArgument
23-
return api(dep)
32+
return modApi(dep)
2433
break
2534
case "con": //noinspection DependencyNotationArgument
26-
return compileOnly(dep)
35+
return modCompileOnly(dep)
2736
break
2837
case "imp": //noinspection DependencyNotationArgument
29-
return implementation(dep)
38+
return modImplementation(dep)
3039
break
3140
case "-":
3241
return dep
@@ -38,17 +47,16 @@ dependencies {
3847
new PropUtil(project).applyDependencies(project.name, selector)
3948
}
4049

41-
// Configure ModDevGradle
42-
neoForge {
43-
neoFormVersion = neoform_version
44-
// Apply common AccessTransformer if it exists
45-
def at = file("src/main/resources/META-INF/accesstransformer.cfg")
46-
if (at.exists()) accessTransformers.from(at.absolutePath)
47-
validateAccessTransformers = true
48-
// Apply Parchment mappings
49-
parchment {
50-
minecraftVersion = parchment_minecraft_version
51-
mappingsVersion = parchment_version
50+
// Configure Loom
51+
loom {
52+
// Apply common AccessWidener if it exists
53+
def aw = file("src/main/resources/${mod_id}.accesswidener")
54+
if (aw.exists()) accessWidenerPath.set(aw)
55+
if (aw.exists()) {
56+
validateAccessWidener { accessWidener = aw }
57+
afterEvaluate {
58+
validateAccessWidener.run()
59+
}
5260
}
5361
}
5462

common/src/main/java/dev/terminalmc/commandkeys/CommandKeys.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.minecraft.client.player.LocalPlayer;
3838
import net.minecraft.network.chat.Component;
3939
import net.minecraft.network.chat.MutableComponent;
40+
import net.minecraft.resources.ResourceLocation;
4041
import org.jetbrains.annotations.Nullable;
4142

4243
import java.util.ArrayList;
@@ -55,11 +56,13 @@ public class CommandKeys {
5556
.append(Component.literal(MOD_NAME).withStyle(ChatFormatting.DARK_AQUA))
5657
.append(Component.literal("] ").withStyle(ChatFormatting.DARK_GRAY))
5758
.withStyle(ChatFormatting.GRAY);
59+
public static final KeyMapping.Category CATEGORY =
60+
KeyMapping.Category.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "main"));
5861
public static final KeyMapping CONFIG_KEY = new KeyMapping(
5962
translationKey("key", "main.edit"),
6063
InputConstants.Type.KEYSYM,
6164
InputConstants.KEY_K,
62-
translationKey("key", "main")
65+
CATEGORY
6366
);
6467
public static final List<KeyMapping> KEYBINDS = List.of(CONFIG_KEY);
6568

@@ -219,7 +222,7 @@ private static void send(
219222
) {
220223
Minecraft mc = Minecraft.getInstance();
221224
if (type) {
222-
ChatScreen screen = new ChatScreen(message);
225+
ChatScreen screen = new ChatScreen(message, false);
223226
mc.setScreen(screen);
224227
int index = message.indexOf("%edit%");
225228
if (index != -1) {

common/src/main/java/dev/terminalmc/commandkeys/config/Keybind.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ public static boolean isKeyDown(InputConstants.Key key) {
102102
return false;
103103
if (key.getType().equals(InputConstants.Type.MOUSE)) {
104104
return GLFW.glfwGetMouseButton(
105-
Minecraft.getInstance().getWindow().getWindow(),
105+
Minecraft.getInstance().getWindow().handle(),
106106
key.getValue()
107107
) == 1;
108108
} else {
109-
return GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getWindow(), key.getValue())
109+
return GLFW.glfwGetKey(Minecraft.getInstance().getWindow().handle(), key.getValue())
110110
== 1;
111111
}
112112
}

common/src/main/java/dev/terminalmc/commandkeys/gui/screen/OptionScreen.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import net.minecraft.client.gui.components.StringWidget;
2626
import net.minecraft.client.gui.screens.Screen;
2727
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
28+
import net.minecraft.client.input.KeyEvent;
29+
import net.minecraft.client.input.MouseButtonEvent;
2830
import net.minecraft.network.chat.CommonComponents;
2931
import net.minecraft.network.chat.Component;
3032
import org.jetbrains.annotations.NotNull;
@@ -113,7 +115,7 @@ protected void addTitle() {
113115
0, // Top of screen
114116
(HEADER_MARGIN / 2) - (h / 2) // Center of margin
115117
);
116-
addRenderableWidget(new StringWidget(x, y, w, h, title, font).alignLeft());
118+
addRenderableWidget(new StringWidget(x, y, w, h, title, font));
117119
}
118120

119121
@Override
@@ -159,30 +161,30 @@ public Screen getLastScreen() {
159161
// Input handling
160162

161163
@Override
162-
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
163-
if (list.keyPressed(InputConstants.getKey(keyCode, scanCode)))
164+
public boolean keyPressed(KeyEvent event) {
165+
if (list.keyPressed(InputConstants.getKey(event)))
164166
return true;
165-
return super.keyPressed(keyCode, scanCode, modifiers);
167+
return super.keyPressed(event);
166168
}
167169

168170
@Override
169-
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
170-
if (list.keyReleased(InputConstants.getKey(keyCode, scanCode)))
171+
public boolean keyReleased(KeyEvent event) {
172+
if (list.keyReleased(InputConstants.getKey(event)))
171173
return true;
172-
return super.keyReleased(keyCode, scanCode, modifiers);
174+
return super.keyReleased(event);
173175
}
174176

175177
@Override
176-
public boolean mouseClicked(double mouseX, double mouseY, int delta) {
177-
if (list.mouseClicked(InputConstants.Type.MOUSE.getOrCreate(delta)))
178+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
179+
if (list.mouseClicked(InputConstants.Type.MOUSE.getOrCreate(event.button())))
178180
return true;
179-
return super.mouseClicked(mouseX, mouseY, delta);
181+
return super.mouseClicked(event, doubleClick);
180182
}
181183

182184
@Override
183-
public boolean mouseReleased(double mouseX, double mouseY, int delta) {
184-
if (list.mouseReleased(InputConstants.Type.MOUSE.getOrCreate(delta)))
185+
public boolean mouseReleased(MouseButtonEvent event) {
186+
if (list.mouseReleased(InputConstants.Type.MOUSE.getOrCreate(event.button())))
185187
return true;
186-
return super.mouseReleased(mouseX, mouseY, delta);
188+
return super.mouseReleased(event);
187189
}
188190
}

common/src/main/java/dev/terminalmc/commandkeys/gui/widget/field/FakeTextField.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package dev.terminalmc.commandkeys.gui.widget.field;
1818

19+
import net.minecraft.client.input.MouseButtonEvent;
20+
1921
/**
2022
* A {@link TextField} which renders like a normal editable field, but when clicked, runs a custom
2123
* {@link Runnable} instead of becoming selected.
@@ -44,16 +46,16 @@ public boolean isMouseOver(double mouseX, double mouseY) {
4446
}
4547

4648
@Override
47-
public boolean mouseClicked(double mouseX, double mouseY, int button) {
48-
if (isMouseOver(mouseX, mouseY)) {
49-
onClick(mouseX, mouseY);
49+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
50+
if (isMouseOver(event.x(), event.y())) {
51+
onClick(event, doubleClick);
5052
return true;
5153
}
5254
return false;
5355
}
5456

5557
@Override
56-
public void onClick(double mouseX, double mouseY) {
58+
public void onClick(MouseButtonEvent event, boolean doubleClick) {
5759
onClick.run();
5860
}
5961

common/src/main/java/dev/terminalmc/commandkeys/gui/widget/field/MultiLineTextField.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import net.minecraft.client.gui.components.MultilineTextField;
2828
import net.minecraft.client.gui.components.Tooltip;
2929
import net.minecraft.client.gui.components.Whence;
30+
import net.minecraft.client.input.KeyEvent;
31+
import net.minecraft.client.input.MouseButtonEvent;
3032
import net.minecraft.network.chat.Component;
3133
import org.jetbrains.annotations.NotNull;
3234
import org.jetbrains.annotations.Nullable;
@@ -181,8 +183,8 @@ public void setWidth(int width) {
181183
// Chained clicks
182184

183185
@Override
184-
public boolean mouseClicked(double mouseX, double mouseY, int button) {
185-
if (super.mouseClicked(mouseX, mouseY, button)) {
186+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
187+
if (super.mouseClicked(event, doubleClick)) {
186188
// Double-click to select all
187189
long time = Util.getMillis();
188190
if (lastClickTime + CLICK_CHAIN_TIME > time) {
@@ -241,12 +243,12 @@ private void updateHistory(String str) {
241243
}
242244

243245
@Override
244-
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
245-
if (!super.keyPressed(keyCode, scanCode, modifiers)) {
246-
if (TextField.isUndo(keyCode)) {
246+
public boolean keyPressed(KeyEvent event) {
247+
if (!super.keyPressed(event)) {
248+
if (TextField.isUndo(event)) {
247249
undo();
248250
return true;
249-
} else if (TextField.isRedo(keyCode)) {
251+
} else if (TextField.isRedo(event)) {
250252
redo();
251253
return true;
252254
}

common/src/main/java/dev/terminalmc/commandkeys/gui/widget/field/TextField.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import net.minecraft.client.gui.Font;
2424
import net.minecraft.client.gui.components.EditBox;
2525
import net.minecraft.client.gui.components.Tooltip;
26-
import net.minecraft.client.gui.screens.Screen;
26+
import net.minecraft.client.input.KeyEvent;
27+
import net.minecraft.client.input.MouseButtonEvent;
2728
import net.minecraft.network.chat.Component;
2829
import net.minecraft.util.Mth;
2930
import org.jetbrains.annotations.NotNull;
@@ -166,8 +167,8 @@ public void setTextColor(int color) {
166167
// Chained clicks and click-drag
167168

168169
@Override
169-
public boolean mouseClicked(double mouseX, double mouseY, int button) {
170-
if (super.mouseClicked(mouseX, mouseY, button)) {
170+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
171+
if (super.mouseClicked(event, doubleClick)) {
171172
long time = Util.getMillis();
172173
if (lastClickTime + CLICK_CHAIN_TIME > time) {
173174
switch (++chainedClicks) {
@@ -205,7 +206,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
205206
lastClickTime = time;
206207

207208
// Reset drag origin
208-
dragOriginX = mouseX;
209+
dragOriginX = event.x();
209210
dragOriginPos = getCursorPosition();
210211

211212
return true;
@@ -214,27 +215,21 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
214215
}
215216

216217
@Override
217-
public boolean mouseDragged(
218-
double mouseX,
219-
double mouseY,
220-
int button,
221-
double dragX,
222-
double dragY
223-
) {
224-
if (button != 0)
218+
public boolean mouseDragged(MouseButtonEvent event, double dragX, double dragY) {
219+
if (event.button() != 0)
225220
return false;
226221
String str = getValue();
227222

228-
if (mouseX < dragOriginX) { // Dragging left
223+
if (event.x() < dragOriginX) { // Dragging left
229224
String subLeft = str.substring(0, dragOriginPos);
230225
int offsetChars =
231-
font.plainSubstrByWidth(subLeft, Mth.floor(dragOriginX - mouseX), true)
226+
font.plainSubstrByWidth(subLeft, Mth.floor(dragOriginX - event.x()), true)
232227
.length();
233228
moveCursorTo(dragOriginPos - offsetChars, true);
234229
} else { // Dragging right
235230
String subRight = str.substring(dragOriginPos);
236231
int offsetChars =
237-
font.plainSubstrByWidth(subRight, Mth.floor(mouseX - dragOriginX), false)
232+
font.plainSubstrByWidth(subRight, Mth.floor(event.x() - dragOriginX), false)
238233
.length();
239234
moveCursorTo(dragOriginPos + offsetChars, true);
240235
}
@@ -258,12 +253,12 @@ private void updateHistory(String str) {
258253
}
259254

260255
@Override
261-
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
262-
if (!super.keyPressed(keyCode, scanCode, modifiers)) {
263-
if (isUndo(keyCode)) {
256+
public boolean keyPressed(KeyEvent event) {
257+
if (!super.keyPressed(event)) {
258+
if (isUndo(event)) {
264259
undo();
265260
return true;
266-
} else if (isRedo(keyCode)) {
261+
} else if (isRedo(event)) {
267262
redo();
268263
return true;
269264
}
@@ -311,13 +306,17 @@ public Optional<Component> validate(String str) {
311306

312307
// Utility methods
313308

314-
public static boolean isUndo(int keyCode) {
315-
return keyCode == InputConstants.KEY_Z && Screen.hasControlDown() && !Screen.hasShiftDown()
316-
&& !Screen.hasAltDown();
309+
public static boolean isUndo(KeyEvent event) {
310+
return event.key() == InputConstants.KEY_Z
311+
&& event.hasControlDown()
312+
&& !event.hasShiftDown()
313+
&& !event.hasAltDown();
317314
}
318315

319-
public static boolean isRedo(int keyCode) {
320-
return keyCode == InputConstants.KEY_Y && Screen.hasControlDown() && !Screen.hasShiftDown()
321-
&& !Screen.hasAltDown();
316+
public static boolean isRedo(KeyEvent event) {
317+
return event.key() == InputConstants.KEY_Y
318+
&& event.hasControlDown()
319+
&& !event.hasShiftDown()
320+
&& !event.hasAltDown();
322321
}
323322
}

0 commit comments

Comments
 (0)