Skip to content

Commit ecf3eb4

Browse files
committed
Port to 1.20.3-rc1
1 parent e346358 commit ecf3eb4

File tree

16 files changed

+114
-41
lines changed

16 files changed

+114
-41
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ dependencies {
4949

5050
compileOnly 'com.demonwav.mcdev:annotations:2.0.0'
5151

52-
modRuntimeOnly 'me.djtheredstoner:DevAuth-fabric:1.1.0'
52+
modRuntimeOnly('me.djtheredstoner:DevAuth-fabric:1.1.0') {
53+
exclude group: 'net.fabricmc', module: 'fabric-loader'
54+
}
5355
}
5456

5557
jar {

gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx2G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/develop/
6-
minecraft_version=1.20.2
7-
minecraft_version_dependency=1.20.2
8-
minecraft_version_list=1.20.2
9-
minecraft_version_list_presentable=1.20.2
10-
yarn_mappings=1.20.2+build.4
6+
minecraft_version=1.20.3-rc1
7+
minecraft_version_dependency=1.20.3-rc.1
8+
minecraft_version_list=1.20.3-rc1
9+
minecraft_version_list_presentable=1.20.3-rc1
10+
yarn_mappings=1.20.3-rc1+build.2
1111
loader_version=0.15.0
1212

1313
# Mod Properties
@@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx2G
1717

1818
# Dependencies
1919
# also check this on https://fabricmc.net/develop/
20-
fabric_version=0.91.1+1.20.2
20+
fabric_version=0.91.1+1.20.3
2121
clientarguments_version=1.6
2222
betterconfig_version=1.2.1
2323
seedfinding_core_version=1.192.1

src/main/java/net/earthcomputer/clientcommands/command/CEnchantCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
88
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
99
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
10-
import net.minecraft.command.CommandException;
1110
import net.minecraft.enchantment.Enchantment;
1211
import net.minecraft.enchantment.EnchantmentLevelEntry;
1312
import net.minecraft.item.Item;
@@ -35,7 +34,7 @@ private static boolean enchantmentPredicate(Item item, Enchantment ench) {
3534
return !ench.isTreasure() && ench.isAvailableForRandomSelection() && (item == Items.BOOK || ench.target.isAcceptableItem(item));
3635
}
3736

38-
private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) throws CommandException {
37+
private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) {
3938
if (!Configs.getEnchantingPrediction()) {
4039
Text text = Text.translatable("commands.cenchant.needEnchantingPrediction")
4140
.formatted(Formatting.RED)

src/main/java/net/earthcomputer/clientcommands/command/FakeCommandSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class FakeCommandSource extends ServerCommandSource {
1212
public FakeCommandSource(ClientPlayerEntity player) {
13-
super(player, player.getPos(), player.getRotationClient(), null, 314159265, player.getEntityName(), player.getName(), null, player);
13+
super(player, player.getPos(), player.getRotationClient(), null, 314159265, player.getNameForScoreboard(), player.getName(), null, player);
1414
}
1515

1616
@Override

src/main/java/net/earthcomputer/clientcommands/command/GlowCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static int glowBlock(FabricClientCommandSource source, BlockPos pos1, Bl
129129
boundingBoxes.replaceAll((box) -> box.offset(pos1));
130130
}
131131
} else {
132-
boundingBoxes.add(new Box(pos1, pos2));
132+
boundingBoxes.add(Box.enclosing(pos1, pos2));
133133
}
134134

135135
for (Box box : boundingBoxes) {

src/main/java/net/earthcomputer/clientcommands/command/ItemGroupCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ private static void saveFile() throws CommandSyntaxException {
225225
});
226226
rootTag.putInt("DataVersion", SharedConstants.getGameVersion().getSaveVersion().getId());
227227
rootTag.put("Groups", compoundTag);
228-
File newFile = File.createTempFile("groups", ".dat", configPath.toFile());
228+
Path newFile = File.createTempFile("groups", ".dat", configPath.toFile()).toPath();
229229
NbtIo.write(rootTag, newFile);
230-
File backupFile = new File(configPath.toFile(), "groups.dat_old");
231-
File currentFile = new File(configPath.toFile(), "groups.dat");
230+
Path backupFile = configPath.resolve("groups.dat_old");
231+
Path currentFile = configPath.resolve("groups.dat");
232232
Util.backupAndReplace(currentFile, newFile, backupFile);
233233
} catch (IOException e) {
234234
e.printStackTrace();
@@ -238,7 +238,7 @@ private static void saveFile() throws CommandSyntaxException {
238238

239239
private static void loadFile() throws IOException {
240240
groups.clear();
241-
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "groups.dat"));
241+
NbtCompound rootTag = NbtIo.read(configPath.resolve("groups.dat"));
242242
if (rootTag == null) {
243243
return;
244244
}

src/main/java/net/earthcomputer/clientcommands/command/KitCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ private static void saveFile() throws CommandSyntaxException {
177177
kits.forEach(compoundTag::put);
178178
rootTag.putInt("DataVersion", SharedConstants.getGameVersion().getSaveVersion().getId());
179179
rootTag.put("Kits", compoundTag);
180-
File newFile = File.createTempFile("kits", ".dat", configPath.toFile());
180+
Path newFile = File.createTempFile("kits", ".dat", configPath.toFile()).toPath();
181181
NbtIo.write(rootTag, newFile);
182-
File backupFile = new File(configPath.toFile(), "kits.dat_old");
183-
File currentFile = new File(configPath.toFile(), "kits.dat");
182+
Path backupFile = configPath.resolve("kits.dat_old");
183+
Path currentFile = configPath.resolve("kits.dat");;
184184
Util.backupAndReplace(currentFile, newFile, backupFile);
185185
} catch (IOException e) {
186186
throw SAVE_FAILED_EXCEPTION.create();
@@ -189,7 +189,7 @@ private static void saveFile() throws CommandSyntaxException {
189189

190190
private static void loadFile() throws IOException {
191191
kits.clear();
192-
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "kits.dat"));
192+
NbtCompound rootTag = NbtIo.read(configPath.resolve("kits.dat"));
193193
if (rootTag == null) {
194194
return;
195195
}

src/main/java/net/earthcomputer/clientcommands/command/VarCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ private static void saveFile() throws CommandSyntaxException {
123123
try {
124124
NbtCompound rootTag = new NbtCompound();
125125
variables.forEach(rootTag::putString);
126-
File newFile = File.createTempFile("vars", ".dat", configPath.toFile());
126+
Path newFile = File.createTempFile("vars", ".dat", configPath.toFile()).toPath();
127127
NbtIo.write(rootTag, newFile);
128-
File backupFile = new File(configPath.toFile(), "vars.dat_old");
129-
File currentFile = new File(configPath.toFile(), "vars.dat");
128+
Path backupFile = configPath.resolve("vars.dat_old");
129+
Path currentFile = configPath.resolve("vars.dat");
130130
Util.backupAndReplace(currentFile, newFile, backupFile);
131131
} catch (IOException e) {
132132
throw SAVE_FAILED_EXCEPTION.create();
@@ -135,7 +135,7 @@ private static void saveFile() throws CommandSyntaxException {
135135

136136
private static void loadFile() throws IOException {
137137
variables.clear();
138-
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "vars.dat"));
138+
NbtCompound rootTag = NbtIo.read(configPath.resolve("vars.dat"));
139139
if (rootTag == null) {
140140
return;
141141
}

src/main/java/net/earthcomputer/clientcommands/command/arguments/FormattedTextArgumentType.java

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
package net.earthcomputer.clientcommands.command.arguments;
22

33
import com.google.common.collect.ImmutableMap;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonPrimitive;
46
import com.mojang.brigadier.StringReader;
57
import com.mojang.brigadier.arguments.ArgumentType;
68
import com.mojang.brigadier.context.CommandContext;
79
import com.mojang.brigadier.exceptions.CommandSyntaxException;
10+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
811
import com.mojang.brigadier.suggestion.Suggestions;
912
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
13+
import com.mojang.serialization.JsonOps;
14+
import net.earthcomputer.clientcommands.mixin.HoverEventActionAccessor;
1015
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1116
import net.minecraft.command.CommandSource;
12-
import net.minecraft.text.*;
17+
import net.minecraft.text.ClickEvent;
18+
import net.minecraft.text.HoverEvent;
19+
import net.minecraft.text.MutableText;
20+
import net.minecraft.text.Style;
21+
import net.minecraft.text.Text;
22+
import net.minecraft.text.TextCodecs;
23+
import net.minecraft.text.TextColor;
1324
import net.minecraft.util.Formatting;
1425
import net.minecraft.util.Identifier;
15-
16-
import java.util.*;
26+
import net.minecraft.util.StringIdentifiable;
27+
import net.minecraft.util.Util;
28+
29+
import java.util.ArrayList;
30+
import java.util.Arrays;
31+
import java.util.Collection;
32+
import java.util.List;
33+
import java.util.Locale;
34+
import java.util.Map;
1735
import java.util.concurrent.CompletableFuture;
18-
import java.util.function.BiFunction;
1936
import java.util.function.Consumer;
37+
import java.util.function.Function;
2038

2139
public class FormattedTextArgumentType implements ArgumentType<MutableText> {
22-
2340
private static final Collection<String> EXAMPLES = Arrays.asList("Earth", "bold{xpple}", "bold{italic{red{nwex}}}");
41+
private static final DynamicCommandExceptionType INVALID_CLICK_ACTION = new DynamicCommandExceptionType(action -> Text.translatable("commands.client.invalidClickAction", action));
42+
private static final DynamicCommandExceptionType INVALID_HOVER_ACTION = new DynamicCommandExceptionType(action -> Text.translatable("commands.client.invalidHoverAction", action));
43+
private static final DynamicCommandExceptionType INVALID_HOVER_EVENT = new DynamicCommandExceptionType(event -> Text.translatable("commands.client.invalidHoverEvent", event));
2444

2545
private FormattedTextArgumentType() {
2646
}
@@ -177,28 +197,54 @@ static class FormattedText {
177197
.put("hex", new Styler((s, o) -> s.withColor(TextColor.fromRgb(Integer.parseInt(o.get(0), 16))), 1))
178198
.put("insert", new Styler((s, o) -> s.withInsertion(o.get(0)), 1))
179199

180-
.put("click", new Styler((s, o) -> s.withClickEvent(new ClickEvent(ClickEvent.Action.byName(o.get(0)), o.get(1))), 2, "change_page", "copy_to_clipboard", "open_file", "open_url", "run_command", "suggest_command"))
181-
.put("hover", new Styler((s, o) -> s.withHoverEvent(HoverEvent.Action.byName(o.get(0)).buildHoverEvent(Text.of(o.get(1)))), 2, "show_entity", "show_item", "show_text"))
200+
.put("click", new Styler((s, o) -> s.withClickEvent(parseClickEvent(o.get(0), o.get(1))), 2, "change_page", "copy_to_clipboard", "open_file", "open_url", "run_command", "suggest_command"))
201+
.put("hover", new Styler((s, o) -> s.withHoverEvent(parseHoverEvent(o.get(0), o.get(1))), 2, "show_entity", "show_item", "show_text"))
182202

183203
// aliases
184204
.put("strike", new Styler((s, o) -> s.withFormatting(Formatting.STRIKETHROUGH), 0))
185205
.put("magic", new Styler((s, o) -> s.withFormatting(Formatting.OBFUSCATED), 0))
186206
.build();
187207

188-
private final BiFunction<Style, List<String>, Style> styler;
208+
private final StylerFunc styler;
189209
private final MutableText argument;
190-
private final List<String> optional;
210+
private final List<String> args;
191211

192-
public FormattedText(BiFunction<Style, List<String>, Style> styler, MutableText argument, List<String> optional) {
212+
public FormattedText(StylerFunc styler, MutableText argument, List<String> args) {
193213
this.styler = styler;
194214
this.argument = argument;
195-
this.optional = optional;
215+
this.args = args;
216+
}
217+
218+
public MutableText style() throws CommandSyntaxException {
219+
return this.argument.setStyle(this.styler.apply(this.argument.getStyle(), this.args));
220+
}
221+
222+
private record Styler(StylerFunc operator, int argumentCount, String... suggestions) {}
223+
224+
@FunctionalInterface
225+
interface StylerFunc {
226+
Style apply(Style style, List<String> args) throws CommandSyntaxException;
196227
}
197228

198-
public MutableText style() {
199-
return this.argument.setStyle(this.styler.apply(this.argument.getStyle(), this.optional));
229+
private static final Function<String, ClickEvent.Action> CLICK_EVENT_ACTION_BY_NAME = StringIdentifiable.createMapper(ClickEvent.Action.values(), Function.identity());
230+
231+
private static ClickEvent parseClickEvent(String name, String value) throws CommandSyntaxException {
232+
ClickEvent.Action action = CLICK_EVENT_ACTION_BY_NAME.apply(name);
233+
if (action == null) {
234+
throw INVALID_CLICK_ACTION.create(name);
235+
}
236+
return new ClickEvent(action, value);
200237
}
201238

202-
private record Styler(BiFunction<Style, List<String>, Style> operator, int argumentCount, String... suggestions) {}
239+
private static HoverEvent parseHoverEvent(String name, String value) throws CommandSyntaxException {
240+
HoverEvent.Action<?> action = HoverEvent.Action.UNVALIDATED_CODEC.parse(JsonOps.INSTANCE, new JsonPrimitive(name)).result().orElse(null);
241+
if (action == null) {
242+
throw INVALID_HOVER_ACTION.create(name);
243+
}
244+
245+
JsonElement text = Util.getResult(TextCodecs.CODEC.encodeStart(JsonOps.INSTANCE, Text.of(value)), IllegalStateException::new);
246+
HoverEvent.EventData<?> eventData = Util.getResult(((HoverEventActionAccessor) action).getLegacyCodec().parse(JsonOps.INSTANCE, text), error -> INVALID_HOVER_EVENT.create(value));
247+
return new HoverEvent(eventData);
248+
}
203249
}
204250
}

src/main/java/net/earthcomputer/clientcommands/features/Relogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package net.earthcomputer.clientcommands.features;
22

33
import net.minecraft.client.MinecraftClient;
4-
import net.minecraft.client.gui.screen.ConnectScreen;
54
import net.minecraft.client.gui.screen.MessageScreen;
65
import net.minecraft.client.gui.screen.TitleScreen;
6+
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
77
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
88
import net.minecraft.client.network.ServerAddress;
99
import net.minecraft.client.network.ServerInfo;
@@ -64,7 +64,7 @@ public static boolean relog() {
6464
return false;
6565
}
6666
mc.setScreenAndRender(new MessageScreen(Text.translatable("selectWorld.data_read")));
67-
mc.createIntegratedServerLoader().start(mc.currentScreen, levelName);
67+
mc.createIntegratedServerLoader().start(levelName, () -> mc.setScreen(new TitleScreen()));
6868
return true;
6969
} else {
7070
ServerInfo serverInfo = mc.getCurrentServerEntry();

0 commit comments

Comments
 (0)