Skip to content

Commit

Permalink
Port to 1.20.3-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Dec 3, 2023
1 parent e346358 commit ecf3eb4
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 41 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ dependencies {

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

modRuntimeOnly 'me.djtheredstoner:DevAuth-fabric:1.1.0'
modRuntimeOnly('me.djtheredstoner:DevAuth-fabric:1.1.0') {
exclude group: 'net.fabricmc', module: 'fabric-loader'
}
}

jar {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.20.2
minecraft_version_dependency=1.20.2
minecraft_version_list=1.20.2
minecraft_version_list_presentable=1.20.2
yarn_mappings=1.20.2+build.4
minecraft_version=1.20.3-rc1
minecraft_version_dependency=1.20.3-rc.1
minecraft_version_list=1.20.3-rc1
minecraft_version_list_presentable=1.20.3-rc1
yarn_mappings=1.20.3-rc1+build.2
loader_version=0.15.0

# Mod Properties
Expand All @@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx2G

# Dependencies
# also check this on https://fabricmc.net/develop/
fabric_version=0.91.1+1.20.2
fabric_version=0.91.1+1.20.3
clientarguments_version=1.6
betterconfig_version=1.2.1
seedfinding_core_version=1.192.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandException;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -35,7 +34,7 @@ private static boolean enchantmentPredicate(Item item, Enchantment ench) {
return !ench.isTreasure() && ench.isAvailableForRandomSelection() && (item == Items.BOOK || ench.target.isAcceptableItem(item));
}

private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) throws CommandException {
private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) {
if (!Configs.getEnchantingPrediction()) {
Text text = Text.translatable("commands.cenchant.needEnchantingPrediction")
.formatted(Formatting.RED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class FakeCommandSource extends ServerCommandSource {
public FakeCommandSource(ClientPlayerEntity player) {
super(player, player.getPos(), player.getRotationClient(), null, 314159265, player.getEntityName(), player.getName(), null, player);
super(player, player.getPos(), player.getRotationClient(), null, 314159265, player.getNameForScoreboard(), player.getName(), null, player);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static int glowBlock(FabricClientCommandSource source, BlockPos pos1, Bl
boundingBoxes.replaceAll((box) -> box.offset(pos1));
}
} else {
boundingBoxes.add(new Box(pos1, pos2));
boundingBoxes.add(Box.enclosing(pos1, pos2));
}

for (Box box : boundingBoxes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ private static void saveFile() throws CommandSyntaxException {
});
rootTag.putInt("DataVersion", SharedConstants.getGameVersion().getSaveVersion().getId());
rootTag.put("Groups", compoundTag);
File newFile = File.createTempFile("groups", ".dat", configPath.toFile());
Path newFile = File.createTempFile("groups", ".dat", configPath.toFile()).toPath();
NbtIo.write(rootTag, newFile);
File backupFile = new File(configPath.toFile(), "groups.dat_old");
File currentFile = new File(configPath.toFile(), "groups.dat");
Path backupFile = configPath.resolve("groups.dat_old");
Path currentFile = configPath.resolve("groups.dat");
Util.backupAndReplace(currentFile, newFile, backupFile);
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -238,7 +238,7 @@ private static void saveFile() throws CommandSyntaxException {

private static void loadFile() throws IOException {
groups.clear();
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "groups.dat"));
NbtCompound rootTag = NbtIo.read(configPath.resolve("groups.dat"));
if (rootTag == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ private static void saveFile() throws CommandSyntaxException {
kits.forEach(compoundTag::put);
rootTag.putInt("DataVersion", SharedConstants.getGameVersion().getSaveVersion().getId());
rootTag.put("Kits", compoundTag);
File newFile = File.createTempFile("kits", ".dat", configPath.toFile());
Path newFile = File.createTempFile("kits", ".dat", configPath.toFile()).toPath();
NbtIo.write(rootTag, newFile);
File backupFile = new File(configPath.toFile(), "kits.dat_old");
File currentFile = new File(configPath.toFile(), "kits.dat");
Path backupFile = configPath.resolve("kits.dat_old");
Path currentFile = configPath.resolve("kits.dat");;
Util.backupAndReplace(currentFile, newFile, backupFile);
} catch (IOException e) {
throw SAVE_FAILED_EXCEPTION.create();
Expand All @@ -189,7 +189,7 @@ private static void saveFile() throws CommandSyntaxException {

private static void loadFile() throws IOException {
kits.clear();
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "kits.dat"));
NbtCompound rootTag = NbtIo.read(configPath.resolve("kits.dat"));
if (rootTag == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ private static void saveFile() throws CommandSyntaxException {
try {
NbtCompound rootTag = new NbtCompound();
variables.forEach(rootTag::putString);
File newFile = File.createTempFile("vars", ".dat", configPath.toFile());
Path newFile = File.createTempFile("vars", ".dat", configPath.toFile()).toPath();
NbtIo.write(rootTag, newFile);
File backupFile = new File(configPath.toFile(), "vars.dat_old");
File currentFile = new File(configPath.toFile(), "vars.dat");
Path backupFile = configPath.resolve("vars.dat_old");
Path currentFile = configPath.resolve("vars.dat");
Util.backupAndReplace(currentFile, newFile, backupFile);
} catch (IOException e) {
throw SAVE_FAILED_EXCEPTION.create();
Expand All @@ -135,7 +135,7 @@ private static void saveFile() throws CommandSyntaxException {

private static void loadFile() throws IOException {
variables.clear();
NbtCompound rootTag = NbtIo.read(new File(configPath.toFile(), "vars.dat"));
NbtCompound rootTag = NbtIo.read(configPath.resolve("vars.dat"));
if (rootTag == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
package net.earthcomputer.clientcommands.command.arguments;

import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.mojang.serialization.JsonOps;
import net.earthcomputer.clientcommands.mixin.HoverEventActionAccessor;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.text.*;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

import java.util.*;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.Util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

public class FormattedTextArgumentType implements ArgumentType<MutableText> {

private static final Collection<String> EXAMPLES = Arrays.asList("Earth", "bold{xpple}", "bold{italic{red{nwex}}}");
private static final DynamicCommandExceptionType INVALID_CLICK_ACTION = new DynamicCommandExceptionType(action -> Text.translatable("commands.client.invalidClickAction", action));
private static final DynamicCommandExceptionType INVALID_HOVER_ACTION = new DynamicCommandExceptionType(action -> Text.translatable("commands.client.invalidHoverAction", action));
private static final DynamicCommandExceptionType INVALID_HOVER_EVENT = new DynamicCommandExceptionType(event -> Text.translatable("commands.client.invalidHoverEvent", event));

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

.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"))
.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"))
.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"))
.put("hover", new Styler((s, o) -> s.withHoverEvent(parseHoverEvent(o.get(0), o.get(1))), 2, "show_entity", "show_item", "show_text"))

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

private final BiFunction<Style, List<String>, Style> styler;
private final StylerFunc styler;
private final MutableText argument;
private final List<String> optional;
private final List<String> args;

public FormattedText(BiFunction<Style, List<String>, Style> styler, MutableText argument, List<String> optional) {
public FormattedText(StylerFunc styler, MutableText argument, List<String> args) {
this.styler = styler;
this.argument = argument;
this.optional = optional;
this.args = args;
}

public MutableText style() throws CommandSyntaxException {
return this.argument.setStyle(this.styler.apply(this.argument.getStyle(), this.args));
}

private record Styler(StylerFunc operator, int argumentCount, String... suggestions) {}

@FunctionalInterface
interface StylerFunc {
Style apply(Style style, List<String> args) throws CommandSyntaxException;
}

public MutableText style() {
return this.argument.setStyle(this.styler.apply(this.argument.getStyle(), this.optional));
private static final Function<String, ClickEvent.Action> CLICK_EVENT_ACTION_BY_NAME = StringIdentifiable.createMapper(ClickEvent.Action.values(), Function.identity());

private static ClickEvent parseClickEvent(String name, String value) throws CommandSyntaxException {
ClickEvent.Action action = CLICK_EVENT_ACTION_BY_NAME.apply(name);
if (action == null) {
throw INVALID_CLICK_ACTION.create(name);
}
return new ClickEvent(action, value);
}

private record Styler(BiFunction<Style, List<String>, Style> operator, int argumentCount, String... suggestions) {}
private static HoverEvent parseHoverEvent(String name, String value) throws CommandSyntaxException {
HoverEvent.Action<?> action = HoverEvent.Action.UNVALIDATED_CODEC.parse(JsonOps.INSTANCE, new JsonPrimitive(name)).result().orElse(null);
if (action == null) {
throw INVALID_HOVER_ACTION.create(name);
}

JsonElement text = Util.getResult(TextCodecs.CODEC.encodeStart(JsonOps.INSTANCE, Text.of(value)), IllegalStateException::new);
HoverEvent.EventData<?> eventData = Util.getResult(((HoverEventActionAccessor) action).getLegacyCodec().parse(JsonOps.INSTANCE, text), error -> INVALID_HOVER_EVENT.create(value));
return new HoverEvent(eventData);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.earthcomputer.clientcommands.features;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.gui.screen.MessageScreen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
Expand Down Expand Up @@ -64,7 +64,7 @@ public static boolean relog() {
return false;
}
mc.setScreenAndRender(new MessageScreen(Text.translatable("selectWorld.data_read")));
mc.createIntegratedServerLoader().start(mc.currentScreen, levelName);
mc.createIntegratedServerLoader().start(levelName, () -> mc.setScreen(new TitleScreen()));
return true;
} else {
ServerInfo serverInfo = mc.getCurrentServerEntry();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.earthcomputer.clientcommands.mixin;

import com.mojang.serialization.Codec;
import net.minecraft.text.HoverEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(HoverEvent.Action.class)
public interface HoverEventActionAccessor {
@Accessor
Codec<HoverEvent.EventData<?>> getLegacyCodec();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onRightClickBlock(ClientPlayerEntity player, Hand hand, BlockHitResu
}
}

@Inject(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"))
@Inject(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/block/BlockState;"))
public void onBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> ci) {
World world = MinecraftClient.getInstance().world;
ClientPlayerEntity player = MinecraftClient.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
import net.earthcomputer.clientcommands.render.RenderQueue;
import net.earthcomputer.clientcommands.task.TaskManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.*;
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.MessageScreen;
import net.minecraft.client.gui.screen.ProgressScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.world.LevelLoadingScreen;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/clientcommands/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
"commands.client.enable": "Enable",
"commands.client.expectedRegex": "Invalid regex %s",
"commands.client.invalidArgumentException": "Invalid argument '%s'",
"commands.client.invalidClickAction": "Invalid click event action '%s'",
"commands.client.invalidHoverAction": "Invalid hover event action '%s'",
"commands.client.invalidHoverEvent": "Invalid hover event '%s'",
"commands.client.notClient": "Not a client-side command",
"commands.client.requiresRestart": "This change will take effect after you restart your client",
"commands.client.tooFewArguments": "Too few arguments",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/clientcommands.aw
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ accessible class net/minecraft/client/render/RenderPhase$LineWidth
accessible field net/minecraft/client/network/DataQueryHandler expectedTransactionId I

accessible method net/minecraft/client/MinecraftClient openChatScreen (Ljava/lang/String;)V

accessible method net/minecraft/text/HoverEvent <init> (Lnet/minecraft/text/HoverEvent$EventData;)V
accessible class net/minecraft/text/HoverEvent$EventData
1 change: 1 addition & 0 deletions src/main/resources/mixins.clientcommands.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
"ChatInputSuggestorAccessor",
"CheckedRandomAccessor",
"HoverEventActionAccessor",
"InGameHudAccessor",
"LandPathNodeMakerAccessor",
"MixinAnvilContainer",
Expand Down

0 comments on commit ecf3eb4

Please sign in to comment.