Skip to content

Commit b2f4d15

Browse files
committed
build(mappings): migrate mappings to **Mojang official**
1 parent fd45f58 commit b2f4d15

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ Up to 20 buttons are currently supported! More are planned.
1919

2020
### How It Works
2121
The list of commands are serialized into a JSON format and stored locally on the users’ systems. The mod writes any new commands into the JSON as new buttons are created, and loads the JSON at the start of the game. A local list instance exists for reading and loading the buttons each time, so that file reading is kept to a minimum.
22+
23+
## Development
24+
25+
### Mappings
26+
27+
We are using the **Mojang official** mappings to de-obfuscate Minecraft and insert patches.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repositories {
2626
dependencies {
2727
// To change the versions see the gradle.properties file
2828
minecraft "com.mojang:minecraft:${project.minecraft_version}"
29-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
29+
mappings(loom.officialMojangMappings())
3030
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
3131

3232
// Fabric API. This is technically optional, but you probably want it anyway.

src/main/java/cn/msdnicrosoft/commandbuttons/CommandButtons.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import cn.msdnicrosoft.commandbuttons.gui.ButtonGUI;
44
import cn.msdnicrosoft.commandbuttons.gui.ButtonGUIScreen;
5+
import com.mojang.blaze3d.platform.InputConstants;
56
import net.fabricmc.api.ModInitializer;
67
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
78
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
8-
import net.minecraft.client.MinecraftClient;
9-
import net.minecraft.client.network.ClientPlayerEntity;
10-
import net.minecraft.client.option.KeyBinding;
11-
import net.minecraft.client.util.InputUtil;
9+
import net.minecraft.client.KeyMapping;
10+
import net.minecraft.client.Minecraft;
11+
import net.minecraft.client.player.LocalPlayer;
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414
import org.json.simple.JSONObject;
@@ -19,7 +19,7 @@
1919
public class CommandButtons implements ModInitializer {
2020
public static final String MOD_ID = "mgbuttons";
2121
private static ArrayList<JSONObject> masterCommList;
22-
private static final MinecraftClient mc = MinecraftClient.getInstance();
22+
private static final Minecraft mc = Minecraft.getInstance();
2323
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
2424

2525
public static void send(String text) {
@@ -31,14 +31,14 @@ public static void send(String text) {
3131
}
3232

3333
public static void send(String text, boolean useCommand) {
34-
ClientPlayerEntity player = mc.player;
34+
LocalPlayer player = mc.player;
3535
if (player == null) {
3636
return;
3737
}
3838
if (useCommand) {
39-
player.sendCommand(text);
39+
player.command(text);
4040
} else {
41-
player.sendChatMessage(text);
41+
player.chat(text);
4242
}
4343
}
4444

@@ -67,16 +67,16 @@ public void onInitialize() {
6767

6868
private void assignGuiToKey() {
6969
// Currently, assigns to the G key
70-
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
70+
KeyMapping keyBinding = KeyBindingHelper.registerKeyBinding(new KeyMapping(
7171
"key.commandbuttons.opengui", // The translation key of the keybinding's name
72-
InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse.
72+
InputConstants.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse.
7373
GLFW.GLFW_KEY_G, // The keycode of the key
7474
"gui.commandbuttons.mgbuttons" // The translation key of the keybinding's category.
7575
));
7676

7777
ClientTickEvents.END_CLIENT_TICK.register(client -> {
78-
while (keyBinding.wasPressed()) {
79-
MinecraftClient.getInstance().setScreen(new ButtonGUIScreen(new ButtonGUI()));
78+
while (keyBinding.consumeClick()) {
79+
Minecraft.getInstance().setScreen(new ButtonGUIScreen(new ButtonGUI()));
8080
// client.player.closeScreen();
8181
}
8282
});

src/main/java/cn/msdnicrosoft/commandbuttons/gui/ButtonGUI.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
99
import io.github.cottonmc.cotton.gui.widget.WTextField;
1010
import io.github.cottonmc.cotton.gui.widget.WToggleButton;
11-
import net.minecraft.client.MinecraftClient;
12-
import net.minecraft.text.Text;
1311
import org.json.simple.JSONObject;
1412

1513
import java.util.ArrayList;
14+
import net.minecraft.client.Minecraft;
15+
import net.minecraft.network.chat.Component;
1616

1717
public class ButtonGUI extends LightweightGuiDescription {
1818
int xValue = 0;
@@ -25,7 +25,7 @@ public ButtonGUI() {
2525
addCloseButton(root);
2626

2727
// Add delete toggle button
28-
WToggleButton delToggle = new WToggleButton(Text.translatable("mgbuttons.gui.delete"));
28+
WToggleButton delToggle = new WToggleButton(Component.translatable("mgbuttons.gui.delete"));
2929
root.add(delToggle, 0, 11, 3, 1);
3030

3131
addSavedButtons(root, delToggle);
@@ -34,10 +34,10 @@ public ButtonGUI() {
3434
}
3535

3636
private void addCloseButton(WGridPanel root) {
37-
WButton escButton = new WButton(Text.literal("X"));
37+
WButton escButton = new WButton(Component.literal("X"));
3838
escButton.setOnClick(() -> {
39-
assert MinecraftClient.getInstance().player != null;
40-
MinecraftClient.getInstance().player.closeScreen();
39+
assert Minecraft.getInstance().player != null;
40+
Minecraft.getInstance().player.clientSideCloseContainer();
4141
});
4242
root.add(escButton, 17, 1, 2, 2);
4343
}
@@ -46,17 +46,17 @@ private void addCommandSection(WGridPanel root, WToggleButton toggle) {
4646
// Add text field for command NAME entry
4747
WTextField nameTextField = new WTextField();
4848
nameTextField.setMaxLength(11);
49-
nameTextField.setSuggestion(Text.translatable("mgbuttons.gui.name"));
49+
nameTextField.setSuggestion(Component.translatable("mgbuttons.gui.name"));
5050
root.add(nameTextField, 0, 12, 6, 1);
5151

5252
// Add text field for command / entry
5353
WTextField commandTextField = new WTextField();
54-
commandTextField.setSuggestion(Text.translatable("mgbuttons.gui.command"));
54+
commandTextField.setSuggestion(Component.translatable("mgbuttons.gui.command"));
5555
commandTextField.setMaxLength(300);
5656
root.add(commandTextField, 6, 12, 11, 1);
5757

5858
// Add button for command entry
59-
WButton addCmdBtn = new WButton(Text.literal("+"));
59+
WButton addCmdBtn = new WButton(Component.literal("+"));
6060
addCmdBtn.setOnClick(() -> addGUIButton(root, nameTextField, commandTextField, toggle));
6161
root.add(addCmdBtn, 18, 12, 1, 1);
6262
}
@@ -72,7 +72,7 @@ private void addGUIButton(WGridPanel root, WTextField name, WTextField command,
7272

7373
if (!isListTooLong()) {
7474
String commandString = command.getText();
75-
WButton button = new WButton(Text.literal(name.getText()));
75+
WButton button = new WButton(Component.literal(name.getText()));
7676
button.setOnClick(() -> {
7777
if (isDeleteToggled.getToggle()) {
7878
ConfigFile.removeObject(newJsonObject);
@@ -103,7 +103,7 @@ private void addGUIButton(WGridPanel root, WTextField name, WTextField command,
103103
// function to load buttons from commands.json
104104
private void addGUIButton(WGridPanel root, String name, String command, WToggleButton isDeleteToggled, JSONObject object) {
105105
if (!name.equals("") && !command.equals("")) {
106-
WButton button = new WButton(Text.literal(name));
106+
WButton button = new WButton(Component.literal(name));
107107
button.setOnClick(() -> {
108108
if (isDeleteToggled.getToggle()) {
109109
ConfigFile.removeObject(object);

0 commit comments

Comments
 (0)