From 30209fff1112f65add699ffb53fa70efcc43ac7c Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sun, 3 May 2026 17:12:45 +0200 Subject: [PATCH 1/8] fix server side /g --- .../redstone/redstonetools/features/commands/GiveMeFeature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java index f0b733c4..2455cab4 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java @@ -43,7 +43,7 @@ private int execute(CommandContext context, ItemStackArgume ItemStack stack = itemArgument.createStack(1, false); stack.setCount(count); server.getCommandManager()./*? if <1.21.10 {*//*executeWithPrefix*//*?} else {*/parseAndExecute/*?}*/( - server.getCommandSource(), "/give @s " + itemArgument.asString(server.getRegistryManager()) + " " + count); + server.getCommandSource(), "/give " + context.getSource().getName() + " " + itemArgument.asString(server.getRegistryManager()) + " " + count); return 0; } } From b9b2a56cfc9c0cd717c255fe8c0634afc30312c5 Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sun, 3 May 2026 17:14:42 +0200 Subject: [PATCH 2/8] update name for chat config --- .../java/tools/redstone/redstonetools/config/ClientData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/java/tools/redstone/redstonetools/config/ClientData.java b/src/client/java/tools/redstone/redstonetools/config/ClientData.java index 51d05d86..8c1e9561 100644 --- a/src/client/java/tools/redstone/redstonetools/config/ClientData.java +++ b/src/client/java/tools/redstone/redstonetools/config/ClientData.java @@ -5,7 +5,7 @@ import kr1v.malilibApi.annotation.Config; import tools.redstone.redstonetools.RedstoneTools; -@Config(RedstoneTools.MOD_ID) +@Config(value = RedstoneTools.MOD_ID, name = "Chat") public class ClientData { public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true, """ From a50126e7b609ba62299fd53039fb381c6f80a200 Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sat, 30 May 2026 12:53:59 +0200 Subject: [PATCH 3/8] Mojang Mappings Time --- build.gradle.kts | 10 +- .../redstonetools/ClientCommands.java | 20 +- .../redstonetools/RedstoneToolsClient.java | 14 +- .../redstonetools/config/MacroManager.java | 2 +- .../config/option/ConfigMacro.java | 18 +- .../features/commands/BaseConvertClient.java | 4 +- .../features/commands/ClientDataFeature.java | 8 +- .../features/commands/EditMacroFeature.java | 8 +- .../features/commands/GiveMeClient.java | 20 +- .../features/commands/MacroFeature.java | 4 +- .../features/commands/PrintFeature.java | 8 +- .../features/commands/QuickTpClient.java | 6 +- .../features/commands/ReachClient.java | 24 +- .../features/commands/RstFeature.java | 8 +- .../commands/argument/MacroArgumentType.java | 8 +- .../features/toggleable/AirPlaceFeature.java | 126 +++++----- .../features/toggleable/AutoDustClient.java | 4 +- .../features/toggleable/AutoRotateClient.java | 4 +- .../features/toggleable/BigDustFeature.java | 4 +- .../toggleable/ClickContainerClient.java | 4 +- .../toggleable/ClientToggleableFeature.java | 6 +- .../macros/actions/CommandAction.java | 8 +- .../redstonetools/malilib/GuiMacroEditor.java | 64 +++-- .../malilib/widget/WidgetBaseWrapper.java | 63 ++--- .../widget/action/CommandListWidget.java | 226 +++++++++--------- .../mixin/blocks/RedstoneHitboxMixin.java | 24 +- .../mixin/features/AirPlaceClientMixin.java | 34 +-- .../mixin/features/AutoRotateClientMixin.java | 14 +- .../mixin/features/ChatHudMixin.java | 10 +- .../features/ChatInputSuggestorAccessor.java | 10 +- .../features/ChatInputSuggestorMixin.java | 30 +-- .../ClientPlayNetworkHandlerMixin.java | 34 +-- .../mixin/features/CommandSourceMixin.java | 10 +- .../features/ItemBindItemStackMixin.java | 26 +- .../features/SuggestionWindowAccessor.java | 8 +- .../mixin/features/SuggestionWindowMixin.java | 18 +- .../features/TextFieldWidgetAccessor.java | 12 +- .../mixin/features/WorldRendererInvoker.java | 30 ++- .../mixin/macros/AddMacroButtonMixin.java | 21 +- .../redstone/redstonetools/Commands.java | 19 +- .../redstonetools/RedstoneToolsGameRules.java | 35 +-- .../features/commands/BaseConvertFeature.java | 27 +-- .../commands/BinaryBlockReadFeature.java | 43 ++-- .../commands/BlockRaycastFeature.java | 32 +-- .../features/commands/ColorCodeFeature.java | 19 +- .../features/commands/ColoredFeature.java | 17 +- .../features/commands/CopyStateFeature.java | 45 ++-- .../features/commands/GiveMeFeature.java | 31 ++- .../features/commands/ItemBindFeature.java | 57 +++-- .../commands/ItemComponentsFeature.java | 41 ++-- .../commands/MinSelectionFeature.java | 19 +- .../features/commands/PickBlockFeature.java | 65 ++--- .../features/commands/QuickTpFeature.java | 47 ++-- .../features/commands/RStackFeature.java | 25 +- .../features/commands/ReachFeature.java | 37 ++- .../commands/SignalStrengthBlockFeature.java | 25 +- .../features/toggleable/AutoDustFeature.java | 12 +- .../toggleable/AutoRotateFeature.java | 10 +- .../toggleable/ClickContainerFeature.java | 86 +++---- .../toggleable/ToggleableFeature.java | 40 ++-- .../mixin/AbstractBlockMixin.java | 14 +- .../mixin/features/AutoDustMixin.java | 44 ++-- .../mixin/features/AutoRotateMixin.java | 28 +-- .../mixin/features/CommandManagerMixin.java | 14 +- .../features/PlayerInventoryAccessor.java | 12 +- .../ServerPlayNetworkHandlerAccessor.java | 14 +- .../gamerules/DoContainerDropsMixin.java | 24 +- .../packets/SetFeatureEnabledPayload.java | 31 ++- .../redstonetools/utils/ArgumentUtils.java | 39 ++- .../redstonetools/utils/BlockColor.java | 3 +- .../redstonetools/utils/BlockInfo.java | 8 +- .../redstonetools/utils/ColoredBlock.java | 16 +- .../redstonetools/utils/ColoredBlockType.java | 14 +- .../redstonetools/utils/ItemUtils.java | 58 ++--- .../redstonetools/utils/PlayerUtils.java | 12 +- .../redstonetools/utils/PositionUtils.java | 8 +- .../redstonetools/utils/RaycastUtils.java | 24 +- .../redstonetools/utils/SignalBlock.java | 7 +- .../utils/SignalBlockSupplier.java | 54 ++--- .../redstonetools/utils/WorldEditUtils.java | 8 +- stonecutter.gradle.kts | 2 +- 81 files changed, 1069 insertions(+), 1049 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ba8c17a5..c9669e0f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,15 +23,15 @@ loom { } stonecutter { - swaps["mouse_clicked_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "Click click, boolean doubleClick" // mouseClicked + swaps["mouse_clicked_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "MouseButtonEvent click, boolean doubleClick" // mouseClicked swaps["mouse_clicked_args"] = if (current.parsed < "1.21.10") "mouseX, mouseY, button" else "click, doubleClick" swaps["on_mouse_clicked_args"] = if (current.parsed < "1.21.10") "(int) mouseX, (int) mouseY, button" else "click, doubleClick" // onMouseClicked - swaps["dragged_released_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "Click click" // mouseDragged, mouseReleased + swaps["dragged_released_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "MouseButtonEvent click" // mouseDragged, mouseReleased swaps["dragged_released_args"] = if (current.parsed < "1.21.10") "mouseX, mouseY, button" else "click" swaps["on_released_args"] = if (current.parsed < "1.21.10") "(int) mouseX, (int) mouseY, button" else "click" // onMouseReleased - swaps["keyinput_params"] = if (current.parsed < "1.21.10") "int keyCode, int scanCode, int modifiers" else "KeyInput input" // keyPressed, keyReleased + swaps["keyinput_params"] = if (current.parsed < "1.21.10") "int keyCode, int scanCode, int modifiers" else "KeyEvent input" // keyPressed, keyReleased swaps["keyinput_args"] = if (current.parsed < "1.21.10") "keyCode, scanCode, modifiers" else "input" - swaps["charinput_params"] = if (current.parsed < "1.21.10") "char chr, int modifiers" else "CharInput input" // charTyped + swaps["charinput_params"] = if (current.parsed < "1.21.10") "char chr, int modifiers" else "CharacterEvent input" // charTyped swaps["charinput_args"] = if (current.parsed < "1.21.10") "chr, modifiers" else "input" swaps["click_and_inputs_imports"] = if (current.parsed < "1.21.10") "" else "//\nimport net.minecraft.client.gui.Click;\nimport net.minecraft.client.input.KeyInput;\nimport net.minecraft.client.input.CharInput;" @@ -71,7 +71,7 @@ repositories { dependencies { minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") - mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2") + mappings(loom.officialMojangMappings()) modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") diff --git a/src/client/java/tools/redstone/redstonetools/ClientCommands.java b/src/client/java/tools/redstone/redstonetools/ClientCommands.java index 4409ba68..8981f1c1 100644 --- a/src/client/java/tools/redstone/redstonetools/ClientCommands.java +++ b/src/client/java/tools/redstone/redstonetools/ClientCommands.java @@ -2,12 +2,12 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.commands.CommandBuildContext; //? if >=1.21.11 { -import net.minecraft.command.DefaultPermissions; -import net.minecraft.command.permission.PermissionCheck; -import net.minecraft.server.command.CommandManager; -//?} +/*import net.minecraft.commands.Commands; +import net.minecraft.server.permissions.PermissionCheck; +import net.minecraft.server.permissions.Permissions; +*///?} import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature; import tools.redstone.redstonetools.features.toggleable.BigDustFeature; @@ -18,12 +18,12 @@ public class ClientCommands { public static final Predicate PERMISSION_LEVEL_2 = //? if <=1.21.10 { - /*source -> source.getPlayer().hasPermissionLevel(2); - *///?} else { - CommandManager.requirePermissionLevel(new PermissionCheck.Require(DefaultPermissions.GAMEMASTERS)); - //?} + source -> source.getPlayer().hasPermissions(2); + //?} else { + /*Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); + *///?} - public static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public static void registerCommands(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { if (!DependencyLookup.REDSTONE_TOOLS_SERVER_PRESENT) { BaseConvertClient.INSTANCE.registerCommand(dispatcher, registryAccess); ReachClient.INSTANCE.registerCommand(dispatcher, registryAccess); diff --git a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java index 660371ac..7b878077 100644 --- a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java +++ b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java @@ -17,27 +17,27 @@ public void onInitializeClient() { MalilibApi.registerMod(MOD_ID, MOD_NAME); ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { - if (client.getNetworkHandler() != null) { // dimension change + if (client.getConnection() != null) { // dimension change String dimensionChange = ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue(); if (dimensionChange.startsWith("/")) { - client.getNetworkHandler().sendChatCommand(dimensionChange.substring(1)); + client.getConnection().sendCommand(dimensionChange.substring(1)); } else if (!dimensionChange.isEmpty()){ - client.getNetworkHandler().sendChatMessage(dimensionChange); + client.getConnection().sendChat(dimensionChange); } } else { // world entry String worldEntry = ClientData.AUTORUN_WORLD_ENTRY.getStringValue(); if (worldEntry.startsWith("/")) { - client.send(() -> client.getNetworkHandler().sendChatCommand(worldEntry.substring(1))); + client.execute(() -> client.getConnection().sendCommand(worldEntry.substring(1))); } else if (!worldEntry.isEmpty()){ - client.send(() -> client.getNetworkHandler().sendChatMessage(worldEntry)); + client.execute(() -> client.getConnection().sendChat(worldEntry)); } if (hasRanCommands) return; hasRanCommands = true; String firstWorldEntry = ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue(); if (firstWorldEntry.startsWith("/")) { - client.send(() -> client.getNetworkHandler().sendChatCommand(firstWorldEntry.substring(1))); + client.execute(() -> client.getConnection().sendCommand(firstWorldEntry.substring(1))); } else if (!firstWorldEntry.isEmpty()) { - client.send(() -> client.getNetworkHandler().sendChatMessage(firstWorldEntry)); + client.execute(() -> client.getConnection().sendChat(firstWorldEntry)); } } }); diff --git a/src/client/java/tools/redstone/redstonetools/config/MacroManager.java b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java index ec8b4c25..ffaaada0 100644 --- a/src/client/java/tools/redstone/redstonetools/config/MacroManager.java +++ b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java @@ -37,7 +37,7 @@ public static List getDefaultMacros() { "/gamerule doDaylightCycle false", "/gamerule doMobSpawning false", //? if <1.21.11 - //"/gamerule doContainerDrops false", + "/gamerule doContainerDrops false", "/time set noon", "/weather clear" }), diff --git a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java index 49eb13ca..5f83135d 100644 --- a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java +++ b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java @@ -12,8 +12,8 @@ import kr1v.malilibApi.MalilibApi; import kr1v.malilibApi.config._new.CustomConfigBase; import kr1v.malilibApi.interfaces.IHotkeyContainer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; import tools.redstone.redstonetools.config.MacroManager; import tools.redstone.redstonetools.macros.actions.Action; import tools.redstone.redstonetools.macros.actions.CommandAction; @@ -114,9 +114,9 @@ public void resetToDefault() { static { MalilibApi.registerButtonBasedConfigType(ConfigMacro.class, (widgetConfigOption, configMacro, x, y, configWidth, configHeight) -> new ButtonGeneric(x, y, configWidth, configHeight, configMacro.getMacroName()) { @Override - protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/net.minecraft.client.gui.Click click, boolean doubleClick/*? } else {*//*int mouseX, int mouseY, int mouseButton*//*? }*/) { - super.onMouseClickedImpl(/*? if >=1.21.10 {*/click, doubleClick/*? } else {*//*mouseX, mouseY, mouseButton*//*? }*/); - GuiBase.openGui(new GuiMacroEditor(Text.of(configMacro.macroName), configMacro, MinecraftClient.getInstance().currentScreen)); + protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*//*net.minecraft.client.input.MouseButtonEvent click, boolean doubleClick*//*? } else {*/int mouseX, int mouseY, int mouseButton/*? }*/) { + super.onMouseClickedImpl(/*? if >=1.21.10 {*//*click, doubleClick*//*? } else {*/mouseX, mouseY, mouseButton/*? }*/); + GuiBase.openGui(new GuiMacroEditor(Component.nullToEmpty(configMacro.macroName), configMacro, Minecraft.getInstance().screen)); return true; } }); @@ -181,8 +181,8 @@ public void run() { if (muted) MacroManager.shouldMute = true; if (!enabled) return; if (layers.getAndSet(layers.get() + 1) > 100) { - assert MinecraftClient.getInstance().player != null; - MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); + assert Minecraft.getInstance().player != null; + Minecraft.getInstance().player.displayClientMessage(Component.nullToEmpty("Please don't cause a stackoverflow :("), false); return; } try { @@ -191,8 +191,8 @@ public void run() { } } catch (StackOverflowError ignored) { try { - assert MinecraftClient.getInstance().player != null; - MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); + assert Minecraft.getInstance().player != null; + Minecraft.getInstance().player.displayClientMessage(Component.nullToEmpty("Please don't cause a stackoverflow :("), false); } catch (NoClassDefFoundError e) { // yeah we are absolutely cooked, there is no way to recover from this. I'm not even sure this can happen // actually there's probably a better throwable to be thrown here. whatever. diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java index 72869ffc..fab331a1 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java @@ -5,7 +5,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.commands.CommandBuildContext; public class BaseConvertClient { @@ -13,7 +13,7 @@ public class BaseConvertClient { protected BaseConvertClient() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register( ClientCommandManager.literal("base") .then(ClientCommandManager.argument("inputNum", StringArgumentType.word()) diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java index 850322ae..2eb6d099 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java @@ -3,8 +3,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.network.chat.Component; import java.util.HashMap; import java.util.Map; @@ -16,7 +16,7 @@ public class ClientDataFeature { public Map variables = new HashMap<>(); public static final ClientDataFeature INSTANCE = new ClientDataFeature(); - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(literal("clientdata") .then(literal("set") .then(argument("name", StringArgumentType.word()) @@ -25,7 +25,7 @@ public void registerCommand(CommandDispatcher dispatc String name = StringArgumentType.getString(context, "name"); String value = StringArgumentType.getString(context, "value"); variables.put(name, value); - context.getSource().sendFeedback(Text.of("Set " + name + " to \"" + value + "\"")); + context.getSource().sendFeedback(Component.literal("Set " + name + " to \"" + value + "\"")); return 1; } ) diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java index bf55d414..9bccdfdc 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java @@ -5,8 +5,8 @@ import kr1v.malilibApi.MalilibApi; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.client.Minecraft; +import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.Macros; @@ -17,10 +17,10 @@ public class EditMacroFeature { protected EditMacroFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(ClientCommandManager.literal("edit-macros") .executes(commandContext -> { - MinecraftClient.getInstance().send(() -> { + Minecraft.getInstance().execute(() -> { InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(Macros.getTab()); MalilibApi.openScreenFor(RedstoneTools.MOD_ID); }); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java index 1931aea9..af6893f5 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java @@ -4,9 +4,9 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.ItemStackArgument; -import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.arguments.item.ItemArgument; +import net.minecraft.commands.arguments.item.ItemInput; import tools.redstone.redstonetools.ClientCommands; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; @@ -18,27 +18,27 @@ public class GiveMeClient { protected GiveMeClient() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register( literal("g") .requires(ClientCommands.PERMISSION_LEVEL_2) - .then(argument("item", ItemStackArgumentType.itemStack(registryAccess)) + .then(argument("item", ItemArgument.item(registryAccess)) .executes(context -> this.execute( context, registryAccess, - ItemStackArgumentType.getItemStackArgument(context, "item"), + ItemArgument.getItem(context, "item"), 1)) .then(argument("count", IntegerArgumentType.integer(1)) .executes(context -> this.execute( context, registryAccess, - ItemStackArgumentType.getItemStackArgument(context, "item"), + ItemArgument.getItem(context, "item"), IntegerArgumentType.getInteger(context, "count")))))); } - private int execute(CommandContext context, CommandRegistryAccess registryAccess, ItemStackArgument itemArgument, int count) { - context.getSource().getPlayer().networkHandler.sendChatCommand( - "give @s " + itemArgument.asString(registryAccess) + " " + count + private int execute(CommandContext context, CommandBuildContext registryAccess, ItemInput itemArgument, int count) { + context.getSource().getPlayer().connection.sendCommand( + "give @s " + itemArgument.serialize(registryAccess) + " " + count ); return 0; } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java index ce7e85d4..c7d7daf5 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.config.option.ConfigMacro; import tools.redstone.redstonetools.features.commands.argument.MacroArgumentType; @@ -17,7 +17,7 @@ public class MacroFeature { protected MacroFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(literal("macro") .then(argument("macro", MacroArgumentType.macro()) .executes(this::execute))); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java index eb538655..f7b8d928 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java @@ -3,8 +3,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.network.chat.Component; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; @@ -12,11 +12,11 @@ public class PrintFeature { public static final PrintFeature INSTANCE = new PrintFeature(); - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(literal("print") .then(argument("text", StringArgumentType.greedyString()) .executes((context -> { - context.getSource().sendFeedback(Text.of(StringArgumentType.getString(context, "text"))); + context.getSource().sendFeedback(Component.literal(StringArgumentType.getString(context, "text"))); return 1; }) ) diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java index 01e3b7b0..41464c0c 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.context.CommandContext; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.ClientCommands; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -16,7 +16,7 @@ public class QuickTpClient { protected QuickTpClient() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register( literal("quicktp") .requires(ClientCommands.PERMISSION_LEVEL_2) @@ -31,7 +31,7 @@ public void registerCommand(CommandDispatcher dispatc } private int execute(CommandContext context, float distance) { - context.getSource().getPlayer().networkHandler.sendChatCommand( + context.getSource().getPlayer().connection.sendCommand( "tp @s ^ ^ ^" + distance ); return 0; diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java index eabafcb0..e584bfc5 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java @@ -5,9 +5,9 @@ import com.mojang.brigadier.context.CommandContext; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.world.entity.ai.attributes.Attributes; import tools.redstone.redstonetools.ClientCommands; @@ -17,7 +17,7 @@ public class ReachClient { protected ReachClient() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(ClientCommandManager.literal("reach") .requires(ClientCommands.PERMISSION_LEVEL_2) .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) @@ -29,7 +29,7 @@ public void registerCommand(CommandDispatcher dispatc .then(ClientCommandManager.literal("block") .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { - builder.suggest(String.valueOf(EntityAttributes.BLOCK_INTERACTION_RANGE.value().getDefaultValue())); + builder.suggest(String.valueOf(Attributes.BLOCK_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); }) .executes(context -> execute(context, true, false)) @@ -38,7 +38,7 @@ public void registerCommand(CommandDispatcher dispatc .then(ClientCommandManager.literal("entity") .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { - builder.suggest(String.valueOf(EntityAttributes.ENTITY_INTERACTION_RANGE.value().getDefaultValue())); + builder.suggest(String.valueOf(Attributes.ENTITY_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); }) .executes(context -> execute(context, false, true)) @@ -48,16 +48,16 @@ public void registerCommand(CommandDispatcher dispatc private int execute(CommandContext context, boolean block, boolean entity) { float reach = FloatArgumentType.getFloat(context, "reach"); - ClientPlayNetworkHandler networkHandler = context.getSource().getPlayer().networkHandler; - if (block) networkHandler.sendChatCommand("attribute @s minecraft:block_interaction_range base set " + reach); - if (entity) networkHandler.sendChatCommand("attribute @s minecraft:entity_interaction_range base set " + reach); + ClientPacketListener networkHandler = context.getSource().getPlayer().connection; + if (block) networkHandler.sendCommand("attribute @s minecraft:block_interaction_range base set " + reach); + if (entity) networkHandler.sendCommand("attribute @s minecraft:entity_interaction_range base set " + reach); return 0; } private int reset(CommandContext context, boolean block, boolean entity) { - ClientPlayNetworkHandler networkHandler = context.getSource().getPlayer().networkHandler; - if (block) networkHandler.sendChatCommand("attribute @s minecraft:block_interaction_range base reset"); - if (entity) networkHandler.sendChatCommand("attribute @s minecraft:entity_interaction_range base reset"); + ClientPacketListener networkHandler = context.getSource().getPlayer().connection; + if (block) networkHandler.sendCommand("attribute @s minecraft:block_interaction_range base reset"); + if (entity) networkHandler.sendCommand("attribute @s minecraft:entity_interaction_range base reset"); return 0; } } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java index 8bcdf3b5..56b72607 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java @@ -5,8 +5,8 @@ import kr1v.malilibApi.MalilibApi; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.client.Minecraft; +import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.Macros; @@ -17,10 +17,10 @@ public class RstFeature { protected RstFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(ClientCommandManager.literal("rst") .executes(commandContext -> { - MinecraftClient.getInstance().send(() -> { + Minecraft.getInstance().execute(() -> { if (InternalMalilibApi.getMod(RedstoneTools.MOD_ID).activeTab() == Macros.getTab()) { InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(null); } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java b/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java index 1e8841b4..67167262 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java @@ -7,8 +7,6 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.command.CommandSource; -import net.minecraft.text.Text; import tools.redstone.redstonetools.config.MacroManager; import tools.redstone.redstonetools.config.Macros; import tools.redstone.redstonetools.config.option.ConfigMacro; @@ -17,6 +15,8 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; public class MacroArgumentType implements ArgumentType { private static final Collection EXAMPLES = List.of(" "); @@ -40,7 +40,7 @@ public ConfigMacro parse(final StringReader reader) throws CommandSyntaxExceptio final ConfigMacro macro = MacroManager.getMacro(result); if (macro == null) { reader.setCursor(start); - throw new SimpleCommandExceptionType(Text.literal("Macro '" + result + "' doesn't exist!")).create(); + throw new SimpleCommandExceptionType(Component.literal("Macro '" + result + "' doesn't exist!")).create(); } return macro; } @@ -60,6 +60,6 @@ public CompletableFuture listSuggestions(CommandContext cont List macroNamesList = new ArrayList<>(); Macros.getMacros().forEach(macro -> macroNamesList.add(macro.getMacroName())); macroNamesList.sort(String.CASE_INSENSITIVE_ORDER); - return CommandSource.suggestMatching(macroNamesList, builder); + return SharedSuggestionProvider.suggest(macroNamesList, builder); } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 410de328..8a820d93 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -1,36 +1,38 @@ package tools.redstone.redstonetools.features.toggleable; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; //? if <1.21.10 { -/*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; -*///?} else { -import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; + //?} else { +/*import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; -import net.minecraft.client.render.state.OutlineRenderState; -//?} -//? if <=1.21.10 { -/*import net.minecraft.client.render.RenderLayer; -*///?} else { -import net.minecraft.client.render.RenderLayers; -//?} -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.BlockRotation; -import net.minecraft.util.Colors; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +*///?} +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +//? if <=1.21.10 { +import net.minecraft.client.renderer.RenderType; +//? } else { +/*import net.minecraft.client.renderer.rendertype.RenderTypes; +import net.minecraft.client.renderer.state.BlockOutlineRenderState; +*///? } +//? if =1.21.10 +//import net.minecraft.client.renderer.state.BlockOutlineRenderState; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.core.BlockPos; +import net.minecraft.util.CommonColors; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; import tools.redstone.redstonetools.ClientCommands; import tools.redstone.redstonetools.config.General; import tools.redstone.redstonetools.config.Toggles; @@ -49,7 +51,7 @@ protected AirPlaceFeature() { super(Toggles.AIRPLACE); } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(literal("airplace") .requires(ClientCommands.PERMISSION_LEVEL_2) .executes(this::toggle)); @@ -57,10 +59,10 @@ public void registerCommand(CommandDispatcher dispatc public static float reach; - public static boolean canAirPlace(PlayerEntity player) { + public static boolean canAirPlace(Player player) { if (player.isSpectator()) return false; - ItemStack itemStack = player.getMainHandStack(); + ItemStack itemStack = player.getMainHandItem(); // empty slot if (itemStack == null || itemStack.getItem() == Items.AIR) @@ -73,14 +75,14 @@ public static boolean canAirPlace(PlayerEntity player) { // TODO: shouldn't offhand also be checked? // rocket boost for elytra return itemStack.getItem() != Items.FIREWORK_ROCKET || - player.getEquippedStack(EquipmentSlot.CHEST).getItem() != Items.ELYTRA || - !player.isGliding(); + player.getItemBySlot(EquipmentSlot.CHEST).getItem() != Items.ELYTRA || + !player.isFallFlying(); } - public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { - reach = (float) playerEntity.getAttributeInstance(EntityAttributes.BLOCK_INTERACTION_RANGE).getBaseValue(); + public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { + reach = (float) playerEntity.getAttribute(Attributes.BLOCK_INTERACTION_RANGE).getBaseValue(); var hit = RaycastUtils.rayCastFromEye(playerEntity, reach); - return new BlockHitResult(hit.getPos(), hit.getSide(), hit.getBlockPos(), false); + return new BlockHitResult(hit.getLocation(), hit.getDirection(), hit.getBlockPos(), false); } { @@ -91,8 +93,8 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { if (!General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) return; - MinecraftClient client = MinecraftClient.getInstance(); - if (client.player == null || client.interactionManager == null) + Minecraft client = Minecraft.getInstance(); + if (client.player == null || client.gameMode == null) return; if (crosshairTarget == null) return; @@ -105,69 +107,71 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { BlockHitResult hitResult = findAirPlaceBlockHit(client.player); BlockPos blockPos = hitResult.getBlockPos(); - if (!client.world.getBlockState(blockPos).isAir()) + if (!client.level.getBlockState(blockPos).isAir()) return; if (blockPos.getY() > 319 || blockPos.getY() < -64) return; - BlockState blockState = ItemUtils.getUseState(client.player, client.player.getMainHandStack(), reach); + BlockState blockState = ItemUtils.getUseState(client.player, client.player.getMainHandItem(), reach); if (AutoRotateClient.isEnabled.getBooleanValue()) { - blockState = blockState.rotate(BlockRotation.CLOCKWISE_180); + blockState = blockState.rotate(Rotation.CLOCKWISE_180); } if (blockState == null) return; /* render block outline */ - Camera camera = client.gameRenderer.getCamera(); - Vec3d camPos = camera - //? if <=1.21.10 { - /*.getPos(); + Camera camera = client.gameRenderer.getMainCamera(); + Vec3 camPos = camera + //? if <=1.21.5 { + .getPosition(); + //? } else if <=1.21.10 { + /*.position(); *///?} else { - .getCameraPos(); - //?} + /*.position(); + *///?} VertexConsumer consumer = context.consumers().getBuffer( //? if <=1.21.10 { - /*RenderLayer.getLines() - *///?} else { - RenderLayers.lines() - //?} + RenderType.lines() + //?} else { + /*RenderTypes.lines() + *///?} ); //? if <1.21.10 { - /*((WorldRendererInvoker) context.worldRenderer()).invokeDrawBlockOutline( + ((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( context.matrixStack(), consumer, client.player, camPos.x, camPos.y, camPos.z, blockPos, blockState, - Colors.BLACK + CommonColors.BLACK ); - *///?} else { - ((WorldRendererInvoker) context.worldRenderer()).invokeDrawBlockOutline( + //?} else { + /*((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( context.matrices(), consumer, camPos.x, camPos.y, camPos.z, - new OutlineRenderState( + new BlockOutlineRenderState( blockPos, false, false, - blockState.getOutlineShape(client.world, blockPos) + blockState.getShape(client.level, blockPos) ), - Colors.BLACK/*? if >=1.21.11 {*/, client.getWindow().getMinimumLineWidth()/*?}*/ + CommonColors.BLACK/^? if >=1.21.11 {^//^, client.getWindow().getAppropriateLineWidth()^//^?}^/ ); - //?} + *///?} }; //? if <1.21.10 { - /*WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> { + WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> { listener.accept(context, hitResult); return true; }); - *///?} else { - WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, MinecraftClient.getInstance().crosshairTarget)); - //?} + //?} else { + /*WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + *///?} } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java index 548c9567..d0684564 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java @@ -3,7 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -17,7 +17,7 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - if (MinecraftClient.getInstance().getNetworkHandler() != null) { + if (Minecraft.getInstance().getConnection() != null) { SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoDust", t.getBooleanValue()); ClientPlayNetworking.send(payload); } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java index 36134b67..875345b3 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java @@ -3,7 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -17,7 +17,7 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - if (MinecraftClient.getInstance().getNetworkHandler() != null) { + if (Minecraft.getInstance().getConnection() != null) { SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoRotate", t.getBooleanValue()); ClientPlayNetworking.send(payload); } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java index c74b4f50..56ff4a70 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java @@ -3,7 +3,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.config.Toggles; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -16,7 +16,7 @@ protected BigDustFeature() { super(Toggles.BIGDUST); } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(literal("bigdust") .executes(this::toggle) .then(argument("heightInPixels", IntegerArgumentType.integer(1, 16)) diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java index 817d9326..5d9ac122 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java @@ -3,7 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -17,7 +17,7 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - if (MinecraftClient.getInstance().getNetworkHandler() != null) { + if (Minecraft.getInstance().getConnection() != null) { SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("ClickContainers", t.getBooleanValue()); ClientPlayNetworking.send(payload); } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java index 8ab6e9f6..593aa40d 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public abstract class ClientToggleableFeature { private final ConfigBoolean enabled; // volatile for thread safety @@ -43,7 +43,7 @@ public void enable() { public int enable(FabricClientCommandSource source) throws CommandSyntaxException { enable(); - source.getPlayer().sendMessage(Text.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + source.getPlayer().displayClientMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); return 0; } @@ -54,7 +54,7 @@ public void disable() { public int disable(FabricClientCommandSource source) throws CommandSyntaxException { disable(); - source.getPlayer().sendMessage(Text.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + source.getPlayer().displayClientMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); return 0; } diff --git a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java index 27f6c9f6..65b9276d 100644 --- a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java +++ b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java @@ -1,6 +1,6 @@ package tools.redstone.redstonetools.macros.actions; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; public class CommandAction extends Action { public String command; @@ -11,12 +11,12 @@ public CommandAction(String command) { @Override public void run() { - var player = MinecraftClient.getInstance().player; + var player = Minecraft.getInstance().player; assert player != null; if (command.startsWith("/")) - player.networkHandler.sendChatCommand(command.substring(1)); + player.connection.sendCommand(command.substring(1)); else if (!command.isEmpty()) - player.networkHandler.sendChatMessage(command); + player.connection.sendChat(command); } @Override diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index eec3cadd..5371dcd1 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -8,21 +8,17 @@ import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetKeybindSettings; //? if >=1.21.11 { -import fi.dy.masa.malilib.render.GuiContext; -//?} +/*import fi.dy.masa.malilib.render.GuiContext; +*///?} import fi.dy.masa.malilib.hotkeys.IKeybind; import fi.dy.masa.malilib.hotkeys.KeybindMulti; import kr1v.malilibApi.InternalMalilibApi; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; -/*$ click_and_inputs_imports {*/// -import net.minecraft.client.gui.Click; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.input.CharInput;/*$}*/ -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.MacroManager; import tools.redstone.redstonetools.config.option.ConfigMacro; @@ -39,12 +35,12 @@ public class GuiMacroEditor extends Screen { public CommandListWidget commandList; private final IConfigBoolean enabledConfigBoolean; private final IConfigBoolean mutedConfigBoolean; - public TextFieldWidget nameWidget; + public EditBox nameWidget; private float errorCountDown; private final IKeybind keybind; private ConfigButtonKeybind buttonKeybind; - public GuiMacroEditor(Text title, ConfigMacro macro, Screen parent) { + public GuiMacroEditor(Component title, ConfigMacro macro, Screen parent) { super(title); this.parent = parent; this.macro = macro; @@ -58,10 +54,10 @@ public GuiMacroEditor(Text title, ConfigMacro macro, Screen parent) { } @Override - public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) { + public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { super.render(context, mouseX, mouseY, deltaTicks); if (errorCountDown > 0.0f) { - context.drawText(this.textRenderer, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + context.drawString(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); errorCountDown -= deltaTicks; } } @@ -83,9 +79,9 @@ protected void init() { GuiUtils.Layout nameWidgetLayout = layouts.get(4); GuiUtils.Layout buttonMutedLayout = layouts.get(5); - this.commandList = this.addDrawableChild(new CommandListWidget(this, this.client, this.width, this.height - 75, 0, 36, this.macro)); - this.addDrawableChild(ButtonWidget.builder(Text.of("Add command"), button -> this.commandList.addEntry()) - .dimensions(addCommandLayout.x(), addCommandLayout.y(), addCommandLayout.width(), addCommandLayout.height()) + this.commandList = this.addRenderableWidget(new CommandListWidget(this, this.minecraft, this.width, this.height - 75, 0, 36, this.macro)); + this.addRenderableWidget(Button.builder(Component.nullToEmpty("Add command"), button -> this.commandList.addEntry()) + .bounds(addCommandLayout.x(), addCommandLayout.y(), addCommandLayout.width(), addCommandLayout.height()) .build()); WidgetKeybindSettings widgetAdvancedKeybindSettings = new WidgetKeybindSettings(keybindSettingsLayout.x(), keybindSettingsLayout.y(), keybindSettingsLayout.width(), keybindSettingsLayout.height(), keybind, "", null, null); @@ -106,36 +102,36 @@ public void updateDisplayString() { } }; - this.addDrawableChild(new WidgetBaseWrapper(buttonMuted)); - this.addDrawableChild(new WidgetBaseWrapper(widgetAdvancedKeybindSettings)); - this.addDrawableChild(new WidgetBaseWrapper(buttonKeybind)); - this.addDrawableChild(new WidgetBaseWrapper(buttonEnabled)); - this.nameWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, nameWidgetLayout.width(), nameWidgetLayout.height(), Text.of(""))); - this.nameWidget.setText(macro.getMacroName()); + this.addRenderableWidget(new WidgetBaseWrapper(buttonMuted)); + this.addRenderableWidget(new WidgetBaseWrapper(widgetAdvancedKeybindSettings)); + this.addRenderableWidget(new WidgetBaseWrapper(buttonKeybind)); + this.addRenderableWidget(new WidgetBaseWrapper(buttonEnabled)); + this.nameWidget = addRenderableWidget(new EditBox(this.font, nameWidgetLayout.width(), nameWidgetLayout.height(), Component.nullToEmpty(""))); + this.nameWidget.setValue(macro.getMacroName()); this.nameWidget.setPosition(nameWidgetLayout.x(), nameWidgetLayout.y()); } //? if <=1.21.8 { - /*@Override + @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!this.buttonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { this.buttonKeybind.onClearSelection(); } return super.mouseClicked(mouseX, mouseY, button); } - *///? } else { - @Override - public boolean mouseClicked(Click click, boolean doubled) { + //? } else { + /*@Override + public boolean mouseClicked(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) { if (!this.buttonKeybind.isMouseOver((int) click.x(), (int) click.y())) { this.buttonKeybind.onClearSelection(); } return super.mouseClicked(click, doubled); } - //? } + *///? } @Override - public void close() { - if (MacroManager.nameExists(this.nameWidget.getText(), this.macro)) { + public void onClose() { + if (MacroManager.nameExists(this.nameWidget.getValue(), this.macro)) { errorCountDown = 50.0f; return; } @@ -143,7 +139,7 @@ public void close() { macro.setActions(this.commandList.children().stream().map(m -> m.command).toList()); macro.setEnabled(this.enabledConfigBoolean.getBooleanValue()); macro.setMuted(this.mutedConfigBoolean.getBooleanValue()); - macro.setMacroName(this.nameWidget.getText()); + macro.setMacroName(this.nameWidget.getValue()); macro.setKeybind(this.keybind.getStringValue()); macro.setSettings(this.keybind.getSettings()); @@ -154,6 +150,6 @@ public void close() { // if settings are changed while on the title screen, the settings are never saved // hmmm... this also happens with normal configs, not just macros // I'll just hope nobody notices - MinecraftClient.getInstance().send(() -> InternalMalilibApi.getMod(RedstoneTools.MOD_ID).configHandler.save()); + Minecraft.getInstance().schedule(() -> InternalMalilibApi.getMod(RedstoneTools.MOD_ID).configHandler.save()); } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java index 351f2c1e..1c536311 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java @@ -3,17 +3,20 @@ import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetBase; //? if >=1.21.11 -import fi.dy.masa.malilib.render.GuiContext; +//import fi.dy.masa.malilib.render.GuiContext; import net.minecraft.client.gui.*; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -//? if >1.21.8 { -import net.minecraft.client.input.CharInput; -import net.minecraft.client.input.KeyInput; -//? } - +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.narration.NarrationElementOutput; +//? if >=1.21.10 { +/*import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.input.MouseButtonEvent; +*///? } import java.util.Collection; -public class WidgetBaseWrapper implements Element, Drawable, Selectable { +public class WidgetBaseWrapper implements GuiEventListener, Renderable, NarratableEntry { private final WidgetBase wrapped; public WidgetBaseWrapper(WidgetBase wrapped) { @@ -21,7 +24,7 @@ public WidgetBaseWrapper(WidgetBase wrapped) { } //? if <=1.21.8 { - /*@Override + @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { if (configButtonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { @@ -42,7 +45,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { wrapped.onMouseReleased((int) mouseX, (int) mouseY, button); - return Element.super.mouseReleased(mouseX, mouseY, button); + return GuiEventListener.super.mouseReleased(mouseX, mouseY, button); } @Override @@ -54,9 +57,9 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { public boolean charTyped(char chr, int modifiers) { return wrapped.onCharTyped(chr, modifiers); } - *///? } else { - @Override - public boolean mouseClicked(Click click, boolean doubled) { + //? } else { + /*@Override + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { if (configButtonKeybind.isMouseOver((int) click.x(), (int) click.y())) { boolean selectedPre = configButtonKeybind.isSelected(); @@ -74,22 +77,22 @@ public boolean mouseClicked(Click click, boolean doubled) { } @Override - public boolean mouseReleased(Click click) { + public boolean mouseReleased(MouseButtonEvent click) { wrapped.onMouseReleased(click); - return Element.super.mouseReleased(click); + return GuiEventListener.super.mouseReleased(click); } @Override - public boolean charTyped(CharInput input) { + public boolean charTyped(CharacterEvent input) { return wrapped.onCharTyped(input); } @Override - public boolean keyPressed(KeyInput input) { - if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) configButtonKeybind.onKeyPressed(input.getKeycode()); + public boolean keyPressed(KeyEvent input) { + if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) configButtonKeybind.onKeyPressed(input.input()); return wrapped.onKeyTyped(input); } - //? } + *///? } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { @@ -121,29 +124,29 @@ public boolean isFocused() { } @Override - public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) { + public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { //? if <=1.21.5 { - /*wrapped.render(mouseX, mouseY, this.isFocused(), context); - *///? } else if <=1.21.10 { + wrapped.render(mouseX, mouseY, this.isFocused(), context); + //? } else if <=1.21.10 { /*wrapped.render(context, mouseX, mouseY, this.isFocused()); *///? } else { - wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); - //? } + /*wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); + *///? } } @Override - public SelectionType getType() { - if (this.isFocused()) return SelectionType.FOCUSED; - return SelectionType.NONE; + public NarrationPriority narrationPriority() { + if (this.isFocused()) return NarrationPriority.FOCUSED; + return NarrationPriority.NONE; } @Override - public Collection getNarratedParts() { - return Selectable.super.getNarratedParts(); + public Collection getNarratables() { + return NarratableEntry.super.getNarratables(); } @Override - public void appendNarrations(NarrationMessageBuilder builder) { + public void updateNarration(NarrationElementOutput builder) { } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index e1e32a78..62070e7d 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -3,25 +3,26 @@ import fi.dy.masa.malilib.gui.button.ButtonBase; import fi.dy.masa.malilib.gui.button.ButtonGeneric; //? if >=1.21.11 { -import fi.dy.masa.malilib.render.GuiContext; -//?} -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.ScreenRect; -import net.minecraft.client.gui.navigation.GuiNavigation; -import net.minecraft.client.gui.navigation.GuiNavigationPath; -import net.minecraft.client.gui.navigation.NavigationAxis; -import net.minecraft.client.gui.navigation.NavigationDirection; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.EntryListWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; -/*$ click_and_inputs_imports {*/// -import net.minecraft.client.gui.Click; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.input.CharInput;/*$}*/ -import net.minecraft.client.util.math.Rect2i; -import net.minecraft.text.Text; +/*import fi.dy.masa.malilib.render.GuiContext; +import net.minecraft.client.gui.navigation.ScreenRectangle; +*///? } +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractSelectionList; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; +import net.minecraft.client.gui.navigation.ScreenAxis; +import net.minecraft.client.gui.navigation.ScreenDirection; +//? if >=1.21.10 { +/*import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.input.MouseButtonEvent; +*///? } +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import tools.redstone.redstonetools.config.option.ConfigMacro; import tools.redstone.redstonetools.macros.actions.CommandAction; @@ -29,17 +30,17 @@ import tools.redstone.redstonetools.mixin.features.ChatInputSuggestorAccessor; import tools.redstone.redstonetools.mixin.features.SuggestionWindowAccessor; //? if >=1.21.10 { -import tools.redstone.redstonetools.mixin.features.TextFieldWidgetAccessor; -//?} +/*import tools.redstone.redstonetools.mixin.features.TextFieldWidgetAccessor; +*///?} -public class CommandListWidget extends EntryListWidget { +public class CommandListWidget extends AbstractSelectionList { private final GuiMacroEditor parent; @Nullable - private ChatInputSuggestor commandSuggester; + private CommandSuggestions commandSuggester; private final ConfigMacro macro; - public CommandListWidget(GuiMacroEditor parent, MinecraftClient mc, int width, int height, int y, int itemHeight, ConfigMacro macro) { + public CommandListWidget(GuiMacroEditor parent, Minecraft mc, int width, int height, int y, int itemHeight, ConfigMacro macro) { super(mc, width, height, y, itemHeight); this.parent = parent; this.macro = macro; @@ -54,8 +55,8 @@ public CommandListWidget(GuiMacroEditor parent, MinecraftClient mc, int width, i @Override public void setSelected(@Nullable CommandListWidget.CommandEntry entry) { - if (this.getSelectedOrNull() != null) { - this.getSelectedOrNull().commandWidget.setSuggestion(null); + if (this.getSelected() != null) { + this.getSelected().commandWidget.setSuggestion(null); } super.setSelected(entry); if (entry == null) { @@ -63,12 +64,12 @@ public void setSelected(@Nullable CommandListWidget.CommandEntry entry) { return; } //? if >=1.21.10 - ((TextFieldWidgetAccessor) entry.commandWidget).getFormatters().clear(); - this.commandSuggester = new ChatInputSuggestor( - client, + //((TextFieldWidgetAccessor) entry.commandWidget).getFormatters().clear(); + this.commandSuggester = new CommandSuggestions( + minecraft, this.parent, entry.commandWidget, - client.textRenderer, + minecraft.font, false, false, 0, @@ -77,71 +78,71 @@ public void setSelected(@Nullable CommandListWidget.CommandEntry entry) { 0xD0000000 ) { @Override - public void refresh() { - if (client == null) return; - if (client.getNetworkHandler() == null) return; - super.refresh(); + public void updateCommandInfo() { + if (minecraft == null) return; + if (minecraft.getConnection() == null) return; + super.updateCommandInfo(); } @Override - public void renderMessages(DrawContext context) { + public void renderUsage(GuiGraphics context) { //? if >=1.21.8 { - context.getMatrices().pushMatrix(); - //?} else - //context.getMatrices().push(); + /*context.pose().pushMatrix(); + *///?} else + context.pose().pushPose(); var x = 0; var y = entry.commandWidget.getY() + 20 - 72; - context.getMatrices().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); - super.renderMessages(context); + context.pose().translate(x, y/*? if <1.21.8 {*/, 0/*?}*/); + super.renderUsage(context); //? if >=1.21.8 { - context.getMatrices().popMatrix(); - //?} else - //context.getMatrices().pop(); + /*context.pose().popMatrix(); + *///?} else + context.pose().popPose(); } }; - this.commandSuggester.setWindowActive(true); - this.commandSuggester.refresh(); + this.commandSuggester.setAllowSuggestions(true); + this.commandSuggester.updateCommandInfo(); } @Override - public void setScrollY(double scrollY) { - super.setScrollY(scrollY); + public void setScrollAmount(double scrollY) { + super.setScrollAmount(scrollY); recalculateAllActionsPositions(); - if (this.commandSuggester != null && this.getSelectedOrNull() != null) { - ChatInputSuggestor.SuggestionWindow window = ((ChatInputSuggestorAccessor) this.commandSuggester).getWindow(); + if (this.commandSuggester != null && this.getSelected() != null) { + CommandSuggestions.SuggestionsList window = ((ChatInputSuggestorAccessor) this.commandSuggester).getSuggestions(); if (window == null) return; - Rect2i area = ((SuggestionWindowAccessor) window).getArea(); - area.setY(this.getSelectedOrNull().commandWidget.getY() + 23); + Rect2i area = ((SuggestionWindowAccessor) window).getRect(); + area.setY(this.getSelected().commandWidget.getY() + 23); } } @Override - public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { - if (this.getEntryCount() == 0) { + public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) { + if (this.getItemCount() == 0) { return null; } if (!this.isFocused()) { - return GuiNavigationPath.of(this); + return ComponentPath.leaf(this); } - if (!(navigation instanceof GuiNavigation.Arrow(NavigationDirection navigationDirection))) { - return super.getNavigationPath(navigation); + if (!(navigation instanceof FocusNavigationEvent.ArrowNavigation(ScreenDirection navigationDirection))) { + return super.nextFocusPath(navigation); } - if (navigationDirection.getAxis() == NavigationAxis.HORIZONTAL) { - return GuiNavigationPath.of(this.getSelectedOrNull(), this); + if (navigationDirection.getAxis() == ScreenAxis.HORIZONTAL) { + return ComponentPath.path(this.getSelected(), this); } - CommandEntry neighboringEntry = this.getNeighboringEntry(navigationDirection); + CommandEntry neighboringEntry = this.nextEntry(navigationDirection); if (neighboringEntry == null) { - return GuiNavigationPath.of(this.getSelectedOrNull(), this); + return ComponentPath.path(this.getSelected(), this); } - return GuiNavigationPath.of(neighboringEntry, this); + return ComponentPath.path(neighboringEntry, this); } @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (this.commandSuggester != null && this.commandSuggester.mouseClicked(/*? if <1.21.10 {*//*mouseX, mouseY, button*//*?} else {*/click/*?}*/)) return true; - return super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); + public boolean mouseClicked(/*$ mouse_clicked_params {*/double mouseX, double mouseY, int button/*$}*/) { + if (this.commandSuggester != null && this.commandSuggester.mouseClicked(/*? if <1.21.10 {*/mouseX, mouseY, button/*?} else {*//*click*//*?}*/)) return true; + return super.mouseClicked(/*$ mouse_clicked_args {*/mouseX, mouseY, button/*$}*/); } @Override @@ -151,14 +152,14 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou } @Override - public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - if (this.commandSuggester != null && this.commandSuggester.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; - return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); + public boolean keyPressed(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { + if (this.commandSuggester != null && this.commandSuggester.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; + return super.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/); } @Override - protected void renderList(DrawContext context, int mouseX, int mouseY, float deltaTicks) { - super.renderList(context, mouseX, mouseY, deltaTicks); + protected void renderListItems(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { + super.renderListItems(context, mouseX, mouseY, deltaTicks); if (this.commandSuggester != null) { this.commandSuggester.render(context, mouseX, mouseY); } @@ -166,14 +167,13 @@ protected void renderList(DrawContext context, int mouseX, int mouseY, float del @Override //? if >=1.21.10 { - protected boolean isEntrySelectionAllowed() { - //?} else { - /*protected boolean isSelectedEntry(int index) { - *///?} + /*protected boolean entriesCanBeSelected() { + *///?} else { + protected boolean isSelectedItem(int index) { + //?} return false; } - @Override public int getRowWidth() { return this.width - 50; @@ -183,51 +183,57 @@ public void addEntry() { this.macro.getActions().addFirst(new CommandAction("")); CommandEntry entry = new CommandEntry(this.macro.getActions().getFirst()); this.addEntryToTop(entry); - this.centerScrollOn(this.getFirst()); + //? if <=1.21.8 { + this.centerScrollOn(this.getFirstElement()); + //? } else + //this.centerScrollOn(this.getFirst()); recalculateAllActionsPositions(); if (this.commandSuggester != null) { - this.commandSuggester.refresh(); + this.commandSuggester.updateCommandInfo(); } } private void recalculateAllActionsPositions() { - int i = this.getY() - (int) this.getScrollY(); + int i = this.getY() - (int) this.scrollAmount(); for (CommandEntry entry : this.children()) { entry.removeButton.setY(i + 6); entry.commandWidget.setY(i + 3); + //? if <=1.21.8 { i += this.itemHeight; + //? } else + //i += this.defaultEntryHeight; } } //? if >=1.21.10 { - private CommandEntry getFirst() { + /*private CommandEntry getFirst() { return this.children().getFirst(); } - //?} + *///?} @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) { + protected void updateWidgetNarration(NarrationElementOutput builder) { } public class CommandEntry extends Entry { public final CommandAction command; - private TextFieldWidget commandWidget; + private EditBox commandWidget; private ButtonBase removeButton; public CommandEntry(CommandAction command) { this.command = command; - this.commandWidget = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, CommandListWidget.this.getX() + 4 + 25, 0, CommandListWidget.this.getRowWidth() - 100, 26, Text.of("")); + this.commandWidget = new EditBox(Minecraft.getInstance().font, CommandListWidget.this.getX() + 4 + 25, 0, CommandListWidget.this.getRowWidth() - 100, 26, Component.nullToEmpty("")); commandWidget.setMaxLength(256); - commandWidget.setText(command.command); - commandWidget.setChangedListener(this::onCommandChanged); + commandWidget.setValue(command.command); + commandWidget.setResponder(this::onCommandChanged); this.removeButton = new ButtonGeneric(0, 0, -1, 20, "Remove"); this.removeButton.setX(CommandListWidget.this.getX() + CommandListWidget.this.getRowWidth() - this.removeButton.getWidth() - 10 + 25); this.removeButton.setActionListener((button, mouseButton) -> { CommandListWidget.this.macro.getActions().remove(CommandListWidget.this.children().indexOf(this)); - CommandListWidget.this.removeEntryWithoutScrolling(this); + CommandListWidget.this.removeEntryFromTop(this); recalculateAllActionsPositions(); }); } @@ -235,26 +241,26 @@ public CommandEntry(CommandAction command) { private void onCommandChanged(String text) { command.command = text; if (CommandListWidget.this.commandSuggester != null) { - CommandListWidget.this.commandSuggester.refresh(); + CommandListWidget.this.commandSuggester.updateCommandInfo(); } } @Override - public void render(DrawContext context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { + public void /*? if <=1.21.8 {*/render/*? } else {*//*renderContent*//*? }*/(GuiGraphics context, /*? if <1.21.10 {*/ int index, int argY, int argX, int entryWidth, int entryHeight, /*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { commandWidget.render(context, mouseX, mouseY, tickProgress); //? if <=1.21.5 { - /*removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); - *///?} else if <=1.21.10 { + removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); + //?} else if <=1.21.10 { /*removeButton.render(context, mouseX, mouseY, removeButton.isMouseOver()); *///?} else { - GuiContext guiContext = GuiContext.fromGuiGraphics(context); - ScreenRect last = context.scissorStack.peekLast(); + /*GuiContext guiContext = GuiContext.fromGuiGraphics(context); + ScreenRectangle last = context.scissorStack.peek(); if (last != null) { guiContext.pushScissor(last); } removeButton.render(guiContext, mouseX, mouseY, removeButton.isMouseOver()); - //?} + *///?} } @Override @@ -270,48 +276,48 @@ public void mouseMoved(double mouseX, double mouseY) { } @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (commandWidget.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; - if (removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; + public boolean mouseClicked(/*$ mouse_clicked_params {*/double mouseX, double mouseY, int button/*$}*/) { + if (commandWidget.mouseClicked(/*$ mouse_clicked_args {*/mouseX, mouseY, button/*$}*/)) return true; + if (removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/(int) mouseX, (int) mouseY, button/*$}*/)) return true; return false; } @Override - public boolean mouseReleased(/*$ dragged_released_params {*/Click click/*$}*/) { - removeButton.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - return commandWidget.mouseReleased(/*$ dragged_released_args {*/click/*$}*/); + public boolean mouseReleased(/*$ dragged_released_params {*/double mouseX, double mouseY, int button/*$}*/) { + removeButton.onMouseReleased(/*$ on_released_args {*/(int) mouseX, (int) mouseY, button/*$}*/); + return commandWidget.mouseReleased(/*$ dragged_released_args {*/mouseX, mouseY, button/*$}*/); } @Override - public boolean mouseDragged(/*$ dragged_released_params {*/Click click/*$}*/, double deltaX, double deltaY) { - return commandWidget.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); + public boolean mouseDragged(/*$ dragged_released_params {*/double mouseX, double mouseY, int button/*$}*/, double deltaX, double deltaY) { + return commandWidget.mouseDragged(/*$ dragged_released_args {*/mouseX, mouseY, button/*$}*/, deltaX, deltaY); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { if (commandWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true; - var x = /*? if <1.21.10 {*//*(int)*//*?}*/mouseX; - var y = /*? if <1.21.10 {*//*(int)*//*?}*/mouseY; + var x = /*? if <1.21.10 {*/(int)/*?}*/mouseX; + var y = /*? if <1.21.10 {*/(int)/*?}*/mouseY; if (removeButton.onMouseScrolled(x, y, horizontalAmount, verticalAmount)) return true; return false; } @Override - public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - if (commandWidget.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; - if (removeButton.onKeyTyped(/*$ keyinput_args {*/input/*$}*/)) return true; + public boolean keyPressed(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { + if (commandWidget.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; + if (removeButton.onKeyTyped(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; return false; } @Override - public boolean keyReleased(/*$ keyinput_params {*/KeyInput input/*$}*/) { - return commandWidget.keyReleased(/*$ keyinput_args {*/input/*$}*/); + public boolean keyReleased(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { + return commandWidget.keyReleased(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/); } @Override - public boolean charTyped(/*$ charinput_params {*/CharInput input/*$}*/) { - if (commandWidget.charTyped(/*$ charinput_args {*/input/*$}*/)) return true; - if (removeButton.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; + public boolean charTyped(/*$ charinput_params {*/char chr, int modifiers/*$}*/) { + if (commandWidget.charTyped(/*$ charinput_args {*/chr, modifiers/*$}*/)) return true; + if (removeButton.onCharTyped(/*$ charinput_args {*/chr, modifiers/*$}*/)) return true; return false; } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java index ab8605b0..97f97f7d 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java @@ -1,13 +1,13 @@ package tools.redstone.redstonetools.mixin.blocks; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneWireBlock; -import net.minecraft.block.ShapeContext; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RedStoneWireBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import org.lwjgl.util.tinyfd.TinyFileDialogs; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -17,14 +17,14 @@ import tools.redstone.redstonetools.config.General; import tools.redstone.redstonetools.features.toggleable.BigDustFeature; -@Mixin(RedstoneWireBlock.class) +@Mixin(RedStoneWireBlock.class) public class RedstoneHitboxMixin { // use array for better performance @Unique private static final VoxelShape[] SHAPES = new VoxelShape[17]; - @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) - public void getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + @Inject(method = "getShape", at = @At("HEAD"), cancellable = true) + public void getOutlineShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context, CallbackInfoReturnable cir) { if (!FabricLoader.getInstance().isModLoaded("malilib")) { TinyFileDialogs.tinyfd_messageBox( "Error", @@ -41,9 +41,9 @@ public void getOutlineShape(BlockState state, BlockView world, BlockPos pos, Sha } static { - SHAPES[0] = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 0.01, 16.0); + SHAPES[0] = Block.box(0.0, 0.0, 0.0, 16.0, 0.01, 16.0); for (int i = 1; i <= 16; i++) { - SHAPES[i] = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, i, 16.0); + SHAPES[i] = Block.box(0.0, 0.0, 0.0, 16.0, i, 16.0); } } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/AirPlaceClientMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/AirPlaceClientMixin.java index abf7b58b..cb4eb861 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/AirPlaceClientMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/AirPlaceClientMixin.java @@ -1,9 +1,9 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.util.hit.HitResult; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.phys.HitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -13,21 +13,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature; -@Mixin(MinecraftClient.class) +@Mixin(Minecraft.class) public class AirPlaceClientMixin { @Shadow - public HitResult crosshairTarget; + public HitResult hitResult; - @Inject(method = "doItemUse", at = @At(value = "HEAD")) + @Inject(method = "startUseItem", at = @At(value = "HEAD")) public void doItemUse(CallbackInfo callbackInfo) { if (!isAirPlaceAllowed()) { return; } - crosshairTarget = AirPlaceFeature.findAirPlaceBlockHit(getPlayer()); + hitResult = AirPlaceFeature.findAirPlaceBlockHit(getPlayer()); } - @Inject(method = "doAttack", at = @At(value = "HEAD")) + @Inject(method = "startAttack", at = @At(value = "HEAD")) public void doAttack(CallbackInfoReturnable cir) { if (!isAirPlaceAllowed()) { return; @@ -35,7 +35,7 @@ public void doAttack(CallbackInfoReturnable cir) { // Call interactionManager directly because the block is air, with which the player cannot interact var hit = AirPlaceFeature.findAirPlaceBlockHit(getPlayer()); - getInteractionManager().attackBlock(hit.getBlockPos(), hit.getSide()); + getInteractionManager().startDestroyBlock(hit.getBlockPos(), hit.getDirection()); } @Unique @@ -46,12 +46,12 @@ private boolean isAirPlaceAllowed() { } // If the hit result is already set - if (crosshairTarget != null && crosshairTarget.getType() != HitResult.Type.MISS) { + if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { return false; } // If blockpos isn't air - if (getMinecraftClient().world != null && !getMinecraftClient().world.getBlockState(AirPlaceFeature.findAirPlaceBlockHit(getPlayer()).getBlockPos()).isAir()) { + if (getMinecraftClient().level != null && !getMinecraftClient().level.getBlockState(AirPlaceFeature.findAirPlaceBlockHit(getPlayer()).getBlockPos()).isAir()) { return false; } @@ -66,18 +66,18 @@ private boolean isAirPlaceAllowed() { } @Unique - private MinecraftClient getMinecraftClient() { - return (MinecraftClient) (Object) this; + private Minecraft getMinecraftClient() { + return (Minecraft) (Object) this; } @Unique - private ClientPlayerEntity getPlayer() { + private LocalPlayer getPlayer() { return getMinecraftClient().player; } @Unique - private ClientPlayerInteractionManager getInteractionManager() { - return getMinecraftClient().interactionManager; + private MultiPlayerGameMode getInteractionManager() { + return getMinecraftClient().gameMode; } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java index 37c42ec8..a8a39031 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java @@ -2,10 +2,10 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.util.BlockRotation; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,15 +14,15 @@ @Mixin(BlockItem.class) public abstract class AutoRotateClientMixin { @Shadow - protected abstract boolean canPlace(ItemPlacementContext context, BlockState state); + protected abstract boolean canPlace(BlockPlaceContext context, BlockState state); @ModifyReturnValue(method = "getPlacementState", at = @At("RETURN")) - private BlockState changeRotation(BlockState original, @Local(argsOnly = true) ItemPlacementContext context) { + private BlockState changeRotation(BlockState original, @Local(argsOnly = true) BlockPlaceContext context) { if (!AutoRotateClient.isEnabled.getBooleanValue() || original == null) return original; BlockState backup = original; - original = original.rotate(BlockRotation.CLOCKWISE_180); + original = original.rotate(Rotation.CLOCKWISE_180); if (this.canPlace(context, original)) return original; diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java index b97f389c..986e0353 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java @@ -1,17 +1,17 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import tools.redstone.redstonetools.config.MacroManager; -@Mixin(ChatHud.class) +@Mixin(ChatComponent.class) public class ChatHudMixin { - @Inject(method = "addMessage(Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true) - private void injected(Text message, CallbackInfo ci) { + @Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), cancellable = true) + private void injected(Component message, CallbackInfo ci) { if (MacroManager.shouldMute) ci.cancel(); } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java index 1781166e..2dc9a719 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java @@ -1,16 +1,16 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.gui.components.EditBox; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(ChatInputSuggestor.class) +@Mixin(CommandSuggestions.class) public interface ChatInputSuggestorAccessor { @Accessor - TextFieldWidget getTextField(); + EditBox getInput(); @Accessor - @Nullable ChatInputSuggestor.SuggestionWindow getWindow(); + @Nullable CommandSuggestions.SuggestionsList getSuggestions(); } \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java index f1a2e97f..6f6eb5e3 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java @@ -2,9 +2,9 @@ import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,34 +14,34 @@ import tools.redstone.redstonetools.malilib.GuiMacroEditor; import tools.redstone.redstonetools.utils.StringUtils; -@Mixin(ChatInputSuggestor.class) +@Mixin(CommandSuggestions.class) public class ChatInputSuggestorMixin { @Final @Shadow - TextFieldWidget textField; + EditBox input; @Shadow @Final - private Screen owner; + private Screen screen; - @WrapMethod(method = "refresh") + @WrapMethod(method = "updateCommandInfo") private void makeMethodSeeReplacedVariables(Operation original) { - boolean shouldReturn = !ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(textField.getText()).length() < textField.getText().length(); + boolean shouldReturn = !ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(input.getValue()).length() < input.getValue().length(); if (shouldReturn) return; - String originalCommand = textField.getText(); - ((TextFieldWidgetAccessor) textField).setTextDirectly(StringUtils.insertVariablesAndMath(textField.getText())); + String originalCommand = input.getValue(); + ((TextFieldWidgetAccessor) input).setTextDirectly(StringUtils.insertVariablesAndMath(input.getValue())); original.call(); - ((TextFieldWidgetAccessor) textField).setTextDirectly(originalCommand); + ((TextFieldWidgetAccessor) input).setTextDirectly(originalCommand); } @ModifyArg( - method = "show", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatInputSuggestor$SuggestionWindow;(Lnet/minecraft/client/gui/screen/ChatInputSuggestor;IIILjava/util/List;Z)V"), + method = "showSuggestions", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/CommandSuggestions$SuggestionsList;(Lnet/minecraft/client/gui/components/CommandSuggestions;IIILjava/util/List;Z)V"), index = 2 ) private int modifyY(int y) { - if (this.owner instanceof GuiMacroEditor) { - return textField.getY() + 20; + if (this.screen instanceof GuiMacroEditor) { + return input.getY() + 20; } return y; } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ClientPlayNetworkHandlerMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ClientPlayNetworkHandlerMixin.java index b59efd5f..caba1eda 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ClientPlayNetworkHandlerMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ClientPlayNetworkHandlerMixin.java @@ -2,13 +2,13 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.impl.command.client.ClientCommandInternals; -import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.CommandSource; -import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.resource.featuretoggle.FeatureSet; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.protocol.game.ClientboundCommandsPacket; +import net.minecraft.world.flag.FeatureFlagSet; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -20,30 +20,30 @@ import tools.redstone.redstonetools.utils.DependencyLookup; import tools.redstone.redstonetools.utils.StringUtils; -@Mixin(ClientPlayNetworkHandler.class) +@Mixin(ClientPacketListener.class) public class ClientPlayNetworkHandlerMixin { - @Inject(method = "onCommandTree", at = @At("RETURN"), order = 750) - private void onOnCommandTree(CommandTreeS2CPacket packet, CallbackInfo info) { - var parse = commandDispatcher.parse("base 0x2 5", commandSource); // there's probably a better way to check for rst being on the server, but I cba rn + @Inject(method = "handleCommands", at = @At("RETURN"), order = 750) + private void onOnCommandTree(ClientboundCommandsPacket packet, CallbackInfo info) { + var parse = commands.parse("base 0x2 5", suggestionsProvider); // there's probably a better way to check for rst being on the server, but I cba rn DependencyLookup.REDSTONE_TOOLS_SERVER_PRESENT = !parse.getReader().canRead(); - ClientCommands.registerCommands(ClientCommandInternals.getActiveDispatcher(), CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures)); + ClientCommands.registerCommands(ClientCommandInternals.getActiveDispatcher(), CommandBuildContext.simple(this.registryAccess, this.enabledFeatures)); } @Shadow - private CommandDispatcher commandDispatcher; + private CommandDispatcher commands; @Shadow @Final - private ClientCommandSource commandSource; + private ClientSuggestionProvider suggestionsProvider; @Final @Shadow - private FeatureSet enabledFeatures; + private FeatureFlagSet enabledFeatures; @Final @Shadow - private DynamicRegistryManager.Immutable combinedDynamicRegistries; + private RegistryAccess.Frozen registryAccess; - @ModifyVariable(method = "sendChatCommand", at = @At("HEAD"), argsOnly = true, order = 750) + @ModifyVariable(method = "sendCommand", at = @At("HEAD"), argsOnly = true, order = 750) public String sendChatCommand(String command) { return StringUtils.insertVariablesAndMath(command); } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java index a490fc86..33b882d3 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java @@ -1,6 +1,5 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.command.CommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -10,12 +9,13 @@ import java.util.ArrayList; import java.util.List; +import net.minecraft.commands.SharedSuggestionProvider; -import static net.minecraft.command.CommandSource.SUGGESTION_MATCH_PREFIX; +import static net.minecraft.commands.SharedSuggestionProvider.MATCH_SPLITTER; -@Mixin(CommandSource.class) +@Mixin(SharedSuggestionProvider.class) public interface CommandSourceMixin { - @Inject(method = "shouldSuggest", at = @At("HEAD"), cancellable = true) + @Inject(method = "matchesSubStr", at = @At("HEAD"), cancellable = true) private static void meow(String remaining, String candidate, CallbackInfoReturnable cir) { if (!General.BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS.getBooleanValue()) return; if (candidate == null) { @@ -31,7 +31,7 @@ private static void meow(String remaining, String candidate, CallbackInfoReturna List starts = new ArrayList<>(); starts.add(0); for (int i = 0; i < n; i++) { - if (SUGGESTION_MATCH_PREFIX.matches(candidate.charAt(i))) { + if (MATCH_SPLITTER.matches(candidate.charAt(i))) { starts.add(i + 1); } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ItemBindItemStackMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ItemBindItemStackMixin.java index b549f83c..c810a261 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ItemBindItemStackMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ItemBindItemStackMixin.java @@ -1,11 +1,11 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; +import net.minecraft.client.Minecraft; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,15 +16,15 @@ public abstract class ItemBindItemStackMixin { @Inject(method = "use", at = @At("HEAD"), cancellable = true) - private void checkCommandNBT(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable cir) { - assert MinecraftClient.getInstance().player != null; - ItemStack stack = user.getMainHandStack(); - if (stack.isEmpty()) stack = user.getOffHandStack(); - if (!world.isClient()) return; + private void checkCommandNBT(Level world, Player user, InteractionHand hand, CallbackInfoReturnable cir) { + assert Minecraft.getInstance().player != null; + ItemStack stack = user.getMainHandItem(); + if (stack.isEmpty()) stack = user.getOffhandItem(); + if (!world.isClientSide()) return; if (ItemUtils.containsCommand(stack)) { String command = ItemUtils.getCommand(stack); - MinecraftClient.getInstance().player.networkHandler.sendChatCommand(command); - cir.setReturnValue(ActionResult.PASS); + Minecraft.getInstance().player.connection.sendCommand(command); + cir.setReturnValue(InteractionResult.PASS); } } } \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java index cc23100d..678deb41 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java @@ -1,12 +1,12 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.util.math.Rect2i; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.renderer.Rect2i; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(ChatInputSuggestor.SuggestionWindow.class) +@Mixin(CommandSuggestions.SuggestionsList.class) public interface SuggestionWindowAccessor { @Accessor - Rect2i getArea(); + Rect2i getRect(); } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java index 48c27ab6..40a2a2a7 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java @@ -2,25 +2,25 @@ import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.gui.components.EditBox; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import tools.redstone.redstonetools.utils.StringUtils; -@Mixin(ChatInputSuggestor.SuggestionWindow.class) +@Mixin(CommandSuggestions.SuggestionsList.class) public class SuggestionWindowMixin { @Shadow @Final - ChatInputSuggestor field_21615; + CommandSuggestions field_21615; - @WrapMethod(method = "complete") + @WrapMethod(method = "useSuggestion") private void expandVariablesToo(Operation original) { - TextFieldWidget textField = ((ChatInputSuggestorAccessor) this.field_21615).getTextField(); - String beforeComplete = textField.getText(); + EditBox textField = ((ChatInputSuggestorAccessor) this.field_21615).getInput(); + String beforeComplete = textField.getValue(); original.call(); - if (StringUtils.expand(beforeComplete, textField.getText()).equals(textField.getText())) return; - textField.setText(StringUtils.expand(beforeComplete, textField.getText())); + if (StringUtils.expand(beforeComplete, textField.getValue()).equals(textField.getValue())) return; + textField.setValue(StringUtils.expand(beforeComplete, textField.getValue())); } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java index 86ab4098..6f6a4744 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java @@ -1,18 +1,18 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.client.gui.widget.TextFieldWidget; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; +import net.minecraft.client.gui.components.EditBox; -@Mixin(TextFieldWidget.class) +@Mixin(EditBox.class) public interface TextFieldWidgetAccessor { - @Accessor("text") + @Accessor("value") void setTextDirectly(String s); //? if >=1.21.10 { - @Accessor - List getFormatters(); - //?} + /*@Accessor + List getFormatters(); + *///?} } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java index e4f55bc0..440b9ba0 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java @@ -1,26 +1,24 @@ package tools.redstone.redstonetools.mixin.features; -//? if <1.21.10 { -/*import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -*///?} else { -import net.minecraft.client.render.state.OutlineRenderState; -//?} -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.LevelRenderer; +//? if >=1.21.10 +//import net.minecraft.client.renderer.state.BlockOutlineRenderState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(WorldRenderer.class) +@Mixin(LevelRenderer.class) public interface WorldRendererInvoker { @Invoker //? if <=1.21.8 { - /*void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); - *///?} else if <=1.21.10 { - /*void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, OutlineRenderState state, int color); + void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); + //?} else if <=1.21.10 { + /*void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, BlockOutlineRenderState state, int color); *///?} else { - void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, OutlineRenderState state, int color, float lineWidth); - //?} + /*void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, BlockOutlineRenderState state, int color, float lineWidth); + *///?} } \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java index ba11bacf..bb4fa082 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java @@ -2,13 +2,12 @@ import kr1v.malilibApi.InternalMalilibApi; import kr1v.malilibApi.MalilibApi; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.option.ControlsOptionsScreen; -import net.minecraft.client.gui.screen.option.GameOptionsScreen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.option.GameOptions; -import net.minecraft.text.Text; +import net.minecraft.client.Options; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.options.OptionsSubScreen; +import net.minecraft.client.gui.screens.options.controls.ControlsScreen; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,15 +15,15 @@ import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.Macros; -@Mixin(ControlsOptionsScreen.class) -public abstract class AddMacroButtonMixin extends GameOptionsScreen { - public AddMacroButtonMixin(Screen parent, GameOptions gameOptions, Text title) { +@Mixin(ControlsScreen.class) +public abstract class AddMacroButtonMixin extends OptionsSubScreen { + public AddMacroButtonMixin(Screen parent, Options gameOptions, Component title) { super(parent, gameOptions, title); } @Inject(method = "addOptions", at = @At("TAIL")) public void addMacroButton(CallbackInfo ci) { - this.body.addWidgetEntry(new ButtonWidget.Builder(Text.of("Macros..."), button -> { + this.list.addSmall(new Button.Builder(Component.nullToEmpty("Macros..."), button -> { InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(Macros.getTab()); MalilibApi.openScreenFor(RedstoneTools.MOD_ID); }).build(), null); diff --git a/src/main/java/tools/redstone/redstonetools/Commands.java b/src/main/java/tools/redstone/redstonetools/Commands.java index ad716163..90f3ba05 100644 --- a/src/main/java/tools/redstone/redstonetools/Commands.java +++ b/src/main/java/tools/redstone/redstonetools/Commands.java @@ -1,12 +1,11 @@ package tools.redstone.redstonetools; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.commands.CommandSourceStack; //? if >=1.21.11 { -import net.minecraft.command.DefaultPermissions; -import net.minecraft.command.permission.PermissionCheck; -import net.minecraft.server.command.CommandManager; -//?} -import net.minecraft.server.command.ServerCommandSource; +/*import net.minecraft.server.permissions.PermissionCheck; +import net.minecraft.server.permissions.Permissions; +*///? } import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.*; import tools.redstone.redstonetools.utils.DependencyLookup; @@ -14,12 +13,12 @@ import java.util.function.Predicate; public class Commands { - public static final Predicate PERMISSION_LEVEL_2 = + public static final Predicate PERMISSION_LEVEL_2 = //? if <=1.21.10 { - /*source -> source.hasPermissionLevel(2); - *///?} else { - CommandManager.requirePermissionLevel(new PermissionCheck.Require(DefaultPermissions.GAMEMASTERS)); - //?} + source -> source.hasPermission(2); + //?} else { + /*net.minecraft.commands.Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); + *///?} public static void registerCommands() { CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> { diff --git a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java index 6ebe460c..aaa1ce2f 100644 --- a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java +++ b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java @@ -1,15 +1,15 @@ package tools.redstone.redstonetools; //? if <=1.21.10 { -/*import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; -import net.minecraft.world.GameRules; +import net.minecraft.world.level.GameRules; public class RedstoneToolsGameRules { private RedstoneToolsGameRules() { } - public static GameRules.Key DO_CONTAINER_DROPS; + public static GameRules.Key DO_CONTAINER_DROPS; // public static GameRules.Key DO_BLOCK_UPDATES_AFTER_EDIT; public static void register() { @@ -20,15 +20,18 @@ public static void register() { // } } } -*///?} else { -import com.mojang.brigadier.arguments.ArgumentType; +//?} else { +/*import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.serialization.Codec; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.resource.featuretoggle.FeatureSet; -import net.minecraft.util.Identifier; -import net.minecraft.world.rule.*; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.flag.FeatureFlagSet; +import net.minecraft.world.level.gamerules.GameRule; +import net.minecraft.world.level.gamerules.GameRuleCategory; +import net.minecraft.world.level.gamerules.GameRuleType; +import net.minecraft.world.level.gamerules.GameRuleTypeVisitor; import java.util.function.ToIntFunction; @@ -55,8 +58,8 @@ private static GameRule registerBooleanRule(String name, GameRuleCatego BoolArgumentType.bool(), Codec.BOOL, defaultValue, - FeatureSet.empty(), - GameRuleVisitor::visitBoolean, + FeatureFlagSet.of(), + GameRuleTypeVisitor::visitBoolean, value -> value ? 1 : 0 ); } @@ -68,13 +71,13 @@ private static GameRule registerRule( ArgumentType argumentType, Codec codec, T defaultValue, - FeatureSet requiredFeatures, - net.minecraft.world.rule.GameRules.Acceptor acceptor, + FeatureFlagSet requiredFeatures, + net.minecraft.world.level.gamerules.GameRules.VisitorCaller acceptor, ToIntFunction commandResultSupplier ) { return Registry.register( - Registries.GAME_RULE, Identifier.of(RedstoneTools.MOD_ID, name), new GameRule<>(category, type, argumentType, acceptor, codec, commandResultSupplier, defaultValue, requiredFeatures) + BuiltInRegistries.GAME_RULE, Identifier.fromNamespaceAndPath(RedstoneTools.MOD_ID, name), new GameRule<>(category, type, argumentType, acceptor, codec, commandResultSupplier, defaultValue, requiredFeatures) ); } } -//?} +*///?} diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/BaseConvertFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/BaseConvertFeature.java index 8168dc97..c708b552 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/BaseConvertFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/BaseConvertFeature.java @@ -5,14 +5,13 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; - import java.math.BigInteger; import java.util.Locale; import java.util.function.Consumer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; public class BaseConvertFeature { @@ -21,16 +20,16 @@ public class BaseConvertFeature { protected BaseConvertFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("base") - .then(CommandManager.argument("inputNum", StringArgumentType.word()) - .then(CommandManager.argument("toBase", IntegerArgumentType.integer(2, 16)) + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) { + dispatcher.register(Commands.literal("base") + .then(Commands.argument("inputNum", StringArgumentType.word()) + .then(Commands.argument("toBase", IntegerArgumentType.integer(2, 16)) .executes(context -> BaseConvertFeature.INSTANCE.execute( StringArgumentType.getString(context, "inputNum"), IntegerArgumentType.getInteger(context, "toBase"), (t) -> { try { - context.getSource().getPlayerOrThrow().sendMessage(t); + context.getSource().getPlayerOrException().sendSystemMessage(t); } catch (CommandSyntaxException ignored) { } } @@ -38,9 +37,9 @@ public void registerCommand(CommandDispatcher dispatcher, C } private static final SimpleCommandExceptionType INVALID_NUMBER = - new SimpleCommandExceptionType(Text.literal("Invalid number")); + new SimpleCommandExceptionType(Component.literal("Invalid number")); - protected int execute(String number, int toBase, Consumer printToChat) + protected int execute(String number, int toBase, Consumer printToChat) throws com.mojang.brigadier.exceptions.CommandSyntaxException { int base = 10; @@ -74,9 +73,9 @@ protected int execute(String number, int toBase, Consumer printToChat) toPrefix = "0b"; } if (!toPrefix.isEmpty()) { - printToChat.accept(Text.literal("%s = %s".formatted(prefix + number, toPrefix + output))); + printToChat.accept(Component.literal("%s = %s".formatted(prefix + number, toPrefix + output))); } else { - printToChat.accept(Text.literal("%s = %s in base %s".formatted(prefix + number, output, toBase))); + printToChat.accept(Component.literal("%s = %s in base %s".formatted(prefix + number, output, toBase))); } return 1; } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java index b41879d8..98907b27 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java @@ -9,20 +9,19 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.RedstoneLampBlock; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.BlockStateArgumentType; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.RedstoneLampBlock; +import net.minecraft.world.level.block.state.BlockState; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.WorldEditUtils; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; public class BinaryBlockReadFeature { public static final BinaryBlockReadFeature INSTANCE = new BinaryBlockReadFeature(); @@ -30,14 +29,14 @@ public class BinaryBlockReadFeature { protected BinaryBlockReadFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register( literal("/read") .requires(Commands.PERMISSION_LEVEL_2) .executes(getCommandForArgumentCount(0)) .then(argument("offset", IntegerArgumentType.integer(1)) .executes(getCommandForArgumentCount(1)) - .then(argument("onBlock", BlockStateArgumentType.blockState(registryAccess)) + .then(argument("onBlock", BlockStateArgument.block(registryAccess)) .executes(getCommandForArgumentCount(2)) .then(argument("toBase", IntegerArgumentType.integer(2, 16)) .executes(getCommandForArgumentCount(3)) @@ -45,22 +44,22 @@ public void registerCommand(CommandDispatcher dispatcher, C .executes(getCommandForArgumentCount(4))))))); } - protected Command getCommandForArgumentCount(int argNum) { + protected Command getCommandForArgumentCount(int argNum) { return context -> execute(context, argNum); } - protected int execute(CommandContext context, int argCount) throws CommandSyntaxException { + protected int execute(CommandContext context, int argCount) throws CommandSyntaxException { boolean reverseBits; int offset = argCount >= 1 ? IntegerArgumentType.getInteger(context, "offset") : 2; BlockState onBlock = argCount >= 2 ? - BlockStateArgumentType.getBlockState(context, "onBlock").getBlockState() : - Blocks.REDSTONE_LAMP.getDefaultState().with(RedstoneLampBlock.LIT, true); + BlockStateArgument.getBlock(context, "onBlock").getState() : + Blocks.REDSTONE_LAMP.defaultBlockState().setValue(RedstoneLampBlock.LIT, true); int toBase = argCount >= 3 ? IntegerArgumentType.getInteger(context, "toBase") : 10; reverseBits = argCount >= 4 && BoolArgumentType.getBool(context, "reverseBits"); return execute(context, offset, onBlock, toBase, reverseBits); } - protected int execute(CommandContext context, int offset, BlockState onBlock, int toBase, boolean reverseBits) throws CommandSyntaxException { + protected int execute(CommandContext context, int offset, BlockState onBlock, int toBase, boolean reverseBits) throws CommandSyntaxException { var source = context.getSource(); Region selection = WorldEditUtils.getSelection(source.getPlayer()); @@ -77,14 +76,14 @@ protected int execute(CommandContext context, int offset, B var spacingVector = direction.multiply(offset); if (direction.x() + direction.y() + direction.z() > 1) { - throw new SimpleCommandExceptionType(Text.of("The selection must have 2 axis the same.")).create(); + throw new SimpleCommandExceptionType(Component.nullToEmpty("The selection must have 2 axis the same.")).create(); } var bits = new StringBuilder(); for (BlockVector3 point = pos1; boundingBox.contains(point); point = point.add(spacingVector)) { var pos = new BlockPos(point.x(), point.y(), point.z()); - var actualState = source.getWorld().getBlockState(pos); - var matches = actualState.equals(onBlock) && actualState.getEntries().equals(onBlock.getEntries()); + var actualState = source.getLevel().getBlockState(pos); + var matches = actualState.equals(onBlock) && actualState.getValues().equals(onBlock.getValues()); bits.append(matches ? 1 : 0); } @@ -94,7 +93,7 @@ protected int execute(CommandContext context, int offset, B } var output = Integer.toString(Integer.parseInt(bits.toString(), 2), toBase); - source.sendMessage(Text.of(output)); + source.sendSystemMessage(Component.nullToEmpty(output)); return 0; } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/BlockRaycastFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/BlockRaycastFeature.java index eb58de3a..258af35c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/BlockRaycastFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/BlockRaycastFeature.java @@ -3,28 +3,28 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; import tools.redstone.redstonetools.utils.BlockInfo; public abstract class BlockRaycastFeature { - protected int execute(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - ServerWorld world = context.getSource().getWorld(); - if (player == null || context.getSource().getWorld() == null) { - throw new CommandSyntaxException(null, Text.of("This command is client-side only.")); + protected int execute(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayer(); + ServerLevel world = context.getSource().getLevel(); + if (player == null || context.getSource().getLevel() == null) { + throw new CommandSyntaxException(null, Component.nullToEmpty("This command is client-side only.")); } - double maxDistance = player.getAttributeValue(EntityAttributes.BLOCK_INTERACTION_RANGE); - BlockHitResult hitresult = (BlockHitResult) player.raycast(maxDistance, 1.0f, false); + double maxDistance = player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE); + BlockHitResult hitresult = (BlockHitResult) player.pick(maxDistance, 1.0f, false); if (hitresult.getType() == HitResult.Type.MISS) { if (requiresBlock()) { - throw new SimpleCommandExceptionType(Text.literal("You must be looking at a block to use this command.")).create(); + throw new SimpleCommandExceptionType(Component.literal("You must be looking at a block to use this command.")).create(); } else { return execute(context, null); } @@ -42,5 +42,5 @@ protected boolean requiresBlock() { return true; } - protected abstract int execute(CommandContext context, BlockInfo blockInfo) throws CommandSyntaxException; + protected abstract int execute(CommandContext context, BlockInfo blockInfo) throws CommandSyntaxException; } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java index 128b1080..fc9420ce 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java @@ -15,16 +15,15 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockType; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.*; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; public class ColorCodeFeature { public static final ColorCodeFeature INSTANCE = new ColorCodeFeature(); @@ -32,7 +31,7 @@ public class ColorCodeFeature { protected ColorCodeFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("/colorcode") .requires(Commands.PERMISSION_LEVEL_2) .then(argument("color", StringArgumentType.string()).suggests(ArgumentUtils.BLOCK_COLOR_SUGGESTION_PROVIDER) @@ -70,7 +69,7 @@ private BaseBlock getColoredBlock(World world, BlockVector3 pos, BlockColor colo return blockType.getDefaultState().toBaseBlock(); } - protected int execute(CommandContext context) throws CommandSyntaxException { + protected int execute(CommandContext context) throws CommandSyntaxException { color = ArgumentUtils.parseBlockColor(context, "color"); try { onlyColor = ArgumentUtils.parseBlockColor(context, "onlyColor"); @@ -117,9 +116,9 @@ public BaseBlock applyBlock(BlockVector3 position) { playerSession.remember(session); - context.getSource().sendMessage(Text.literal("Successfully colored %s block(s) %s.".formatted(blocksColored, color))); + context.getSource().sendSystemMessage(Component.literal("Successfully colored %s block(s) %s.".formatted(blocksColored, color))); } catch (Exception e) { - throw new SimpleCommandExceptionType(Text.literal("An error occurred while coloring the block(s).")).create(); + throw new SimpleCommandExceptionType(Component.literal("An error occurred while coloring the block(s).")).create(); } return 1; } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java index 4ba854f1..76cfb8ec 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java @@ -4,16 +4,15 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.BlockColor; import tools.redstone.redstonetools.utils.BlockInfo; import tools.redstone.redstonetools.utils.ColoredBlockType; import javax.annotation.Nullable; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.world.item.ItemStack; public class ColoredFeature extends PickBlockFeature { public static final ColoredFeature INSTANCE = new ColoredFeature(); @@ -21,11 +20,11 @@ public class ColoredFeature extends PickBlockFeature { protected ColoredFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("colored") + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { + dispatcher.register(net.minecraft.commands.Commands.literal("colored") .requires(Commands.PERMISSION_LEVEL_2) .executes(this::execute) - .then(CommandManager.argument("blockType", StringArgumentType.string()).suggests(ArgumentUtils.COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER) + .then(net.minecraft.commands.Commands.argument("blockType", StringArgumentType.string()).suggests(ArgumentUtils.COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER) .executes(this::execute))); } @@ -37,7 +36,7 @@ protected boolean requiresBlock() { } @Override - protected ItemStack getItemStack(CommandContext context, @Nullable BlockInfo blockInfo) { + protected ItemStack getItemStack(CommandContext context, @Nullable BlockInfo blockInfo) { var color = blockInfo == null ? BlockColor.WHITE : BlockColor.fromBlock(blockInfo.block); @@ -48,7 +47,7 @@ protected ItemStack getItemStack(CommandContext context, @N } @Override - protected int execute(CommandContext context, @Nullable BlockInfo blockInfo) throws CommandSyntaxException { + protected int execute(CommandContext context, @Nullable BlockInfo blockInfo) throws CommandSyntaxException { try { blockType = ArgumentUtils.parseColoredBlockType(context, "blockType"); } catch (Exception e) { diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java index 5deb1c4b..5bfa003a 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java @@ -2,16 +2,6 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; -import net.minecraft.block.BlockState; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.BlockStateComponent; -import net.minecraft.component.type.LoreComponent; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.state.property.Property; -import net.minecraft.text.Text; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.mixin.AbstractBlockMixin; import tools.redstone.redstonetools.mixin.features.ServerPlayNetworkHandlerAccessor; @@ -20,6 +10,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.BlockItemStateProperties; +import net.minecraft.world.item.component.ItemLore; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Property; public class CopyStateFeature extends PickBlockFeature { public static final CopyStateFeature INSTANCE = new CopyStateFeature(); @@ -27,37 +26,37 @@ public class CopyStateFeature extends PickBlockFeature { protected CopyStateFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("copystate").requires(Commands.PERMISSION_LEVEL_2).executes(this::execute)); + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { + dispatcher.register(net.minecraft.commands.Commands.literal("copystate").requires(Commands.PERMISSION_LEVEL_2).executes(this::execute)); } @Override - protected ItemStack getItemStack(CommandContext context, BlockInfo blockInfo) { + protected ItemStack getItemStack(CommandContext context, BlockInfo blockInfo) { Objects.requireNonNull(blockInfo); - ItemStack stack = ((AbstractBlockMixin) blockInfo.state.getBlock()).callGetPickStack(context.getSource().getWorld(), blockInfo.pos, blockInfo.state, true); + ItemStack stack = ((AbstractBlockMixin) blockInfo.state.getBlock()).callGetCloneItemStack(context.getSource().getLevel(), blockInfo.pos, blockInfo.state, true); - ServerPlayNetworkHandlerAccessor.callCopyBlockDataToStack(blockInfo.state, context.getSource().getWorld(), blockInfo.pos, stack); + ServerPlayNetworkHandlerAccessor.callAddBlockDataToItem(blockInfo.state, context.getSource().getLevel(), blockInfo.pos, stack); - List lore = new ArrayList<>(); + List lore = new ArrayList<>(); if (blockInfo.entity != null) { - lore.add(Text.literal("Has block entity data")); + lore.add(Component.literal("Has block entity data")); } if (!blockInfo.state.getProperties().isEmpty()) { - BlockStateComponent component = BlockStateComponent.DEFAULT; + BlockItemStateProperties component = BlockItemStateProperties.EMPTY; for (Property property : blockInfo.state.getProperties()) { component = addToLoreAndComponent(lore, component, blockInfo.state, property); } - stack.set(DataComponentTypes.BLOCK_STATE, component); + stack.set(DataComponents.BLOCK_STATE, component); } - stack.set(DataComponentTypes.LORE, new LoreComponent(lore)); + stack.set(DataComponents.LORE, new ItemLore(lore)); return stack; } - private static > BlockStateComponent addToLoreAndComponent(List lore, BlockStateComponent component, BlockState state, Property property) { - lore.add(Text.of(" " + property.getName() + ": " + state.get(property))); - return component.with(property, state.get(property)); + private static > BlockItemStateProperties addToLoreAndComponent(List lore, BlockItemStateProperties component, BlockState state, Property property) { + lore.add(Component.nullToEmpty(" " + property.getName() + ": " + state.getValue(property))); + return component.with(property, state.getValue(property)); } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java index 2455cab4..8e8cb429 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java @@ -4,17 +4,16 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.ItemStackArgument; -import net.minecraft.command.argument.ItemStackArgumentType; -import net.minecraft.item.ItemStack; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.item.ItemArgument; +import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.world.item.ItemStack; import tools.redstone.redstonetools.Commands; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; public class GiveMeFeature { public static final GiveMeFeature INSTANCE = new GiveMeFeature(); @@ -22,28 +21,28 @@ public class GiveMeFeature { protected GiveMeFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register( literal("g") .requires(Commands.PERMISSION_LEVEL_2) - .then(argument("item", ItemStackArgumentType.itemStack(registryAccess)) + .then(argument("item", ItemArgument.item(registryAccess)) .executes(context -> this.execute( context, - ItemStackArgumentType.getItemStackArgument(context, "item"), + ItemArgument.getItem(context, "item"), 1)) .then(argument("count", IntegerArgumentType.integer(1)) .executes(context -> this.execute( context, - ItemStackArgumentType.getItemStackArgument(context, "item"), + ItemArgument.getItem(context, "item"), IntegerArgumentType.getInteger(context, "count")))))); } - private int execute(CommandContext context, ItemStackArgument itemArgument, int count) throws CommandSyntaxException { + private int execute(CommandContext context, ItemInput itemArgument, int count) throws CommandSyntaxException { MinecraftServer server = context.getSource().getServer(); - ItemStack stack = itemArgument.createStack(1, false); + ItemStack stack = itemArgument.createItemStack(1, false); stack.setCount(count); - server.getCommandManager()./*? if <1.21.10 {*//*executeWithPrefix*//*?} else {*/parseAndExecute/*?}*/( - server.getCommandSource(), "/give " + context.getSource().getName() + " " + itemArgument.asString(server.getRegistryManager()) + " " + count); + server.getCommands().performPrefixedCommand( + server.createCommandSourceStack(), "/give " + context.getSource().getTextName() + " " + itemArgument.serialize(server.registryAccess()) + " " + count); return 0; } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java index 55f4e7f3..2b83db4e 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java @@ -3,21 +3,20 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.LoreComponent; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ItemUtils; import java.util.ArrayList; import java.util.List; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemLore; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class ItemBindFeature { public static final ItemBindFeature INSTANCE = new ItemBindFeature(); @@ -25,7 +24,7 @@ public class ItemBindFeature { protected ItemBindFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("itembind") .requires(Commands.PERMISSION_LEVEL_2) .executes(this::execute) @@ -33,60 +32,60 @@ public void registerCommand(CommandDispatcher dispatcher, C .executes(ItemBindFeature::executeReset))); } - private static int executeReset(CommandContext context) { + private static int executeReset(CommandContext context) { var player = context.getSource().getPlayer(); if (player == null) { return 0; } boolean mainhand; - if (ItemUtils.containsCommand(player.getMainHandStack())) { + if (ItemUtils.containsCommand(player.getMainHandItem())) { mainhand = true; - } else if (ItemUtils.containsCommand(player.getOffHandStack())) { + } else if (ItemUtils.containsCommand(player.getOffhandItem())) { mainhand = false; } else { - context.getSource().getPlayer().sendMessage(Text.of("You need to be holding an item with a command in one of your hands!"), false); + context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); return 0; } - ItemStack stack = mainhand ? player.getMainHandStack() : player.getOffHandStack(); + ItemStack stack = mainhand ? player.getMainHandItem() : player.getOffhandItem(); ItemUtils.removeCommand(stack); - stack.set(DataComponentTypes.LORE, stack.getItem().getDefaultStack().get(DataComponentTypes.LORE)); - context.getSource().getPlayer().sendMessage(Text.of("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); + stack.set(DataComponents.LORE, stack.getItem().getDefaultInstance().get(DataComponents.LORE)); + context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); return 1; } - public static ArrayList playersWaitingForCommand = new ArrayList<>(); + public static ArrayList playersWaitingForCommand = new ArrayList<>(); - protected int execute(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); + protected int execute(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); playersWaitingForCommand.add(source.getPlayer()); - source.sendMessage(Text.literal("Please run any command and hold the item you want the command be bound to in your main hand")); + source.sendSystemMessage(Component.literal("Please run any command and hold the item you want the command be bound to in your main hand")); return 1; } - public static void addCommand(String command, ServerPlayerEntity playerI) { + public static void addCommand(String command, ServerPlayer playerI) { if (!waitingForCommandForPlayer(playerI)) return; - ItemStack stack = playerI.getMainHandStack(); + ItemStack stack = playerI.getMainHandItem(); if (stack.isEmpty()) { - if (playerI.getOffHandStack().isEmpty()) { - playerI.sendMessage(Text.literal("You need to be holding an item!")); + if (playerI.getOffhandItem().isEmpty()) { + playerI.sendSystemMessage(Component.literal("You need to be holding an item!")); return; } else - stack = playerI.getOffHandStack(); + stack = playerI.getOffhandItem(); } ItemUtils.setCommand(stack, command); // `command` here doesn't start with a / for some // reason, so we add it ourselves so its more clear - stack.set(DataComponentTypes.LORE, new LoreComponent(List.of(Text.of("Has command: /" + command)))); + stack.set(DataComponents.LORE, new ItemLore(List.of(Component.nullToEmpty("Has command: /" + command)))); playersWaitingForCommand.remove(playerI); - playerI.sendMessage(Text.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); + playerI.displayClientMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); } - public static boolean waitingForCommandForPlayer(ServerPlayerEntity player1) { + public static boolean waitingForCommandForPlayer(ServerPlayer player1) { return playersWaitingForCommand.contains(player1); } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java index e23b7b9c..b8671da5 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java @@ -11,17 +11,16 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.component.ComponentChanges; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtHelper; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.core.component.DataComponentPatch; import net.minecraft.nbt.NbtOps; -import net.minecraft.registry.RegistryOps; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.nbt.Tag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.RegistryOps; +import net.minecraft.world.item.ItemStack; import tools.redstone.redstonetools.Commands; import java.util.Objects; @@ -32,28 +31,28 @@ public class ItemComponentsFeature { protected ItemComponentsFeature() { } - private final SimpleCommandExceptionType NO_COMPONENTS_EXCEPTION = new SimpleCommandExceptionType(Text.literal("No components!")); + private final SimpleCommandExceptionType NO_COMPONENTS_EXCEPTION = new SimpleCommandExceptionType(Component.literal("No components!")); - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register( - CommandManager.literal("components") + net.minecraft.commands.Commands.literal("components") .requires(Commands.PERMISSION_LEVEL_2) - .executes(context -> components(Objects.requireNonNull(context.getSource().getPlayer()).getMainHandStack(), context.getSource())) - .then(CommandManager.argument("target", EntityArgumentType.player()) - .executes(context -> components(EntityArgumentType.getPlayer(context, "target").getMainHandStack(), context.getSource())) + .executes(context -> components(Objects.requireNonNull(context.getSource().getPlayer()).getMainHandItem(), context.getSource())) + .then(net.minecraft.commands.Commands.argument("target", EntityArgument.player()) + .executes(context -> components(EntityArgument.getPlayer(context, "target").getMainHandItem(), context.getSource())) ) ); } - private int components(ItemStack stack, ServerCommandSource source) throws CommandSyntaxException { - ComponentChanges components = stack.getComponentChanges(); + private int components(ItemStack stack, CommandSourceStack source) throws CommandSyntaxException { + DataComponentPatch components = stack.getComponentsPatch(); if (components.isEmpty()) throw NO_COMPONENTS_EXCEPTION.create(); - RegistryOps ops = source.getRegistryManager().getOps(NbtOps.INSTANCE); - NbtElement output = ComponentChanges.CODEC.encodeStart(ops, components).getOrThrow(); + RegistryOps ops = source.registryAccess().createSerializationContext(NbtOps.INSTANCE); + Tag output = DataComponentPatch.CODEC.encodeStart(ops, components).getOrThrow(); - source.sendFeedback(() -> NbtHelper.toPrettyPrintedText(output), false); + source.sendSuccess(() -> NbtUtils.toPrettyComponent(output), false); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java index ad73011c..931d6eb5 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java @@ -12,18 +12,17 @@ import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.WorldEditUtils; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class MinSelectionFeature { public static final MinSelectionFeature INSTANCE = new MinSelectionFeature(); @@ -31,13 +30,13 @@ public class MinSelectionFeature { protected MinSelectionFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("/minsel") .requires(Commands.PERMISSION_LEVEL_2) .executes(this::execute)); } - protected int execute(CommandContext context) throws CommandSyntaxException { + protected int execute(CommandContext context) throws CommandSyntaxException { var selection = WorldEditUtils.getSelection(context.getSource().getPlayer()); var selectionWorld = selection.getWorld(); @@ -60,7 +59,7 @@ protected int execute(CommandContext context) throws Comman } if (isEmpty) { - throw new SimpleCommandExceptionType(Text.of("Cannot minimize empty selections.")).create(); + throw new SimpleCommandExceptionType(Component.nullToEmpty("Cannot minimize empty selections.")).create(); } minimiseSelection(selectionWorld, selection); @@ -68,7 +67,7 @@ protected int execute(CommandContext context) throws Comman selector.learnChanges(); selector.explainRegionAdjust(actor, localSession); - context.getSource().sendMessage(Text.literal("Minimized selection.")); + context.getSource().sendSystemMessage(Component.literal("Minimized selection.")); return 1; } @@ -98,7 +97,7 @@ private void minimiseSelection(World selectionWorld, Region selection) try { selection.contract(changes.toArray(new BlockVector3[0])); } catch (RegionOperationException e) { - throw new CommandSyntaxException(null, Text.literal("There was an error modifying the region.")); + throw new CommandSyntaxException(null, Component.literal("There was an error modifying the region.")); } if (!finished) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java index 8f054ce3..5e89d38c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java @@ -3,63 +3,72 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; import tools.redstone.redstonetools.mixin.features.PlayerInventoryAccessor; import tools.redstone.redstonetools.utils.BlockInfo; import javax.annotation.Nullable; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetHeldSlotPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; public abstract class PickBlockFeature extends BlockRaycastFeature { @Override - protected int execute(CommandContext context, BlockInfo blockInfo) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); + protected int execute(CommandContext context, BlockInfo blockInfo) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayer(); if (player == null) { - throw new SimpleCommandExceptionType(Text.literal("Failed to get player.")).create(); + throw new SimpleCommandExceptionType(Component.literal("Failed to get player.")).create(); } var stack = getItemStack(context, blockInfo); - PlayerInventory playerInventory = player.getInventory(); + Inventory playerInventory = player.getInventory(); addPickBlock(playerInventory, stack); - int i = playerInventory.getSlotWithStack(stack); + int i = playerInventory.findSlotMatchingItem(stack); if (i != -1) { - if (PlayerInventory.isValidHotbarIndex(i)) { - playerInventory.setSelectedSlot(i); + if (Inventory.isHotbarSlot(i)) { + //? if <=1.21.4 { + playerInventory.setSelectedHotbarSlot(i); + //? } else +// playerInventory.setSelectedSlot(i); } else { - playerInventory.swapSlotWithHotbar(i); + playerInventory.pickSlot(i); } - } else if (player.isInCreativeMode()) { - playerInventory.swapStackWithHotbar(stack); + } else if (player.hasInfiniteMaterials()) { + playerInventory.addAndPickItem(stack); } - context.getSource().getPlayer().networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(((PlayerInventoryAccessor)playerInventory).getSelectedSlot())); - player.playerScreenHandler.sendContentUpdates(); + context.getSource().getPlayer().connection.send(new ClientboundSetHeldSlotPacket(((PlayerInventoryAccessor)playerInventory).getSelected())); + player.inventoryMenu.broadcastChanges(); return 1; } // reimplementation from 1.18.2 - public void addPickBlock(PlayerInventory pi, ItemStack stack) { - int i = pi.getSlotWithStack(stack); - if (PlayerInventory.isValidHotbarIndex(i)) { - pi.setSelectedSlot(i); + public void addPickBlock(Inventory pi, ItemStack stack) { + int i = pi.findSlotMatchingItem(stack); + if (Inventory.isHotbarSlot(i)) { + //? if <=1.21.4 { + pi.setSelectedHotbarSlot(i); + //? } else +// pi.setSelectedSlot(i); return; } if (i == -1) { int j; - pi.setSelectedSlot(pi.getSwappableHotbarSlot()); - if (!((PlayerInventoryAccessor)pi).getMain().get(((PlayerInventoryAccessor)pi).getSelectedSlot()).isEmpty() && (j = pi.getEmptySlot()) != -1) { - ((PlayerInventoryAccessor)pi).getMain().set(j, ((PlayerInventoryAccessor)pi).getMain().get(((PlayerInventoryAccessor)pi).getSelectedSlot())); + //? if <=1.21.4 { + pi.setSelectedHotbarSlot(pi.getSuitableHotbarSlot()); + //? } else +// pi.setSelectedSlot(pi.getSuitableHotbarSlot()); + if (!((PlayerInventoryAccessor)pi).getItems().get(((PlayerInventoryAccessor)pi).getSelected()).isEmpty() && (j = pi.getFreeSlot()) != -1) { + ((PlayerInventoryAccessor)pi).getItems().set(j, ((PlayerInventoryAccessor)pi).getItems().get(((PlayerInventoryAccessor)pi).getSelected())); } - ((PlayerInventoryAccessor)pi).getMain().set(((PlayerInventoryAccessor)pi).getSelectedSlot(), stack); + ((PlayerInventoryAccessor)pi).getItems().set(((PlayerInventoryAccessor)pi).getSelected(), stack); } else { - pi.swapSlotWithHotbar(i); + pi.pickSlot(i); } } - protected abstract ItemStack getItemStack(CommandContext context, @Nullable BlockInfo blockInfo) throws CommandSyntaxException; + protected abstract ItemStack getItemStack(CommandContext context, @Nullable BlockInfo blockInfo) throws CommandSyntaxException; } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java index 5db5f72f..d21ffc5a 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java @@ -6,24 +6,23 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.Vec3d; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.PositionUtils; import tools.redstone.redstonetools.utils.RaycastUtils; import java.util.ArrayList; import java.util.List; - -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; + +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; public class QuickTpFeature { public static final QuickTpFeature INSTANCE = new QuickTpFeature(); @@ -31,7 +30,7 @@ public class QuickTpFeature { protected QuickTpFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("quicktp") .requires(Commands.PERMISSION_LEVEL_2) .executes(this::parseArguments) @@ -43,10 +42,10 @@ public void registerCommand(CommandDispatcher dispatcher, C .executes(this::parseArguments))))); } - protected int parseArguments(CommandContext context) throws CommandSyntaxException { + protected int parseArguments(CommandContext context) throws CommandSyntaxException { var player = context.getSource().getPlayer(); - if (quicktpingForPlayer.contains(player)) throw new SimpleCommandExceptionType(Text.literal("Already doing a quicktp!")).create(); + if (quicktpingForPlayer.contains(player)) throw new SimpleCommandExceptionType(Component.literal("Already doing a quicktp!")).create(); quicktpingForPlayer.add(player); double distance; boolean includeFluids; @@ -83,7 +82,7 @@ protected int parseArguments(CommandContext context) throws } catch (InterruptedException ignored) { } if (thread.isAlive()) { - player.sendMessage(Text.literal("Quicktp still running after 10 seconds. Canceling quicktp!")); + player.sendSystemMessage(Component.literal("Quicktp still running after 10 seconds. Canceling quicktp!")); quicktpingForPlayer.remove(player); } thread.interrupt(); @@ -92,28 +91,28 @@ protected int parseArguments(CommandContext context) throws return 1; } - public static List quicktpingForPlayer = new ArrayList<>(); + public static List quicktpingForPlayer = new ArrayList<>(); - protected static void execute(CommandContext context, double distance, boolean includeFluids, boolean resetVelocity) throws CommandSyntaxException { + protected static void execute(CommandContext context, double distance, boolean includeFluids, boolean resetVelocity) throws CommandSyntaxException { var player = context.getSource().getPlayer(); assert player != null; try { - var hit = player.raycast(distance, 0, includeFluids); + var hit = player.pick(distance, 0, includeFluids); var targetPosition = clampHitPosition(hit); - player.requestTeleport(targetPosition.x, targetPosition.y, targetPosition.z); - if (resetVelocity) player.setVelocity(Vec3d.ZERO); + player.teleportTo(targetPosition.x, targetPosition.y, targetPosition.z); + if (resetVelocity) player.setDeltaMovement(Vec3.ZERO); player.fallDistance = 0; - player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player)); + player.connection.send(new ClientboundSetEntityMotionPacket(player)); } finally { quicktpingForPlayer.remove(player); } } - private static Vec3d clampHitPosition(HitResult hit) { + private static Vec3 clampHitPosition(HitResult hit) { if (hit.getType() != HitResult.Type.BLOCK) { - return hit.getPos().subtract(0, 0.5, 0); + return hit.getLocation().subtract(0, 0.5, 0); } var blockHit = (BlockHitResult) hit; diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java index b3d24f92..976d2c55 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java @@ -19,19 +19,18 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.DirectionArgument; import java.util.Objects; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; import static tools.redstone.redstonetools.utils.DirectionUtils.directionToBlock; import static tools.redstone.redstonetools.utils.DirectionUtils.matchDirection; @@ -41,7 +40,7 @@ public class RStackFeature { protected RStackFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register( literal("/rstack") .requires(Commands.PERMISSION_LEVEL_2) @@ -56,11 +55,11 @@ public void registerCommand(CommandDispatcher dispatcher, C .executes(getCommandForArgumentCount(4))))))); } - protected Command getCommandForArgumentCount(int argNum) { + protected Command getCommandForArgumentCount(int argNum) { return context -> execute(context, argNum); } - protected int execute(CommandContext context, int argCount) throws CommandSyntaxException { + protected int execute(CommandContext context, int argCount) throws CommandSyntaxException { int count = argCount >= 1 ? IntegerArgumentType.getInteger(context, "count") : 1; DirectionArgument direction = argCount >= 2 ? ArgumentUtils.parseDirection(context, "direction") : DirectionArgument.ME; int offset = argCount >= 3 ? IntegerArgumentType.getInteger(context, "offset") : 2; @@ -68,7 +67,7 @@ protected int execute(CommandContext context, int argCount) return execute(context, count, offset, direction, moveSelection); } - protected int execute(CommandContext context, int count, int offset, DirectionArgument direction, boolean moveSelection) throws CommandSyntaxException { + protected int execute(CommandContext context, int count, int offset, DirectionArgument direction, boolean moveSelection) throws CommandSyntaxException { var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); var localSession = WorldEdit.getInstance() @@ -82,7 +81,7 @@ protected int execute(CommandContext context, int count, in try { selection = localSession.getSelection(selectionWorld); } catch (IncompleteRegionException ex) { - throw new SimpleCommandExceptionType(Text.literal("Please make a selection with WorldEdit first.")).create(); + throw new SimpleCommandExceptionType(Component.literal("Please make a selection with WorldEdit first.")).create(); } final Mask airFilter = new Mask() { @@ -103,7 +102,7 @@ public Mask2D toMask2D() { try { stackDirection = matchDirection(direction, playerFacing); } catch (Exception e) { - throw new SimpleCommandExceptionType(Text.literal(e.getMessage().formatted(e))).create(); + throw new SimpleCommandExceptionType(Component.literal(e.getMessage().formatted(e))).create(); } var stackVector = directionToBlock(stackDirection); @@ -129,7 +128,7 @@ public Mask2D toMask2D() { throw new RuntimeException(e); } - context.getSource().sendMessage(Text.literal("Stacked %s time(s).".formatted(count))); + context.getSource().sendSystemMessage(Component.literal("Stacked %s time(s).".formatted(count))); return 1; } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java index 07a2a168..fd5759bd 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java @@ -3,10 +3,9 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.context.CommandContext; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.world.entity.ai.attributes.Attributes; import tools.redstone.redstonetools.Commands; public class ReachFeature { @@ -15,28 +14,28 @@ public class ReachFeature { protected ReachFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("reach") + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { + dispatcher.register(net.minecraft.commands.Commands.literal("reach") .requires(Commands.PERMISSION_LEVEL_2) - .then(CommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(net.minecraft.commands.Commands.argument("reach", FloatArgumentType.floatArg(0.0f)) .executes(context -> execute(context, true, true)) ) - .then(CommandManager.literal("reset") + .then(net.minecraft.commands.Commands.literal("reset") .executes(context -> reset(context, true, true)) ) - .then(CommandManager.literal("block") - .then(CommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(net.minecraft.commands.Commands.literal("block") + .then(net.minecraft.commands.Commands.argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { - builder.suggest(String.valueOf(EntityAttributes.BLOCK_INTERACTION_RANGE.value().getDefaultValue())); + builder.suggest(String.valueOf(Attributes.BLOCK_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); }) .executes(context -> execute(context, true, false)) ) ) - .then(CommandManager.literal("entity") - .then(CommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(net.minecraft.commands.Commands.literal("entity") + .then(net.minecraft.commands.Commands.argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { - builder.suggest(String.valueOf(EntityAttributes.ENTITY_INTERACTION_RANGE.value().getDefaultValue())); + builder.suggest(String.valueOf(Attributes.ENTITY_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); }) .executes(context -> execute(context, false, true)) @@ -44,21 +43,21 @@ public void registerCommand(CommandDispatcher dispatcher, C )); } - private int execute(CommandContext context, boolean block, boolean entity) { + private int execute(CommandContext context, boolean block, boolean entity) { float reach = FloatArgumentType.getFloat(context, "reach"); if (block) execute(context, "/attribute @s minecraft:block_interaction_range base set " + reach); if (entity) execute(context, "/attribute @s minecraft:entity_interaction_range base set " + reach); return 0; } - private int reset(CommandContext context, boolean block, boolean entity) { + private int reset(CommandContext context, boolean block, boolean entity) { if (block) execute(context, "/attribute @s minecraft:block_interaction_range base reset"); if (entity) execute(context, "/attribute @s minecraft:entity_interaction_range base reset"); return 0; } - private static void execute(CommandContext context, String command) { - context.getSource().getServer().getCommandManager() - ./*? if <1.21.10 {*//*executeWithPrefix*//*?} else {*/parseAndExecute/*?}*/(context.getSource(), command); + private static void execute(CommandContext context, String command) { + context.getSource().getServer().getCommands() + .performPrefixedCommand(context.getSource(), command); } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java index c8e7fb09..5cb8cfc0 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java @@ -6,11 +6,6 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.SignalBlock; @@ -18,9 +13,13 @@ import java.util.Locale; import java.util.Objects; import java.util.Random; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; public class SignalStrengthBlockFeature { public static final SignalStrengthBlockFeature INSTANCE = new SignalStrengthBlockFeature(); @@ -28,7 +27,7 @@ public class SignalStrengthBlockFeature { protected SignalStrengthBlockFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("ssb") .requires(Commands.PERMISSION_LEVEL_2) .executes(this::parseArguments) @@ -38,7 +37,7 @@ public void registerCommand(CommandDispatcher dispatcher, C .executes(this::parseArguments)))); } - protected int parseArguments(CommandContext context) throws CommandSyntaxException { + protected int parseArguments(CommandContext context) throws CommandSyntaxException { int signalStrength; SignalBlock block; try { @@ -54,14 +53,14 @@ protected int parseArguments(CommandContext context) throws return execute(context, signalStrength, block); } - protected int execute(CommandContext context, int signalStrength, SignalBlock block) throws CommandSyntaxException { + protected int execute(CommandContext context, int signalStrength, SignalBlock block) throws CommandSyntaxException { try { var playerInventory = Objects.requireNonNull(context.getSource().getPlayer()).getInventory(); ItemStack itemStack = block.getItemStack(signalStrength); - playerInventory.insertStack(itemStack); + playerInventory.add(itemStack); // playerInventory.swapStackWithHotbar(itemStack); } catch (IllegalArgumentException | IllegalStateException | NullPointerException e) { - throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create(); + throw new SimpleCommandExceptionType(Component.literal(e.getMessage())).create(); } // who intentionally doesnt put a space between the last / and the message?? @@ -73,7 +72,7 @@ protected int execute(CommandContext context, int signalStr "This seems unnecessary.", "Is that a typo?", "Do you just like the glint?", "Wow, what a fancy but otherwise useless " + block.name().toLowerCase(Locale.ROOT).replace("_", " ") + "." , "For decoration?"}; - context.getSource().sendMessage(Text.literal(funny[new Random().nextInt(funny.length)])); + context.getSource().sendSystemMessage(Component.literal(funny[new Random().nextInt(funny.length)])); return 1; } diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoDustFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoDustFeature.java index 3e2dd3e0..f75b5d20 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoDustFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoDustFeature.java @@ -3,11 +3,11 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class AutoDustFeature extends ToggleableFeature { public static final AutoDustFeature INSTANCE = new AutoDustFeature(); @@ -15,11 +15,11 @@ public class AutoDustFeature extends ToggleableFeature { protected AutoDustFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("autodust").executes(this::execute)); } - private int execute(CommandContext context) throws CommandSyntaxException { + private int execute(CommandContext context) throws CommandSyntaxException { return this.toggle(context); } diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoRotateFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoRotateFeature.java index 6e00ce52..ad351e77 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoRotateFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/AutoRotateFeature.java @@ -1,11 +1,11 @@ package tools.redstone.redstonetools.features.toggleable; import com.mojang.brigadier.CommandDispatcher; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class AutoRotateFeature extends ToggleableFeature { public static final AutoRotateFeature INSTANCE = new AutoRotateFeature(); @@ -13,7 +13,7 @@ public class AutoRotateFeature extends ToggleableFeature { protected AutoRotateFeature() { } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("autorotate").executes(this::toggle)); } diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java index d828ee2f..c776f4ab 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java @@ -2,24 +2,24 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.state.property.IntProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import tools.redstone.redstonetools.RedstoneTools; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class ClickContainerFeature extends ToggleableFeature { public static final ClickContainerFeature INSTANCE = new ClickContainerFeature(); @@ -31,68 +31,68 @@ protected ClickContainerFeature() { static { UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (world == null) return ActionResult.PASS; - if (world.isClient()) return ActionResult.PASS; - if (!ClickContainerFeature.INSTANCE.isEnabled((ServerPlayerEntity) player)) return ActionResult.PASS; + if (world == null) return InteractionResult.PASS; + if (world.isClientSide()) return InteractionResult.PASS; + if (!ClickContainerFeature.INSTANCE.isEnabled((ServerPlayer) player)) return InteractionResult.PASS; - ItemStack stack = player.getStackInHand(hand); - if (!stack.isEmpty() || stack.getItem() instanceof BlockItem) return ActionResult.PASS; + ItemStack stack = player.getItemInHand(hand); + if (!stack.isEmpty() || stack.getItem() instanceof BlockItem) return InteractionResult.PASS; BlockPos pos = hitResult.getBlockPos(); BlockState state = world.getBlockState(pos); - if (world.getTime() == lasttime) { - return ActionResult.PASS; + if (world.getGameTime() == lasttime) { + return InteractionResult.PASS; } - lasttime = world.getTime(); + lasttime = world.getGameTime(); - if (state.isOf(Blocks.WATER_CAULDRON) || state.isOf(Blocks.LAVA_CAULDRON) || state.isOf(Blocks.POWDER_SNOW_CAULDRON)) { - if (state.contains(Properties.LEVEL_3)) { - handleIntLevelProperty(world, pos, state, Properties.LEVEL_3, Blocks.CAULDRON, (ServerPlayerEntity) player); - return ActionResult.SUCCESS; + if (state.is(Blocks.WATER_CAULDRON) || state.is(Blocks.LAVA_CAULDRON) || state.is(Blocks.POWDER_SNOW_CAULDRON)) { + if (state.hasProperty(BlockStateProperties.LEVEL_CAULDRON)) { + handleIntLevelProperty(world, pos, state, BlockStateProperties.LEVEL_CAULDRON, Blocks.CAULDRON, (ServerPlayer) player); + return InteractionResult.SUCCESS; } } - if (state.isOf(Blocks.CAULDRON)) { - BlockState newState = Blocks.WATER_CAULDRON.getDefaultState().with(Properties.LEVEL_3, 1); - world.setBlockState(pos, newState); - return ActionResult.SUCCESS; + if (state.is(Blocks.CAULDRON)) { + BlockState newState = Blocks.WATER_CAULDRON.defaultBlockState().setValue(BlockStateProperties.LEVEL_CAULDRON, 1); + world.setBlockAndUpdate(pos, newState); + return InteractionResult.SUCCESS; } - if (state.isOf(Blocks.COMPOSTER)) { - handleIntLevelProperty(world, pos, state, Properties.LEVEL_8, Blocks.COMPOSTER, (ServerPlayerEntity) player); - return ActionResult.SUCCESS; + if (state.is(Blocks.COMPOSTER)) { + handleIntLevelProperty(world, pos, state, BlockStateProperties.LEVEL_COMPOSTER, Blocks.COMPOSTER, (ServerPlayer) player); + return InteractionResult.SUCCESS; } - return ActionResult.PASS; + return InteractionResult.PASS; }); } - public static void handleIntLevelProperty(World world, BlockPos pos, BlockState state, IntProperty prop, Block resetBlock, ServerPlayerEntity player) { + public static void handleIntLevelProperty(Level world, BlockPos pos, BlockState state, IntegerProperty prop, Block resetBlock, ServerPlayer player) { if (prop == null) return; Integer current; try { - current = state.get(prop); + current = state.getValue(prop); } catch (Exception e) { RedstoneTools.LOGGER.error("[ClickContainerFeature] Failed to read property " + prop.getName() + " for block " + state.getBlock() + " at " + pos + ": " + e); return; } if (current == null) return; - int max = prop.getValues().stream().max(Integer::compareTo).orElse(current); + int max = prop.getPossibleValues().stream().max(Integer::compareTo).orElse(current); if (current >= max) { - world.setBlockState(pos, resetBlock.getDefaultState()); + world.setBlockAndUpdate(pos, resetBlock.defaultBlockState()); return; } int next = current + 1; - world.setBlockState(pos, state.with(prop, next), 3); + world.setBlock(pos, state.setValue(prop, next), 3); - player.sendMessage(Text.of("§2[ClickContainers] §6Increased level!")); + player.sendSystemMessage(Component.nullToEmpty("§2[ClickContainers] §6Increased level!")); } - public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess, Commands.CommandSelection registrationEnvironment) { dispatcher.register(literal("clickcontainers").executes(this::toggle)); } diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java index 622d3bf6..edc0659e 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java @@ -3,9 +3,9 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; import java.util.HashSet; @@ -15,20 +15,20 @@ public abstract class ToggleableFeature { private final Set enabledFor = new HashSet<>(); // volatile for thread safety - public boolean isEnabled(ServerPlayerEntity player) { - return enabledFor.contains(player.getUuid()); + public boolean isEnabled(ServerPlayer player) { + return enabledFor.contains(player.getUUID()); } - public int toggle(CommandContext context) throws CommandSyntaxException { + public int toggle(CommandContext context) throws CommandSyntaxException { return toggle(context.getSource()); } - public int toggle(ServerCommandSource source) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayerOrThrow(); - return !enabledFor.contains(player.getUuid()) ? enable(source) : disable(source); + public int toggle(CommandSourceStack source) throws CommandSyntaxException { + ServerPlayer player = source.getPlayerOrException(); + return !enabledFor.contains(player.getUUID()) ? enable(source) : disable(source); } - public void setEnabled(boolean status, ServerPlayerEntity player) { + public void setEnabled(boolean status, ServerPlayer player) { if (status) { enable(player); } else { @@ -36,29 +36,29 @@ public void setEnabled(boolean status, ServerPlayerEntity player) { } } - public void enable(ServerPlayerEntity player) { - enabledFor.add(player.getUuid()); + public void enable(ServerPlayer player) { + enabledFor.add(player.getUUID()); var payload = new SetFeatureEnabledPayload(this.getName(), true); ServerPlayNetworking.send(player, payload); onEnable(); } - public int enable(ServerCommandSource source) throws CommandSyntaxException { - enable(source.getPlayerOrThrow()); - source.sendMessage(Text.literal("Enabled " + this.getName())); + public int enable(CommandSourceStack source) throws CommandSyntaxException { + enable(source.getPlayerOrException()); + source.sendSystemMessage(Component.literal("Enabled " + this.getName())); return 0; } - public void disable(ServerPlayerEntity player) { - enabledFor.remove(player.getUuid()); + public void disable(ServerPlayer player) { + enabledFor.remove(player.getUUID()); var payload = new SetFeatureEnabledPayload(this.getName(), false); ServerPlayNetworking.send(player, payload); onDisable(); } - public int disable(ServerCommandSource source) throws CommandSyntaxException { - disable(source.getPlayerOrThrow()); - source.sendMessage(Text.literal("Disabled " + this.getName())); + public int disable(CommandSourceStack source) throws CommandSyntaxException { + disable(source.getPlayerOrException()); + source.sendSystemMessage(Component.literal("Disabled " + this.getName())); return 0; } diff --git a/src/main/java/tools/redstone/redstonetools/mixin/AbstractBlockMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/AbstractBlockMixin.java index f03103eb..4113a733 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/AbstractBlockMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/AbstractBlockMixin.java @@ -1,15 +1,15 @@ package tools.redstone.redstonetools.mixin; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(AbstractBlock.class) +@Mixin(BlockBehaviour.class) public interface AbstractBlockMixin { @Invoker - ItemStack callGetPickStack(WorldView world, BlockPos pos, BlockState state, boolean includeData); + ItemStack callGetCloneItemStack(LevelReader world, BlockPos pos, BlockState state, boolean includeData); } diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoDustMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoDustMixin.java index 60f60a21..b139401c 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoDustMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoDustMixin.java @@ -1,19 +1,19 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -24,14 +24,14 @@ @Mixin(Block.class) public abstract class AutoDustMixin { - @Inject(method = "onPlaced", at = @At("TAIL")) - private void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack, CallbackInfo ci) { - if (placer instanceof ServerPlayerEntity player) { - if (!AutoDustFeature.INSTANCE.isEnabled(player) || world.isClient()) { + @Inject(method = "setPlacedBy", at = @At("TAIL")) + private void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack, CallbackInfo ci) { + if (placer instanceof ServerPlayer player) { + if (!AutoDustFeature.INSTANCE.isEnabled(player) || world.isClientSide()) { return; } - var dustPos = pos.up(); + var dustPos = pos.above(); var block = world.getBlockState(pos).getBlock(); var blockAbove = world.getBlockState(dustPos).getBlock(); @@ -39,9 +39,9 @@ private void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity return; } - ItemPlacementContext context = new ItemPlacementContext(player, Hand.MAIN_HAND, new ItemStack(Items.REDSTONE), - new BlockHitResult(new Vec3d(dustPos.getX(), dustPos.getY(), dustPos.getZ()), Direction.UP, dustPos, false)); - PlayerUtils.getWorld(placer).setBlockState(dustPos, Blocks.REDSTONE_WIRE.getPlacementState(context)); + BlockPlaceContext context = new BlockPlaceContext(player, InteractionHand.MAIN_HAND, new ItemStack(Items.REDSTONE), + new BlockHitResult(new Vec3(dustPos.getX(), dustPos.getY(), dustPos.getZ()), Direction.UP, dustPos, false)); + PlayerUtils.getWorld(placer).setBlockAndUpdate(dustPos, Blocks.REDSTONE_WIRE.getStateForPlacement(context)); } } } diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java index c998360f..b33b2c17 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java @@ -2,12 +2,12 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.BlockRotation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -16,23 +16,23 @@ @Mixin(BlockItem.class) public abstract class AutoRotateMixin { @Shadow - protected abstract boolean canPlace(ItemPlacementContext context, BlockState state); + protected abstract boolean canPlace(BlockPlaceContext context, BlockState state); @ModifyReturnValue(method = "getPlacementState", at = @At("RETURN")) - private BlockState changeRotation(BlockState original, @Local(argsOnly = true) ItemPlacementContext context) { - if (!(context.getPlayer() instanceof ServerPlayerEntity player)) return original; + private BlockState changeRotation(BlockState original, @Local(argsOnly = true) BlockPlaceContext context) { + if (!(context.getPlayer() instanceof ServerPlayer player)) return original; //? if <1.21.10 { - /*MinecraftServer server = player.getServer(); + MinecraftServer server = player.getServer(); if (server == null) return original; - *///?} else { - MinecraftServer server = player.getEntityWorld().getServer(); - //?} - if (!server.isDedicated()) return original; + //?} else { + /*MinecraftServer server = player.level().getServer(); + *///?} + if (!server.isDedicatedServer()) return original; if (!AutoRotateFeature.INSTANCE.isEnabled(player)) return original; if (original == null) return null; BlockState backup = original; - original = original.rotate(BlockRotation.CLOCKWISE_180); + original = original.rotate(Rotation.CLOCKWISE_180); if (this.canPlace(context, original)) return original; diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/CommandManagerMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/CommandManagerMixin.java index bff6bc86..e9e5ab38 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/CommandManagerMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/CommandManagerMixin.java @@ -1,20 +1,20 @@ package tools.redstone.redstonetools.mixin.features; import com.mojang.brigadier.ParseResults; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import tools.redstone.redstonetools.features.commands.ItemBindFeature; -@Mixin(CommandManager.class) +@Mixin(Commands.class) public class CommandManagerMixin { - @Inject(method = "execute", at = @At("HEAD"), cancellable = true) - public void checkItemBind(ParseResults parseResults, String command, CallbackInfo ci) { - ServerPlayerEntity player = parseResults.getContext().getSource().getPlayer(); + @Inject(method = "performCommand", at = @At("HEAD"), cancellable = true) + public void checkItemBind(ParseResults parseResults, String command, CallbackInfo ci) { + ServerPlayer player = parseResults.getContext().getSource().getPlayer(); if (ItemBindFeature.waitingForCommandForPlayer(player)) { ItemBindFeature.addCommand(command, player); ItemBindFeature.playersWaitingForCommand.remove(player); diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/PlayerInventoryAccessor.java b/src/main/java/tools/redstone/redstonetools/mixin/features/PlayerInventoryAccessor.java index 7e60f3bc..b004708f 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/PlayerInventoryAccessor.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/PlayerInventoryAccessor.java @@ -1,16 +1,16 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; +import net.minecraft.core.NonNullList; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(PlayerInventory.class) +@Mixin(Inventory.class) public interface PlayerInventoryAccessor { @Accessor - DefaultedList getMain(); + NonNullList getItems(); @Accessor - int getSelectedSlot(); + int getSelected(); } \ No newline at end of file diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/ServerPlayNetworkHandlerAccessor.java b/src/main/java/tools/redstone/redstonetools/mixin/features/ServerPlayNetworkHandlerAccessor.java index ac850fb3..8c92bba9 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/ServerPlayNetworkHandlerAccessor.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/ServerPlayNetworkHandlerAccessor.java @@ -1,17 +1,17 @@ package tools.redstone.redstonetools.mixin.features; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(ServerPlayNetworkHandler.class) +@Mixin(ServerGamePacketListenerImpl.class) public interface ServerPlayNetworkHandlerAccessor { @Invoker - static void callCopyBlockDataToStack(BlockState state, ServerWorld world, BlockPos pos, ItemStack stack) { + static void callAddBlockDataToItem(BlockState state, ServerLevel world, BlockPos pos, ItemStack stack) { throw new IllegalStateException(); } } diff --git a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java index 0235bf23..c9f3b323 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java @@ -1,25 +1,25 @@ package tools.redstone.redstonetools.mixin.gamerules; -import net.minecraft.item.ItemStack; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ItemScatterer; -import net.minecraft.world.World; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Containers; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import tools.redstone.redstonetools.RedstoneToolsGameRules; -@Mixin(ItemScatterer.class) +@Mixin(Containers.class) public abstract class DoContainerDropsMixin { - @Inject(method = "spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", at = @At("HEAD"), cancellable = true) - private static void preventSpawning(World world, double x, double y, double z, ItemStack stack, CallbackInfo ci) { - if (world instanceof ServerWorld serverWorld) { + @Inject(method = "dropItemStack(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/item/ItemStack;)V", at = @At("HEAD"), cancellable = true) + private static void preventSpawning(Level world, double x, double y, double z, ItemStack stack, CallbackInfo ci) { + if (world instanceof ServerLevel serverWorld) { //? if <=1.21.10 { - /*if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); - *///?} else { - if (!serverWorld.getGameRules().getValue(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); - //?} + if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + //?} else { + /*if (!serverWorld.getGameRules().get(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + *///?} } } } diff --git a/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java b/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java index 59803a3c..fff08a91 100644 --- a/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java +++ b/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java @@ -1,23 +1,30 @@ package tools.redstone.redstonetools.packets; -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.codec.PacketCodecs; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Identifier; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +//? if >=1.21.11 { +/*import net.minecraft.resources.Identifier; +*///? } else +import net.minecraft.resources.ResourceLocation; import tools.redstone.redstonetools.RedstoneTools; -public record SetFeatureEnabledPayload(String feature, boolean enabled) implements CustomPayload { - public static final Identifier SET_ENABLED_PAYLOAD_ID = Identifier.of(RedstoneTools.MOD_ID, "set_enabled"); - public static final CustomPayload.Id ID = new CustomPayload.Id<>(SET_ENABLED_PAYLOAD_ID); - public static final PacketCodec CODEC = PacketCodec.tuple( - PacketCodecs.STRING, SetFeatureEnabledPayload::feature, - PacketCodecs.BOOLEAN, SetFeatureEnabledPayload::enabled, +public record SetFeatureEnabledPayload(String feature, boolean enabled) implements CustomPacketPayload { + //? if >=1.21.11 { + /*public static final Identifier SET_ENABLED_PAYLOAD_ID = Identifier.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); + *///? } else + public static final ResourceLocation SET_ENABLED_PAYLOAD_ID = ResourceLocation.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); + + public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>(SET_ENABLED_PAYLOAD_ID); + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.STRING_UTF8, SetFeatureEnabledPayload::feature, + ByteBufCodecs.BOOL, SetFeatureEnabledPayload::enabled, SetFeatureEnabledPayload::new ); @Override - public CustomPayload.Id getId() { + public CustomPacketPayload.Type type() { return ID; } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/ArgumentUtils.java b/src/main/java/tools/redstone/redstonetools/utils/ArgumentUtils.java index 95d05188..34ade523 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ArgumentUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ArgumentUtils.java @@ -4,12 +4,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.command.CommandSource; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; - import java.util.Arrays; import java.util.stream.Stream; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; public class ArgumentUtils { public static final String[] BLOCK_COLOR_SUGGESTIONS = EnumUtils.lowercaseNames(BlockColor.values()); @@ -20,66 +19,66 @@ public class ArgumentUtils { public static final String[] COLORED_BLOCK_TYPE_SUGGESTIONS = EnumUtils.lowercaseNames(ColoredBlockType.values()); - public static final SuggestionProvider BLOCK_COLOR_SUGGESTION_PROVIDER = (context, builder) -> { + public static final SuggestionProvider BLOCK_COLOR_SUGGESTION_PROVIDER = (context, builder) -> { Stream names = Arrays.stream(BLOCK_COLOR_SUGGESTIONS); - CommandSource.suggestMatching(names, builder); + SharedSuggestionProvider.suggest(names, builder); return builder.buildFuture(); }; - public static final SuggestionProvider SIGNAL_BLOCK_SUGGESTION_PROVIDER = (context, builder) -> { + public static final SuggestionProvider SIGNAL_BLOCK_SUGGESTION_PROVIDER = (context, builder) -> { Stream names = Arrays.stream(SIGNAL_BLOCK_SUGGESTIONS); - CommandSource.suggestMatching(names, builder); + SharedSuggestionProvider.suggest(names, builder); return builder.buildFuture(); }; - public static final SuggestionProvider DIRECTION_SUGGESTION_PROVIDER = (context, builder) -> { + public static final SuggestionProvider DIRECTION_SUGGESTION_PROVIDER = (context, builder) -> { Stream names = Arrays.stream(DIRECTION_SUGGESTIONS); - CommandSource.suggestMatching(names, builder); + SharedSuggestionProvider.suggest(names, builder); return builder.buildFuture(); }; - public static final SuggestionProvider COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER = (context, builder) -> { + public static final SuggestionProvider COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER = (context, builder) -> { Stream names = Arrays.stream(COLORED_BLOCK_TYPE_SUGGESTIONS); - CommandSource.suggestMatching(names, builder); + SharedSuggestionProvider.suggest(names, builder); return builder.buildFuture(); }; - public static SignalBlock parseSignalBlock(CommandContext context, final String name) throws CommandSyntaxException { + public static SignalBlock parseSignalBlock(CommandContext context, final String name) throws CommandSyntaxException { String result = context.getArgument(name, String.class); SignalBlock signalBlock = EnumUtils.byNameOrNull(SignalBlock.values(), result); if (signalBlock == null) { - throw new SimpleCommandExceptionType(Text.literal("Could not resolve signal block!")).create(); + throw new SimpleCommandExceptionType(Component.literal("Could not resolve signal block!")).create(); } return signalBlock; } - public static BlockColor parseBlockColor(CommandContext context, final String name) throws CommandSyntaxException { + public static BlockColor parseBlockColor(CommandContext context, final String name) throws CommandSyntaxException { String result = context.getArgument(name, String.class); BlockColor color = EnumUtils.byNameOrNull(BlockColor.values(), result); if (color == null) { - throw new SimpleCommandExceptionType(Text.literal("Could not resolve block color!")).create(); + throw new SimpleCommandExceptionType(Component.literal("Could not resolve block color!")).create(); } return color; } - public static ColoredBlockType parseColoredBlockType(CommandContext context, final String name) throws CommandSyntaxException { + public static ColoredBlockType parseColoredBlockType(CommandContext context, final String name) throws CommandSyntaxException { String result = context.getArgument(name, String.class); ColoredBlockType blockType = EnumUtils.byNameOrNull(ColoredBlockType.values(), result); if (blockType == null) { - throw new SimpleCommandExceptionType(Text.literal("Could not resolve colored block type!")).create(); + throw new SimpleCommandExceptionType(Component.literal("Could not resolve colored block type!")).create(); } return blockType; } - public static DirectionArgument parseDirection(CommandContext context, final String name) throws CommandSyntaxException { + public static DirectionArgument parseDirection(CommandContext context, final String name) throws CommandSyntaxException { String result = context.getArgument(name, String.class); DirectionArgument direction = EnumUtils.byNameOrNull(DirectionArgument.values(), result); if (direction == null) { - throw new SimpleCommandExceptionType(Text.literal("Could not resolve direction!")).create(); + throw new SimpleCommandExceptionType(Component.literal("Could not resolve direction!")).create(); } return direction; } diff --git a/src/main/java/tools/redstone/redstonetools/utils/BlockColor.java b/src/main/java/tools/redstone/redstonetools/utils/BlockColor.java index 979478ec..ba246bdc 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/BlockColor.java +++ b/src/main/java/tools/redstone/redstonetools/utils/BlockColor.java @@ -1,8 +1,7 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; - import java.util.Arrays; +import net.minecraft.world.level.block.Block; public enum BlockColor { WHITE("white"), diff --git a/src/main/java/tools/redstone/redstonetools/utils/BlockInfo.java b/src/main/java/tools/redstone/redstonetools/utils/BlockInfo.java index dda4776c..1219562a 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/BlockInfo.java +++ b/src/main/java/tools/redstone/redstonetools/utils/BlockInfo.java @@ -1,9 +1,9 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; public class BlockInfo { public final Block block; diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java index 449a0b51..69c0d90d 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java @@ -1,12 +1,15 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; -import net.minecraft.registry.Registries; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.regex.Pattern; +import net.minecraft.core.registries.BuiltInRegistries; +//? if >=1.21.11 { +/*import net.minecraft.resources.Identifier; +*///? } else +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; public class ColoredBlock { private static final Pattern COLORED_BLOCK_REGEX = Pattern.compile( @@ -59,7 +62,7 @@ public String toBlockId() { } public static ColoredBlock fromBlock(@NotNull Block block) { - var blockId = Registries.BLOCK.getId(block).toString(); + var blockId = BuiltInRegistries.BLOCK.getKey(block).toString(); if (COLORED_BLOCK_CACHE.containsKey(blockId)) { return COLORED_BLOCK_CACHE.get(blockId); } @@ -75,7 +78,10 @@ public static ColoredBlock fromBlock(@NotNull Block block) { } public Block toBlock() { - return Registries.BLOCK.get(Identifier.tryParse(toBlockId())); + //? if >=1.21.11 { + /*return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); + *///? } else + return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java index ea739cd8..7413d8f4 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java @@ -1,8 +1,11 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; -import net.minecraft.registry.Registries; -import net.minecraft.util.Identifier; +import net.minecraft.core.registries.BuiltInRegistries; +//? if >=1.21.11 { +/*import net.minecraft.resources.Identifier; +*///? } else +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; public enum ColoredBlockType { // TODO: Merge some things with the ColoredBlock class so we don't have to repeat the formats and stuff @@ -34,6 +37,9 @@ public String toBlockId() { } public Block toBlock() { - return Registries.BLOCK.get(Identifier.tryParse(toBlockId())); + //? if >=1.21.11 { + /*return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); + *///? } else + return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java index d2f8b4b4..7472a878 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java @@ -1,70 +1,74 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.NbtComponent; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.*; -import net.minecraft.nbt.NbtCompound; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; public class ItemUtils { - public static BlockState getPlacementState(PlayerEntity player, ItemStack stack, float reach) { + public static BlockState getPlacementState(Player player, ItemStack stack, float reach) { Item type = stack.getItem(); if (!(type instanceof BlockItem blockItem)) return null; - return blockItem.getBlock().getPlacementState(new ItemPlacementContext( + return blockItem.getBlock().getStateForPlacement(new BlockPlaceContext( player, - player.getActiveHand(), + player.getUsedItemHand(), stack, RaycastUtils.rayCastFromEye(player, reach) )); } - public static BlockState getUseState(PlayerEntity player, ItemStack stack, float reach) { + public static BlockState getUseState(Player player, ItemStack stack, float reach) { if (stack == null || stack.getItem() == Items.AIR) return null; BlockState state = getPlacementState(player, stack, reach); if (state == null) - state = Blocks.BEDROCK.getDefaultState(); + state = Blocks.BEDROCK.defaultBlockState(); return state; } public static String getCommand(ItemStack stack) { - if (stack.contains(DataComponentTypes.CUSTOM_DATA)) { - NbtCompound data = getCustomData(stack); + if (stack.has(DataComponents.CUSTOM_DATA)) { + CompoundTag data = getCustomData(stack); //? if >=1.21.5 { - return data.getString("command", ""); - //?} else { - /*return data.getString("command"); - *///?} + /*return data.getStringOr("command", ""); + *///?} else { + return data.getString("command"); + //?} } return ""; } public static void setCommand(ItemStack stack, String command) { - NbtCompound data = new NbtCompound(); + CompoundTag data = new CompoundTag(); data.putString("command", command); - stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(data)); + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(data)); } public static boolean containsCommand(ItemStack stack) { - if (stack.contains(DataComponentTypes.CUSTOM_DATA)) { - NbtCompound data = getCustomData(stack); + if (stack.has(DataComponents.CUSTOM_DATA)) { + CompoundTag data = getCustomData(stack); return data.contains("command"); } return false; } public static void removeCommand(ItemStack stack) { - if (stack.contains(DataComponentTypes.CUSTOM_DATA)) { - NbtCompound data = getCustomData(stack); + if (stack.has(DataComponents.CUSTOM_DATA)) { + CompoundTag data = getCustomData(stack); data.remove("command"); - stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(data)); + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(data)); } } - private static NbtCompound getCustomData(ItemStack stack) { - return stack.get(DataComponentTypes.CUSTOM_DATA).copyNbt(); + private static CompoundTag getCustomData(ItemStack stack) { + return stack.get(DataComponents.CUSTOM_DATA).copyTag(); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java b/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java index 888c081e..ec25e793 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java @@ -1,14 +1,10 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.entity.Entity; -import net.minecraft.world.World; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; public class PlayerUtils { - public static World getWorld(Entity player) { - //? if <1.21.10 { - /*return player.getWorld(); - *///?} else { - return player.getEntityWorld(); - //?} + public static Level getWorld(Entity player) { + return player.level(); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/PositionUtils.java b/src/main/java/tools/redstone/redstonetools/utils/PositionUtils.java index 52350c3a..cdacfe1b 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/PositionUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/PositionUtils.java @@ -1,13 +1,13 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; public class PositionUtils { private PositionUtils() { } - public static Vec3d getBottomPositionOfBlock(BlockPos position) { - return Vec3d.ofCenter(position).subtract(0, 0.5, 0); + public static Vec3 getBottomPositionOfBlock(BlockPos position) { + return Vec3.atCenterOf(position).subtract(0, 0.5, 0); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java b/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java index c2875dc3..337893cc 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java @@ -1,27 +1,27 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.world.RaycastContext; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.phys.BlockHitResult; public class RaycastUtils { private RaycastUtils() { } public static BlockHitResult getBlockHitNeighbor(BlockHitResult hit) { - var sideOffset = hit.getSide().getUnitVector(); + var sideOffset = hit.getDirection().step(); - var newBlockPos = hit.getBlockPos().add((int) sideOffset.x, (int) sideOffset.y, (int) sideOffset.z); + var newBlockPos = hit.getBlockPos().offset((int) sideOffset.x, (int) sideOffset.y, (int) sideOffset.z); - return hit.withBlockPos(newBlockPos); + return hit.withPosition(newBlockPos); } - public static BlockHitResult rayCastFromEye(PlayerEntity player, float reach) { - return PlayerUtils.getWorld(player).raycast(new RaycastContext( - player.getEyePos(), - player.getEyePos().add(player.getRotationVector().multiply(reach)), - RaycastContext.ShapeType.COLLIDER, - RaycastContext.FluidHandling.NONE, + public static BlockHitResult rayCastFromEye(Player player, float reach) { + return PlayerUtils.getWorld(player).clip(new ClipContext( + player.getEyePosition(), + player.getEyePosition().add(player.getLookAngle().scale(reach)), + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, player )); } diff --git a/src/main/java/tools/redstone/redstonetools/utils/SignalBlock.java b/src/main/java/tools/redstone/redstonetools/utils/SignalBlock.java index f50652eb..ba62acbb 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/SignalBlock.java +++ b/src/main/java/tools/redstone/redstonetools/utils/SignalBlock.java @@ -1,10 +1,9 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; - import java.util.Locale; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; public enum SignalBlock { // cba to do composters. diff --git a/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java b/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java index f691167a..a8b2bcba 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java +++ b/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java @@ -1,18 +1,18 @@ package tools.redstone.redstonetools.utils; -import net.minecraft.block.Block; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.ContainerComponent; -import net.minecraft.component.type.NbtComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.MathHelper; +import net.minecraft.ChatFormatting; +import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.util.Mth; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.component.ItemContainerContents; +import net.minecraft.world.level.block.Block; @FunctionalInterface public interface SignalBlockSupplier { @@ -22,7 +22,7 @@ public interface SignalBlockSupplier { default ItemStack getItemStack(Block ignoredBlock, int signalStrength) { ItemStack item = this.createItem(signalStrength); setItemName(item, signalStrength); - item.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true); + item.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true); return item; } @@ -36,14 +36,14 @@ static SignalBlockSupplier container(int slots, Item containerType) { int itemsNeeded = getItemsNeeded(slots, signalStrength, item); ItemStack stack = new ItemStack(containerType); - DefaultedList inventoryItems = DefaultedList.ofSize(slots, ItemStack.EMPTY); + NonNullList inventoryItems = NonNullList.withSize(slots, ItemStack.EMPTY); for (int slot = 0, count = itemsNeeded; count > 0; slot++, count -= stackSize) { inventoryItems.set(slot, new ItemStack(item, Math.min(stackSize, count))); } - ContainerComponent containerComponent = ContainerComponent.fromStacks(inventoryItems); + ItemContainerContents containerComponent = ItemContainerContents.fromItems(inventoryItems); - stack.set(DataComponentTypes.CONTAINER, containerComponent); + stack.set(DataComponents.CONTAINER, containerComponent); return stack; }; @@ -52,13 +52,13 @@ static SignalBlockSupplier container(int slots, Item containerType) { private static int getItemsNeeded(int slots, int signalStrength, Item item) { int itemsNeeded = Math.max(0, signalStrength == 1 ? 1 - : (int) Math.ceil(slots * (signalStrength - 1) / 14D * item.getMaxCount())); + : (int) Math.ceil(slots * (signalStrength - 1) / 14D * item.getDefaultMaxStackSize())); // Check that the calculated number of items is correct. // This is to prevent problems with items that have a maximum stack size of 1 but stackSize > 1. // TODO: This can be improved by removing an item and adding stackable items up to the desired signal strength. // Even with the improvement, this will still fail for inventories with no available slots. - if (calculateComparatorOutput(itemsNeeded, slots, item.getMaxCount()) != signalStrength) + if (calculateComparatorOutput(itemsNeeded, slots, item.getDefaultMaxStackSize()) != signalStrength) throw new IllegalStateException("This signal strength cannot be achieved with the selected container"); return itemsNeeded; } @@ -70,12 +70,12 @@ static SignalBlockSupplier commandBlock() { ItemStack commandBlockStack = new ItemStack(Items.COMMAND_BLOCK); - NbtCompound blockEntityNbt = new NbtCompound(); + CompoundTag blockEntityNbt = new CompoundTag(); blockEntityNbt.putInt("SuccessCount", signalStrength); - NbtComponent blockEntityData = NbtComponent.of(blockEntityNbt); + CustomData blockEntityData = CustomData.of(blockEntityNbt); - commandBlockStack.set(DataComponentTypes.CUSTOM_DATA, blockEntityData); + commandBlockStack.set(DataComponents.CUSTOM_DATA, blockEntityData); return commandBlockStack; }; } @@ -86,7 +86,7 @@ private static boolean isInvalidSignalStrength(int signalStrength, int maxSignal private static int calculateComparatorOutput(int items, int slots, int item$getMaxCount) { float f = (float) items / (float) item$getMaxCount; - return MathHelper.floor(f / (float) slots * 14.0f) + (items > 0 ? 1 : 0); + return Mth.floor(f / (float) slots * 14.0f) + (items > 0 ? 1 : 0); } private static Item getBestItem(int signalStrength, int slots) { @@ -104,13 +104,13 @@ private static int getStackSize(int signalStrength, Item item) { else if (signalStrength > 15) return 64; else - return item.getMaxCount(); + return item.getDefaultMaxStackSize(); } private static void setItemName(ItemStack item, int signalStrength) { - MutableText text = Text.literal(String.valueOf(signalStrength)); - text.setStyle(text.getStyle().withColor(Formatting.RED)); - item.set(DataComponentTypes.CUSTOM_NAME, text); + MutableComponent text = Component.literal(String.valueOf(signalStrength)); + text.setStyle(text.getStyle().withColor(ChatFormatting.RED)); + item.set(DataComponents.CUSTOM_NAME, text); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java index 3b67941e..b79d92b1 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java @@ -6,11 +6,11 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.fabric.FabricAdapter; import com.sk89q.worldedit.regions.Region; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; public class WorldEditUtils { - public static Region getSelection(ServerPlayerEntity player) throws CommandSyntaxException { + public static Region getSelection(ServerPlayer player) throws CommandSyntaxException { if (!DependencyLookup.WORLDEDIT_PRESENT) { throw new IllegalStateException("WorldEdit is not loaded."); } @@ -26,7 +26,7 @@ public static Region getSelection(ServerPlayerEntity player) throws CommandSynta try { return localSession.getSelection(selectionWorld); } catch (IncompleteRegionException ex) { - throw new SimpleCommandExceptionType(Text.literal("Please make a selection with WorldEdit first")).create(); + throw new SimpleCommandExceptionType(Component.literal("Please make a selection with WorldEdit first")).create(); } } } diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 28337031..86e6267f 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -2,7 +2,7 @@ plugins { id("dev.kikugie.stonecutter") id("me.modmuss50.mod-publish-plugin") version "1.1.0" } -stonecutter.active("1.21.11") +stonecutter.active("1.21.4") version = "${project.property("mod_version")}+${stonecutter.current?.version}" From 0ca6ee354e33cd83770bf69a01e9e0d30ad27fdf Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sat, 30 May 2026 12:54:17 +0200 Subject: [PATCH 4/8] Mojang Mappings Time --- versions/1.21.10/gradle.properties | 1 - versions/1.21.11/gradle.properties | 1 - versions/1.21.4/gradle.properties | 1 - versions/1.21.5/gradle.properties | 1 - versions/1.21.8/gradle.properties | 1 - 5 files changed, 5 deletions(-) diff --git a/versions/1.21.10/gradle.properties b/versions/1.21.10/gradle.properties index 7928fcff..f7422a11 100644 --- a/versions/1.21.10/gradle.properties +++ b/versions/1.21.10/gradle.properties @@ -1,6 +1,5 @@ minecraft_version=1.21.10 minecraft_version_out=1.21.10 -yarn_mappings=1.21.10+build.3 fabric_version=0.138.4+1.21.10 malilib_version=1.21.10:0.26.8 diff --git a/versions/1.21.11/gradle.properties b/versions/1.21.11/gradle.properties index d6011f6a..ba0fccff 100644 --- a/versions/1.21.11/gradle.properties +++ b/versions/1.21.11/gradle.properties @@ -1,6 +1,5 @@ minecraft_version=1.21.11 minecraft_version_out=1.21.11 -yarn_mappings=1.21.11+build.4 fabric_version=0.141.2+1.21.11 malilib_version=1.21.11:0.27.7 diff --git a/versions/1.21.4/gradle.properties b/versions/1.21.4/gradle.properties index d86e2164..38553ad6 100644 --- a/versions/1.21.4/gradle.properties +++ b/versions/1.21.4/gradle.properties @@ -1,6 +1,5 @@ minecraft_version=1.21.4 minecraft_version_out=1.21.4 -yarn_mappings=1.21.4+build.8 fabric_version=0.119.4+1.21.4 malilib_version=1.21.4:0.23.5 diff --git a/versions/1.21.5/gradle.properties b/versions/1.21.5/gradle.properties index d280224d..258f48cc 100644 --- a/versions/1.21.5/gradle.properties +++ b/versions/1.21.5/gradle.properties @@ -1,6 +1,5 @@ minecraft_version=1.21.5 minecraft_version_out=1.21.5 -yarn_mappings=1.21.5+build.1 fabric_version=0.128.2+1.21.5 malilib_version=1.21.5:0.24.3 diff --git a/versions/1.21.8/gradle.properties b/versions/1.21.8/gradle.properties index e4f001bb..1a675783 100644 --- a/versions/1.21.8/gradle.properties +++ b/versions/1.21.8/gradle.properties @@ -1,6 +1,5 @@ minecraft_version=1.21.8 minecraft_version_out=1.21.8 -yarn_mappings=1.21.8+build.1 fabric_version=0.136.1+1.21.8 malilib_version=1.21.8:0.25.7 From 6e1146d13d2fee6c777ca89db8fa88dd67a84276 Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sat, 30 May 2026 14:49:31 +0200 Subject: [PATCH 5/8] 26.1 time! --- build.gradle.kts | 40 +++++-- gradle.properties | 4 + gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 20 ++-- .../redstonetools/ClientCommands.java | 12 +- .../redstonetools/config/MacroManager.java | 2 +- .../config/option/ConfigMacro.java | 4 +- .../features/toggleable/AirPlaceFeature.java | 50 ++++---- .../redstonetools/malilib/GuiMacroEditor.java | 12 +- .../malilib/widget/WidgetBaseWrapper.java | 22 ++-- .../widget/action/CommandListWidget.java | 110 +++++++++--------- .../features/TextFieldWidgetAccessor.java | 4 +- .../mixin/features/WorldRendererInvoker.java | 12 +- .../redstone/redstonetools/Commands.java | 12 +- .../redstonetools/RedstoneToolsGameRules.java | 8 +- .../features/commands/ColorCodeFeature.java | 11 +- .../features/commands/GiveMeFeature.java | 15 ++- .../features/commands/ItemBindFeature.java | 15 ++- .../commands/MinSelectionFeature.java | 5 +- .../features/commands/PickBlockFeature.java | 18 +-- .../features/commands/RStackFeature.java | 5 +- .../mixin/accessor/GiveCommandAccessor.java | 19 +++ .../mixin/features/AutoRotateMixin.java | 8 +- .../gamerules/DoContainerDropsMixin.java | 8 +- .../packets/RedstoneToolsPackets.java | 7 +- .../packets/SetFeatureEnabledPayload.java | 12 +- .../redstonetools/utils/ColoredBlock.java | 12 +- .../redstonetools/utils/ColoredBlockType.java | 12 +- .../redstonetools/utils/ItemUtils.java | 8 +- .../redstonetools/utils/WorldEditUtils.java | 5 +- src/main/resources/redstonetools.mixins.json | 1 + stonecutter.gradle.kts | 2 +- versions/26.1.2/gradle.properties | 7 ++ 33 files changed, 287 insertions(+), 197 deletions(-) create mode 100644 src/main/java/tools/redstone/redstonetools/mixin/accessor/GiveCommandAccessor.java create mode 100644 versions/26.1.2/gradle.properties diff --git a/build.gradle.kts b/build.gradle.kts index c9669e0f..bf7a2ee7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,14 @@ plugins { - id("fabric-loom") version "1.15-SNAPSHOT" id("maven-publish") id("me.modmuss50.mod-publish-plugin") version "1.1.0" + id("dev.kikugie.loom-back-compat") } version = "${project.property("mod_version")}+${stonecutter.current.version}" group = project.property("maven_group")!! +val lastTask: Task = (if (sc.current.parsed.matches("<26.1")) tasks.named("remapJar") else tasks.jar).get() + base { archivesName.set(project.property("archives_base_name") as String) } @@ -71,13 +73,21 @@ repositories { dependencies { minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") - mappings(loom.officialMojangMappings()) - modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") - modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") - modImplementation("fi.dy.masa.malilib:malilib-fabric-${project.property("malilib_version")}") - modImplementation("net.kr1v:malilib-api:${project.property("malilib_api_version")}") { - exclude(group = "net.fabricmc.fabric-api") // prevent 1.21.5 fabric api modules used by malilib from leaking into 1.21.4 + if (sc.current.parsed.matches("<26.1")) { + mappings(loom.officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") + modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") + modImplementation("fi.dy.masa.malilib:malilib-fabric-${project.property("malilib_version")}") + modImplementation("net.kr1v:malilib-api:${project.property("malilib_api_version")}") { + exclude(group = "net.fabricmc.fabric-api") // prevent 1.21.5 fabric api modules used by malilib from leaking into 1.21.4 + } + } else { + implementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") + implementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") + implementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") + implementation("fi.dy.masa.malilib:malilib-fabric-${project.property("malilib_version")}") + implementation("net.kr1v:malilib-api:${project.property("malilib_api_version")}") } annotationProcessor("net.kr1v:malilib-api-processor:1.0.0") } @@ -118,7 +128,7 @@ tasks.processResources { tasks.register("collectFile") { group = "build" - from(tasks.remapJar) + from(lastTask) into(rootProject.layout.buildDirectory.dir("libs/${project.property("mod_version")}")) } @@ -129,11 +139,17 @@ tasks.register("buildAndCollect") { tasks.withType().configureEach { options.encoding = "UTF-8" - options.release = 21 + if (sc.current.parsed.matches("<26.1")) + options.release = 21 + else + options.release = 25 } java { - toolchain.languageVersion = JavaLanguageVersion.of(21) + if (sc.current.parsed.matches("<26.1")) + toolchain.languageVersion = JavaLanguageVersion.of(21) + else + toolchain.languageVersion = JavaLanguageVersion.of(25) withSourcesJar() } @@ -156,7 +172,7 @@ publishing { } publishMods { - file.set(tasks.remapJar.get().archiveFile) + file.set((lastTask as AbstractArchiveTask).archiveFile) type.set(STABLE) modLoaders.add("fabric") diff --git a/gradle.properties b/gradle.properties index 2842bd09..7857aa93 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,3 +7,7 @@ archives_base_name = redstonetools loader_version=0.18.4 mod_version = 3.3.0 + +loomx.loom_version = 1.16-SNAPSHOT +loomx.loom_remap_plugin = net.fabricmc.fabric-loom-remap +loomx.loom_unobf_plugin = net.fabricmc.fabric-loom \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 23449a2b..dbc3ce4a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle.kts b/settings.gradle.kts index b144a456..ec06d301 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,35 +1,35 @@ pluginManagement { repositories { + maven { + url = uri("https://maven.fabricmc.net/") + } mavenCentral() gradlePluginPortal() - maven { - url = uri("https://maven.fabricmc.net/") - } maven { name = "KikuGie Snapshots" url = uri("https://maven.kikugie.dev/snapshots") } + + maven { + name = "KikuGie Releases" + url = uri("https://maven.kikugie.dev/releases") + } } } plugins { id("dev.kikugie.stonecutter") version "0.8.3" + id("dev.kikugie.loom-back-compat") version "0.3" } rootProject.name = "redstonetools-mod" -include("1.21.4") -include("1.21.5") -include("1.21.8") -include("1.21.10") -include("1.21.11") - stonecutter { centralScript = "build.gradle.kts" create(rootProject) { - versions("1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11") + versions("1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11", "26.1.2") vcsVersion = "1.21.11" } } diff --git a/src/client/java/tools/redstone/redstonetools/ClientCommands.java b/src/client/java/tools/redstone/redstonetools/ClientCommands.java index 8981f1c1..4c5b59da 100644 --- a/src/client/java/tools/redstone/redstonetools/ClientCommands.java +++ b/src/client/java/tools/redstone/redstonetools/ClientCommands.java @@ -4,10 +4,10 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.commands.CommandBuildContext; //? if >=1.21.11 { -/*import net.minecraft.commands.Commands; +import net.minecraft.commands.Commands; import net.minecraft.server.permissions.PermissionCheck; import net.minecraft.server.permissions.Permissions; -*///?} +//?} import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature; import tools.redstone.redstonetools.features.toggleable.BigDustFeature; @@ -18,10 +18,10 @@ public class ClientCommands { public static final Predicate PERMISSION_LEVEL_2 = //? if <=1.21.10 { - source -> source.getPlayer().hasPermissions(2); - //?} else { - /*Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); - *///?} + /*source -> source.getPlayer().hasPermissions(2); + *///?} else { + Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); + //?} public static void registerCommands(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { if (!DependencyLookup.REDSTONE_TOOLS_SERVER_PRESENT) { diff --git a/src/client/java/tools/redstone/redstonetools/config/MacroManager.java b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java index ffaaada0..ec8b4c25 100644 --- a/src/client/java/tools/redstone/redstonetools/config/MacroManager.java +++ b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java @@ -37,7 +37,7 @@ public static List getDefaultMacros() { "/gamerule doDaylightCycle false", "/gamerule doMobSpawning false", //? if <1.21.11 - "/gamerule doContainerDrops false", + //"/gamerule doContainerDrops false", "/time set noon", "/weather clear" }), diff --git a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java index 5f83135d..dae4adbf 100644 --- a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java +++ b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java @@ -114,8 +114,8 @@ public void resetToDefault() { static { MalilibApi.registerButtonBasedConfigType(ConfigMacro.class, (widgetConfigOption, configMacro, x, y, configWidth, configHeight) -> new ButtonGeneric(x, y, configWidth, configHeight, configMacro.getMacroName()) { @Override - protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*//*net.minecraft.client.input.MouseButtonEvent click, boolean doubleClick*//*? } else {*/int mouseX, int mouseY, int mouseButton/*? }*/) { - super.onMouseClickedImpl(/*? if >=1.21.10 {*//*click, doubleClick*//*? } else {*/mouseX, mouseY, mouseButton/*? }*/); + protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/net.minecraft.client.input.MouseButtonEvent click, boolean doubleClick/*? } else {*//*int mouseX, int mouseY, int mouseButton*//*? }*/) { + super.onMouseClickedImpl(/*? if >=1.21.10 {*/click, doubleClick/*? } else {*//*mouseX, mouseY, mouseButton*//*? }*/); GuiBase.openGui(new GuiMacroEditor(Component.nullToEmpty(configMacro.macroName), configMacro, Minecraft.getInstance().screen)); return true; } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 8a820d93..41c85750 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -4,20 +4,20 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; //? if <1.21.10 { -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +/*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; - //?} else { -/*import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; + *///?} else { +import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; -*///?} +//?} import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; //? if <=1.21.10 { -import net.minecraft.client.renderer.RenderType; -//? } else { -/*import net.minecraft.client.renderer.rendertype.RenderTypes; +/*import net.minecraft.client.renderer.RenderType; +*///? } else { +import net.minecraft.client.renderer.rendertype.RenderTypes; import net.minecraft.client.renderer.state.BlockOutlineRenderState; -*///? } +//? } //? if =1.21.10 //import net.minecraft.client.renderer.state.BlockOutlineRenderState; import net.minecraft.commands.CommandBuildContext; @@ -124,23 +124,23 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { Camera camera = client.gameRenderer.getMainCamera(); Vec3 camPos = camera //? if <=1.21.5 { - .getPosition(); - //? } else if <=1.21.10 { + /*.getPosition(); + *///? } else if <=1.21.10 { /*.position(); *///?} else { - /*.position(); - *///?} + .position(); + //?} VertexConsumer consumer = context.consumers().getBuffer( //? if <=1.21.10 { - RenderType.lines() - //?} else { - /*RenderTypes.lines() - *///?} + /*RenderType.lines() + *///?} else { + RenderTypes.lines() + //?} ); //? if <1.21.10 { - ((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( + /*((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( context.matrixStack(), consumer, client.player, @@ -149,8 +149,8 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { blockState, CommonColors.BLACK ); - //?} else { - /*((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( + *///?} else { + ((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( context.matrices(), consumer, camPos.x, camPos.y, camPos.z, @@ -160,18 +160,18 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { false, blockState.getShape(client.level, blockPos) ), - CommonColors.BLACK/^? if >=1.21.11 {^//^, client.getWindow().getAppropriateLineWidth()^//^?}^/ + CommonColors.BLACK/*? if >=1.21.11 {*/, client.getWindow().getAppropriateLineWidth()/*?}*/ ); - *///?} + //?} }; //? if <1.21.10 { - WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> { + /*WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> { listener.accept(context, hitResult); return true; }); - //?} else { - /*WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); - *///?} + *///?} else { + WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + //?} } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index 5371dcd1..6e5c1ca0 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -8,8 +8,8 @@ import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetKeybindSettings; //? if >=1.21.11 { -/*import fi.dy.masa.malilib.render.GuiContext; -*///?} +import fi.dy.masa.malilib.render.GuiContext; +//?} import fi.dy.masa.malilib.hotkeys.IKeybind; import fi.dy.masa.malilib.hotkeys.KeybindMulti; import kr1v.malilibApi.InternalMalilibApi; @@ -112,22 +112,22 @@ public void updateDisplayString() { } //? if <=1.21.8 { - @Override + /*@Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!this.buttonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { this.buttonKeybind.onClearSelection(); } return super.mouseClicked(mouseX, mouseY, button); } - //? } else { - /*@Override + *///? } else { + @Override public boolean mouseClicked(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) { if (!this.buttonKeybind.isMouseOver((int) click.x(), (int) click.y())) { this.buttonKeybind.onClearSelection(); } return super.mouseClicked(click, doubled); } - *///? } + //? } @Override public void onClose() { diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java index 1c536311..abea3b7c 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java @@ -3,17 +3,17 @@ import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetBase; //? if >=1.21.11 -//import fi.dy.masa.malilib.render.GuiContext; +import fi.dy.masa.malilib.render.GuiContext; import net.minecraft.client.gui.*; import net.minecraft.client.gui.components.Renderable; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.narration.NarrationElementOutput; //? if >=1.21.10 { -/*import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.CharacterEvent; import net.minecraft.client.input.KeyEvent; import net.minecraft.client.input.MouseButtonEvent; -*///? } +//? } import java.util.Collection; public class WidgetBaseWrapper implements GuiEventListener, Renderable, NarratableEntry { @@ -24,7 +24,7 @@ public WidgetBaseWrapper(WidgetBase wrapped) { } //? if <=1.21.8 { - @Override + /*@Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { if (configButtonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { @@ -57,8 +57,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { public boolean charTyped(char chr, int modifiers) { return wrapped.onCharTyped(chr, modifiers); } - //? } else { - /*@Override + *///? } else { + @Override public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { if (configButtonKeybind.isMouseOver((int) click.x(), (int) click.y())) { @@ -92,7 +92,7 @@ public boolean keyPressed(KeyEvent input) { if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) configButtonKeybind.onKeyPressed(input.input()); return wrapped.onKeyTyped(input); } - *///? } + //? } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { @@ -126,12 +126,12 @@ public boolean isFocused() { @Override public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { //? if <=1.21.5 { - wrapped.render(mouseX, mouseY, this.isFocused(), context); - //? } else if <=1.21.10 { + /*wrapped.render(mouseX, mouseY, this.isFocused(), context); + *///? } else if <=1.21.10 { /*wrapped.render(context, mouseX, mouseY, this.isFocused()); *///? } else { - /*wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); - *///? } + wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); + //? } } @Override diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index 62070e7d..20877f30 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -3,9 +3,9 @@ import fi.dy.masa.malilib.gui.button.ButtonBase; import fi.dy.masa.malilib.gui.button.ButtonGeneric; //? if >=1.21.11 { -/*import fi.dy.masa.malilib.render.GuiContext; +import fi.dy.masa.malilib.render.GuiContext; import net.minecraft.client.gui.navigation.ScreenRectangle; -*///? } +//? } import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ComponentPath; import net.minecraft.client.gui.GuiGraphics; @@ -17,10 +17,10 @@ import net.minecraft.client.gui.navigation.ScreenAxis; import net.minecraft.client.gui.navigation.ScreenDirection; //? if >=1.21.10 { -/*import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.CharacterEvent; import net.minecraft.client.input.KeyEvent; import net.minecraft.client.input.MouseButtonEvent; -*///? } +//? } import net.minecraft.client.renderer.Rect2i; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; @@ -30,8 +30,8 @@ import tools.redstone.redstonetools.mixin.features.ChatInputSuggestorAccessor; import tools.redstone.redstonetools.mixin.features.SuggestionWindowAccessor; //? if >=1.21.10 { -/*import tools.redstone.redstonetools.mixin.features.TextFieldWidgetAccessor; -*///?} +import tools.redstone.redstonetools.mixin.features.TextFieldWidgetAccessor; +//?} public class CommandListWidget extends AbstractSelectionList { @@ -64,7 +64,7 @@ public void setSelected(@Nullable CommandListWidget.CommandEntry entry) { return; } //? if >=1.21.10 - //((TextFieldWidgetAccessor) entry.commandWidget).getFormatters().clear(); + ((TextFieldWidgetAccessor) entry.commandWidget).getFormatters().clear(); this.commandSuggester = new CommandSuggestions( minecraft, this.parent, @@ -87,17 +87,17 @@ public void updateCommandInfo() { @Override public void renderUsage(GuiGraphics context) { //? if >=1.21.8 { - /*context.pose().pushMatrix(); - *///?} else - context.pose().pushPose(); + context.pose().pushMatrix(); + //?} else + //context.pose().pushPose(); var x = 0; var y = entry.commandWidget.getY() + 20 - 72; - context.pose().translate(x, y/*? if <1.21.8 {*/, 0/*?}*/); + context.pose().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); super.renderUsage(context); //? if >=1.21.8 { - /*context.pose().popMatrix(); - *///?} else - context.pose().popPose(); + context.pose().popMatrix(); + //?} else + //context.pose().popPose(); } }; this.commandSuggester.setAllowSuggestions(true); @@ -140,9 +140,9 @@ public void setScrollAmount(double scrollY) { } @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/double mouseX, double mouseY, int button/*$}*/) { - if (this.commandSuggester != null && this.commandSuggester.mouseClicked(/*? if <1.21.10 {*/mouseX, mouseY, button/*?} else {*//*click*//*?}*/)) return true; - return super.mouseClicked(/*$ mouse_clicked_args {*/mouseX, mouseY, button/*$}*/); + public boolean mouseClicked(/*$ mouse_clicked_params {*/MouseButtonEvent click, boolean doubleClick/*$}*/) { + if (this.commandSuggester != null && this.commandSuggester.mouseClicked(/*? if <1.21.10 {*//*mouseX, mouseY, button*//*?} else {*/click/*?}*/)) return true; + return super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); } @Override @@ -152,9 +152,9 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou } @Override - public boolean keyPressed(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { - if (this.commandSuggester != null && this.commandSuggester.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; - return super.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/); + public boolean keyPressed(/*$ keyinput_params {*/KeyEvent input/*$}*/) { + if (this.commandSuggester != null && this.commandSuggester.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; + return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); } @Override @@ -167,10 +167,10 @@ protected void renderListItems(GuiGraphics context, int mouseX, int mouseY, floa @Override //? if >=1.21.10 { - /*protected boolean entriesCanBeSelected() { - *///?} else { - protected boolean isSelectedItem(int index) { - //?} + protected boolean entriesCanBeSelected() { + //?} else { + /*protected boolean isSelectedItem(int index) { + *///?} return false; } @@ -184,9 +184,9 @@ public void addEntry() { CommandEntry entry = new CommandEntry(this.macro.getActions().getFirst()); this.addEntryToTop(entry); //? if <=1.21.8 { - this.centerScrollOn(this.getFirstElement()); - //? } else - //this.centerScrollOn(this.getFirst()); + /*this.centerScrollOn(this.getFirstElement()); + *///? } else + this.centerScrollOn(this.getFirst()); recalculateAllActionsPositions(); if (this.commandSuggester != null) { this.commandSuggester.updateCommandInfo(); @@ -200,17 +200,17 @@ private void recalculateAllActionsPositions() { entry.removeButton.setY(i + 6); entry.commandWidget.setY(i + 3); //? if <=1.21.8 { - i += this.itemHeight; - //? } else - //i += this.defaultEntryHeight; + /*i += this.itemHeight; + *///? } else + i += this.defaultEntryHeight; } } //? if >=1.21.10 { - /*private CommandEntry getFirst() { + private CommandEntry getFirst() { return this.children().getFirst(); } - *///?} + //?} @Override protected void updateWidgetNarration(NarrationElementOutput builder) { @@ -246,21 +246,21 @@ private void onCommandChanged(String text) { } @Override - public void /*? if <=1.21.8 {*/render/*? } else {*//*renderContent*//*? }*/(GuiGraphics context, /*? if <1.21.10 {*/ int index, int argY, int argX, int entryWidth, int entryHeight, /*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { + public void /*? if <=1.21.8 {*//*render*//*? } else {*/renderContent/*? }*/(GuiGraphics context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { commandWidget.render(context, mouseX, mouseY, tickProgress); //? if <=1.21.5 { - removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); - //?} else if <=1.21.10 { + /*removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); + *///?} else if <=1.21.10 { /*removeButton.render(context, mouseX, mouseY, removeButton.isMouseOver()); *///?} else { - /*GuiContext guiContext = GuiContext.fromGuiGraphics(context); + GuiContext guiContext = GuiContext.fromGuiGraphics(context); ScreenRectangle last = context.scissorStack.peek(); if (last != null) { guiContext.pushScissor(last); } removeButton.render(guiContext, mouseX, mouseY, removeButton.isMouseOver()); - *///?} + //?} } @Override @@ -276,48 +276,48 @@ public void mouseMoved(double mouseX, double mouseY) { } @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/double mouseX, double mouseY, int button/*$}*/) { - if (commandWidget.mouseClicked(/*$ mouse_clicked_args {*/mouseX, mouseY, button/*$}*/)) return true; - if (removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/(int) mouseX, (int) mouseY, button/*$}*/)) return true; + public boolean mouseClicked(/*$ mouse_clicked_params {*/MouseButtonEvent click, boolean doubleClick/*$}*/) { + if (commandWidget.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; + if (removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; return false; } @Override - public boolean mouseReleased(/*$ dragged_released_params {*/double mouseX, double mouseY, int button/*$}*/) { - removeButton.onMouseReleased(/*$ on_released_args {*/(int) mouseX, (int) mouseY, button/*$}*/); - return commandWidget.mouseReleased(/*$ dragged_released_args {*/mouseX, mouseY, button/*$}*/); + public boolean mouseReleased(/*$ dragged_released_params {*/MouseButtonEvent click/*$}*/) { + removeButton.onMouseReleased(/*$ on_released_args {*/click/*$}*/); + return commandWidget.mouseReleased(/*$ dragged_released_args {*/click/*$}*/); } @Override - public boolean mouseDragged(/*$ dragged_released_params {*/double mouseX, double mouseY, int button/*$}*/, double deltaX, double deltaY) { - return commandWidget.mouseDragged(/*$ dragged_released_args {*/mouseX, mouseY, button/*$}*/, deltaX, deltaY); + public boolean mouseDragged(/*$ dragged_released_params {*/MouseButtonEvent click/*$}*/, double deltaX, double deltaY) { + return commandWidget.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { if (commandWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true; - var x = /*? if <1.21.10 {*/(int)/*?}*/mouseX; - var y = /*? if <1.21.10 {*/(int)/*?}*/mouseY; + var x = /*? if <1.21.10 {*//*(int)*//*?}*/mouseX; + var y = /*? if <1.21.10 {*//*(int)*//*?}*/mouseY; if (removeButton.onMouseScrolled(x, y, horizontalAmount, verticalAmount)) return true; return false; } @Override - public boolean keyPressed(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { - if (commandWidget.keyPressed(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; - if (removeButton.onKeyTyped(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/)) return true; + public boolean keyPressed(/*$ keyinput_params {*/KeyEvent input/*$}*/) { + if (commandWidget.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; + if (removeButton.onKeyTyped(/*$ keyinput_args {*/input/*$}*/)) return true; return false; } @Override - public boolean keyReleased(/*$ keyinput_params {*/int keyCode, int scanCode, int modifiers/*$}*/) { - return commandWidget.keyReleased(/*$ keyinput_args {*/keyCode, scanCode, modifiers/*$}*/); + public boolean keyReleased(/*$ keyinput_params {*/KeyEvent input/*$}*/) { + return commandWidget.keyReleased(/*$ keyinput_args {*/input/*$}*/); } @Override - public boolean charTyped(/*$ charinput_params {*/char chr, int modifiers/*$}*/) { - if (commandWidget.charTyped(/*$ charinput_args {*/chr, modifiers/*$}*/)) return true; - if (removeButton.onCharTyped(/*$ charinput_args {*/chr, modifiers/*$}*/)) return true; + public boolean charTyped(/*$ charinput_params {*/CharacterEvent input/*$}*/) { + if (commandWidget.charTyped(/*$ charinput_args {*/input/*$}*/)) return true; + if (removeButton.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; return false; } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java index 6f6a4744..55f864f9 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java @@ -12,7 +12,7 @@ public interface TextFieldWidgetAccessor { void setTextDirectly(String s); //? if >=1.21.10 { - /*@Accessor + @Accessor List getFormatters(); - *///?} + //?} } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java index 440b9ba0..9c5291ab 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java @@ -3,7 +3,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.LevelRenderer; -//? if >=1.21.10 +//? if >=26.1.2 { +import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; +//? } else if >=1.21.10 //import net.minecraft.client.renderer.state.BlockOutlineRenderState; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; @@ -15,10 +17,10 @@ public interface WorldRendererInvoker { @Invoker //? if <=1.21.8 { - void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); - //?} else if <=1.21.10 { + /*void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); + *///?} else if <=1.21.10 { /*void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, BlockOutlineRenderState state, int color); *///?} else { - /*void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, BlockOutlineRenderState state, int color, float lineWidth); - *///?} + void invokeRenderHitOutline(PoseStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, BlockOutlineRenderState state, int color, float lineWidth); + //?} } \ No newline at end of file diff --git a/src/main/java/tools/redstone/redstonetools/Commands.java b/src/main/java/tools/redstone/redstonetools/Commands.java index 90f3ba05..16546c88 100644 --- a/src/main/java/tools/redstone/redstonetools/Commands.java +++ b/src/main/java/tools/redstone/redstonetools/Commands.java @@ -3,9 +3,9 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.commands.CommandSourceStack; //? if >=1.21.11 { -/*import net.minecraft.server.permissions.PermissionCheck; +import net.minecraft.server.permissions.PermissionCheck; import net.minecraft.server.permissions.Permissions; -*///? } +//? } import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.*; import tools.redstone.redstonetools.utils.DependencyLookup; @@ -15,10 +15,10 @@ public class Commands { public static final Predicate PERMISSION_LEVEL_2 = //? if <=1.21.10 { - source -> source.hasPermission(2); - //?} else { - /*net.minecraft.commands.Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); - *///?} + /*source -> source.hasPermission(2); + *///?} else { + net.minecraft.commands.Commands.hasPermission(new PermissionCheck.Require(Permissions.COMMANDS_GAMEMASTER)); + //?} public static void registerCommands() { CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> { diff --git a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java index aaa1ce2f..b6914460 100644 --- a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java +++ b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java @@ -1,7 +1,7 @@ package tools.redstone.redstonetools; //? if <=1.21.10 { -import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +/*import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; import net.minecraft.world.level.GameRules; @@ -20,8 +20,8 @@ public static void register() { // } } } -//?} else { -/*import com.mojang.brigadier.arguments.ArgumentType; +*///?} else { +import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.serialization.Codec; import net.minecraft.core.Registry; @@ -80,4 +80,4 @@ private static GameRule registerRule( ); } } -*///?} +//?} diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java index fc9420ce..82e74f77 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java @@ -82,11 +82,18 @@ protected int execute(CommandContext context) throws Command var worldEdit = WorldEdit.getInstance(); assert player != null; - var wePlayer = FabricAdapter.adaptPlayer(player); + + //? if <26.1 { + /*var wePlayer = FabricAdapter.adaptPlayer(player); + *///? } else + var wePlayer = FabricAdapter.get().fromNativePlayer(player); var playerSession = worldEdit.getSessionManager().get(wePlayer); // for each block in the selection - final World world = FabricAdapter.adapt(PlayerUtils.getWorld(player)); + //? if <26.1 { + /*final World world = FabricAdapter.adapt(PlayerUtils.getWorld(player)); + *///? } else + final World world = FabricAdapter.get().fromNativeWorld(PlayerUtils.getWorld(player)); try (EditSession session = worldEdit.newEditSession(world)) { // create mask and pattern and execute block set int blocksColored = session.replaceBlocks(selection, diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java index 8e8cb429..5632c360 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java @@ -11,6 +11,10 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.ItemStack; import tools.redstone.redstonetools.Commands; +import tools.redstone.redstonetools.mixin.accessor.GiveCommandAccessor; + +import java.util.List; +import java.util.Objects; import static net.minecraft.commands.Commands.argument; import static net.minecraft.commands.Commands.literal; @@ -38,11 +42,18 @@ public void registerCommand(CommandDispatcher dispatcher, Co } private int execute(CommandContext context, ItemInput itemArgument, int count) throws CommandSyntaxException { - MinecraftServer server = context.getSource().getServer(); - ItemStack stack = itemArgument.createItemStack(1, false); + //? if <26.1 { + /*MinecraftServer server = context.getSource().getServer(); + //? if <26.1 { + /^ItemStack stack = itemArgument.createItemStack(1, false); + ^///? } else + ItemStack stack = itemArgument.createItemStack(1); stack.setCount(count); server.getCommands().performPrefixedCommand( server.createCommandSourceStack(), "/give " + context.getSource().getTextName() + " " + itemArgument.serialize(server.registryAccess()) + " " + count); + *///? } else { + GiveCommandAccessor.invokeGiveItem(context.getSource(), itemArgument, List.of(Objects.requireNonNull(context.getSource().getPlayer())), count); + //? } return 0; } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java index 2b83db4e..92e1cf32 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java @@ -43,13 +43,19 @@ private static int executeReset(CommandContext context) { } else if (ItemUtils.containsCommand(player.getOffhandItem())) { mainhand = false; } else { - context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); + //? if <26.1 { + /*context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); + *///? } else + context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); return 0; } ItemStack stack = mainhand ? player.getMainHandItem() : player.getOffhandItem(); ItemUtils.removeCommand(stack); stack.set(DataComponents.LORE, stack.getItem().getDefaultInstance().get(DataComponents.LORE)); - context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); + //? if <26.1 { + /*context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); + *///? } else + context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); return 1; } @@ -81,7 +87,10 @@ public static void addCommand(String command, ServerPlayer playerI) { stack.set(DataComponents.LORE, new ItemLore(List.of(Component.nullToEmpty("Has command: /" + command)))); playersWaitingForCommand.remove(playerI); - playerI.displayClientMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); + //? if <26.1 { + /*playerI.displayClientMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); + *///? } else + playerI.sendSystemMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName(stack).getString())), false); } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java index 931d6eb5..ce60ed4a 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java @@ -40,7 +40,10 @@ protected int execute(CommandContext context) throws Command var selection = WorldEditUtils.getSelection(context.getSource().getPlayer()); var selectionWorld = selection.getWorld(); - var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + //? if <26.1 { + /*var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + *///? } else + var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java index 5e89d38c..f73d6e33 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/PickBlockFeature.java @@ -31,9 +31,9 @@ protected int execute(CommandContext context, BlockInfo bloc if (i != -1) { if (Inventory.isHotbarSlot(i)) { //? if <=1.21.4 { - playerInventory.setSelectedHotbarSlot(i); - //? } else -// playerInventory.setSelectedSlot(i); + /*playerInventory.setSelectedHotbarSlot(i); + *///? } else + playerInventory.setSelectedSlot(i); } else { playerInventory.pickSlot(i); } @@ -50,17 +50,17 @@ public void addPickBlock(Inventory pi, ItemStack stack) { int i = pi.findSlotMatchingItem(stack); if (Inventory.isHotbarSlot(i)) { //? if <=1.21.4 { - pi.setSelectedHotbarSlot(i); - //? } else -// pi.setSelectedSlot(i); + /*pi.setSelectedHotbarSlot(i); + *///? } else + pi.setSelectedSlot(i); return; } if (i == -1) { int j; //? if <=1.21.4 { - pi.setSelectedHotbarSlot(pi.getSuitableHotbarSlot()); - //? } else -// pi.setSelectedSlot(pi.getSuitableHotbarSlot()); + /*pi.setSelectedHotbarSlot(pi.getSuitableHotbarSlot()); + *///? } else + pi.setSelectedSlot(pi.getSuitableHotbarSlot()); if (!((PlayerInventoryAccessor)pi).getItems().get(((PlayerInventoryAccessor)pi).getSelected()).isEmpty() && (j = pi.getFreeSlot()) != -1) { ((PlayerInventoryAccessor)pi).getItems().set(j, ((PlayerInventoryAccessor)pi).getItems().get(((PlayerInventoryAccessor)pi).getSelected())); } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java index 976d2c55..a9ee5eb0 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java @@ -68,7 +68,10 @@ protected int execute(CommandContext context, int argCount) } protected int execute(CommandContext context, int count, int offset, DirectionArgument direction, boolean moveSelection) throws CommandSyntaxException { - var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + //? if <26.1 { + /*var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + *///? } else + var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/src/main/java/tools/redstone/redstonetools/mixin/accessor/GiveCommandAccessor.java b/src/main/java/tools/redstone/redstonetools/mixin/accessor/GiveCommandAccessor.java new file mode 100644 index 00000000..687db3cf --- /dev/null +++ b/src/main/java/tools/redstone/redstonetools/mixin/accessor/GiveCommandAccessor.java @@ -0,0 +1,19 @@ +package tools.redstone.redstonetools.mixin.accessor; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.item.ItemInput; +import net.minecraft.server.commands.GiveCommand; +import net.minecraft.server.level.ServerPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.Collection; + +@Mixin(GiveCommand.class) +public interface GiveCommandAccessor { + @Invoker + static int invokeGiveItem(final CommandSourceStack source, final ItemInput input, final Collection players, final int count) throws CommandSyntaxException { + throw new AssertionError(); + } +} diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java index b33b2c17..9f177094 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java @@ -22,11 +22,11 @@ public abstract class AutoRotateMixin { private BlockState changeRotation(BlockState original, @Local(argsOnly = true) BlockPlaceContext context) { if (!(context.getPlayer() instanceof ServerPlayer player)) return original; //? if <1.21.10 { - MinecraftServer server = player.getServer(); + /*MinecraftServer server = player.getServer(); if (server == null) return original; - //?} else { - /*MinecraftServer server = player.level().getServer(); - *///?} + *///?} else { + MinecraftServer server = player.level().getServer(); + //?} if (!server.isDedicatedServer()) return original; if (!AutoRotateFeature.INSTANCE.isEnabled(player)) return original; if (original == null) return null; diff --git a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java index c9f3b323..09c23760 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java @@ -16,10 +16,10 @@ public abstract class DoContainerDropsMixin { private static void preventSpawning(Level world, double x, double y, double z, ItemStack stack, CallbackInfo ci) { if (world instanceof ServerLevel serverWorld) { //? if <=1.21.10 { - if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); - //?} else { - /*if (!serverWorld.getGameRules().get(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); - *///?} + /*if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + *///?} else { + if (!serverWorld.getGameRules().get(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + //?} } } } diff --git a/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java b/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java index 05eb07ce..ef2faf25 100644 --- a/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java +++ b/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java @@ -8,8 +8,13 @@ public class RedstoneToolsPackets { public static void registerPackets() { - PayloadTypeRegistry.playS2C().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + //? if <26.1 { + /*PayloadTypeRegistry.playS2C().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); PayloadTypeRegistry.playC2S().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + *///? } else { + PayloadTypeRegistry.serverboundPlay().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + PayloadTypeRegistry.clientboundPlay().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + //? } ServerPlayNetworking.registerGlobalReceiver(SetFeatureEnabledPayload.ID, (payload, context) -> { String feature = payload.feature(); diff --git a/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java b/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java index fff08a91..2fd76aa1 100644 --- a/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java +++ b/src/main/java/tools/redstone/redstonetools/packets/SetFeatureEnabledPayload.java @@ -5,16 +5,16 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; //? if >=1.21.11 { -/*import net.minecraft.resources.Identifier; -*///? } else -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; +//? } else +//import net.minecraft.resources.ResourceLocation; import tools.redstone.redstonetools.RedstoneTools; public record SetFeatureEnabledPayload(String feature, boolean enabled) implements CustomPacketPayload { //? if >=1.21.11 { - /*public static final Identifier SET_ENABLED_PAYLOAD_ID = Identifier.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); - *///? } else - public static final ResourceLocation SET_ENABLED_PAYLOAD_ID = ResourceLocation.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); + public static final Identifier SET_ENABLED_PAYLOAD_ID = Identifier.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); + //? } else + //public static final ResourceLocation SET_ENABLED_PAYLOAD_ID = ResourceLocation.fromNamespaceAndPath(RedstoneTools.MOD_ID, "set_enabled"); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>(SET_ENABLED_PAYLOAD_ID); public static final StreamCodec CODEC = StreamCodec.composite( diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java index 69c0d90d..72010b35 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java @@ -6,9 +6,9 @@ import java.util.regex.Pattern; import net.minecraft.core.registries.BuiltInRegistries; //? if >=1.21.11 { -/*import net.minecraft.resources.Identifier; -*///? } else -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; +//? } else +//import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; public class ColoredBlock { @@ -79,9 +79,9 @@ public static ColoredBlock fromBlock(@NotNull Block block) { public Block toBlock() { //? if >=1.21.11 { - /*return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); - *///? } else - return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); + return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); + //? } else + //return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java index 7413d8f4..2c5e809e 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java @@ -2,9 +2,9 @@ import net.minecraft.core.registries.BuiltInRegistries; //? if >=1.21.11 { -/*import net.minecraft.resources.Identifier; -*///? } else -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; +//? } else +//import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; public enum ColoredBlockType { @@ -38,8 +38,8 @@ public String toBlockId() { public Block toBlock() { //? if >=1.21.11 { - /*return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); - *///? } else - return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); + return BuiltInRegistries.BLOCK.getValue(Identifier.tryParse(toBlockId())); + //? } else + //return BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(toBlockId())); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java index 7472a878..365c3540 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java @@ -38,10 +38,10 @@ public static String getCommand(ItemStack stack) { if (stack.has(DataComponents.CUSTOM_DATA)) { CompoundTag data = getCustomData(stack); //? if >=1.21.5 { - /*return data.getStringOr("command", ""); - *///?} else { - return data.getString("command"); - //?} + return data.getStringOr("command", ""); + //?} else { + /*return data.getString("command"); + *///?} } return ""; } diff --git a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java index b79d92b1..3968f1b9 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java @@ -15,7 +15,10 @@ public static Region getSelection(ServerPlayer player) throws CommandSyntaxExcep throw new IllegalStateException("WorldEdit is not loaded."); } - var actor = FabricAdapter.adaptPlayer(player); + //? if <26.1 { + /*var actor = FabricAdapter.adaptPlayer(player); + *///? } else + var actor = FabricAdapter.get().fromNativePlayer(player); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/src/main/resources/redstonetools.mixins.json b/src/main/resources/redstonetools.mixins.json index 74caf7de..b57c766a 100644 --- a/src/main/resources/redstonetools.mixins.json +++ b/src/main/resources/redstonetools.mixins.json @@ -8,6 +8,7 @@ }, "mixins": [ "AbstractBlockMixin", + "accessor.GiveCommandAccessor", "features.AutoDustMixin", "features.AutoRotateMixin", "features.CommandManagerMixin", diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 86e6267f..d6b7bffa 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -2,7 +2,7 @@ plugins { id("dev.kikugie.stonecutter") id("me.modmuss50.mod-publish-plugin") version "1.1.0" } -stonecutter.active("1.21.4") +stonecutter.active("26.1.2") version = "${project.property("mod_version")}+${stonecutter.current?.version}" diff --git a/versions/26.1.2/gradle.properties b/versions/26.1.2/gradle.properties new file mode 100644 index 00000000..6f6b11a2 --- /dev/null +++ b/versions/26.1.2/gradle.properties @@ -0,0 +1,7 @@ +minecraft_version=26.1.2 +minecraft_version_out=26.1.2 + +fabric_version=0.150.0+26.1.2 +malilib_version=26.1.2:0.28.6 +malilib_api_version=0.8.2-26.1 +worldedit_version=26.1.2:8.0.0-SNAPSHOT From b289dfbe1ed677069556560f2dcfd9e280cdd24a Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sat, 20 Jun 2026 19:55:07 +0200 Subject: [PATCH 6/8] 26.1 time! --- .../redstonetools/RedstoneToolsClient.java | 12 ++++- .../config/option/ConfigMacro.java | 10 +++- .../features/commands/BaseConvertClient.java | 14 ++++-- .../features/commands/ClientDataFeature.java | 7 ++- .../features/commands/EditMacroFeature.java | 8 +++- .../features/commands/GiveMeClient.java | 26 +++++++++-- .../features/commands/MacroFeature.java | 7 ++- .../features/commands/PrintFeature.java | 7 ++- .../features/commands/QuickTpClient.java | 7 ++- .../features/commands/ReachClient.java | 23 ++++++---- .../features/commands/RstFeature.java | 8 +++- .../features/toggleable/AirPlaceFeature.java | 46 ++++++++++++++----- .../features/toggleable/BigDustFeature.java | 7 ++- .../toggleable/ClientToggleableFeature.java | 10 +++- .../redstonetools/malilib/GuiMacroEditor.java | 17 ++++--- .../malilib/widget/WidgetBaseWrapper.java | 17 +++++-- .../widget/action/CommandListWidget.java | 36 ++++++++++++--- .../mixin/blocks/RedstoneHitboxMixin.java | 12 ----- .../mixin/features/ChatHudMixin.java | 12 ++++- .../mixin/features/SuggestionWindowMixin.java | 10 +++- src/main/resources/fabric.mod.json | 2 +- 21 files changed, 222 insertions(+), 76 deletions(-) diff --git a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java index 7b878077..1e8a4420 100644 --- a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java +++ b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java @@ -2,7 +2,11 @@ import kr1v.malilibApi.MalilibApi; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents; +//? if >=26.1 { +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; +//? } else { +/*import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents; +*///? } import tools.redstone.redstonetools.config.ClientData; import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets; @@ -16,7 +20,11 @@ public void onInitializeClient() { LOGGER.info("Initializing Redstone Tools"); MalilibApi.registerMod(MOD_ID, MOD_NAME); - ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { + //? if >=26.1 { + ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((client, clientWorld) -> { + //? } else { + /*ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { + *///? } if (client.getConnection() != null) { // dimension change String dimensionChange = ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue(); if (dimensionChange.startsWith("/")) { diff --git a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java index dae4adbf..a7ff7a86 100644 --- a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java +++ b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java @@ -182,7 +182,10 @@ public void run() { if (!enabled) return; if (layers.getAndSet(layers.get() + 1) > 100) { assert Minecraft.getInstance().player != null; - Minecraft.getInstance().player.displayClientMessage(Component.nullToEmpty("Please don't cause a stackoverflow :("), false); + //? if <26.1 { + /*Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); + *///? } else + Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); return; } try { @@ -192,7 +195,10 @@ public void run() { } catch (StackOverflowError ignored) { try { assert Minecraft.getInstance().player != null; - Minecraft.getInstance().player.displayClientMessage(Component.nullToEmpty("Please don't cause a stackoverflow :("), false); + //? if <26.1 { + /*Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); + *///? } else + Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); } catch (NoClassDefFoundError e) { // yeah we are absolutely cooked, there is no way to recover from this. I'm not even sure this can happen // actually there's probably a better throwable to be thrown here. whatever. diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java index fab331a1..852a3d2e 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java @@ -3,10 +3,16 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.commands.CommandBuildContext; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class BaseConvertClient { public static final BaseConvertClient INSTANCE = new BaseConvertClient(); @@ -15,9 +21,9 @@ protected BaseConvertClient() { } public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register( - ClientCommandManager.literal("base") - .then(ClientCommandManager.argument("inputNum", StringArgumentType.word()) - .then(ClientCommandManager.argument("toBase", IntegerArgumentType.integer(2, 16)) + literal("base") + .then(argument("inputNum", StringArgumentType.word()) + .then(argument("toBase", IntegerArgumentType.integer(2, 16)) .executes(context -> BaseConvertFeature.INSTANCE.execute( StringArgumentType.getString(context, "inputNum"), IntegerArgumentType.getInteger(context, "toBase"), diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java index 2eb6d099..ed2e5fae 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java @@ -9,8 +9,13 @@ import java.util.HashMap; import java.util.Map; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class ClientDataFeature { public Map variables = new HashMap<>(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java index 9bccdfdc..2882d1e7 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java @@ -3,13 +3,17 @@ import com.mojang.brigadier.CommandDispatcher; import kr1v.malilibApi.InternalMalilibApi; import kr1v.malilibApi.MalilibApi; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.Macros; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class EditMacroFeature { public static final EditMacroFeature INSTANCE = new EditMacroFeature(); @@ -18,7 +22,7 @@ protected EditMacroFeature() { } public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { - dispatcher.register(ClientCommandManager.literal("edit-macros") + dispatcher.register(literal("edit-macros") .executes(commandContext -> { Minecraft.getInstance().execute(() -> { InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(Macros.getTab()); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java index af6893f5..bc87e240 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java @@ -9,8 +9,13 @@ import net.minecraft.commands.arguments.item.ItemInput; import tools.redstone.redstonetools.ClientCommands; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } public class GiveMeClient { public static final GiveMeClient INSTANCE = new GiveMeClient(); @@ -27,7 +32,7 @@ public void registerCommand(CommandDispatcher dispatc context, registryAccess, ItemArgument.getItem(context, "item"), - 1)) + null)) .then(argument("count", IntegerArgumentType.integer(1)) .executes(context -> this.execute( context, @@ -36,9 +41,22 @@ public void registerCommand(CommandDispatcher dispatc IntegerArgumentType.getInteger(context, "count")))))); } - private int execute(CommandContext context, CommandBuildContext registryAccess, ItemInput itemArgument, int count) { + private int execute(CommandContext context, CommandBuildContext registryAccess, ItemInput itemArgument, Integer count) { + //? if <26.1 { + /*String itemString = itemArgument.serialize(registryAccess); + *///? } else { + String itemString; + if (count != null) { + itemString = context.getInput().substring(2, context.getInput().length() - 1 - Integer.toString(count).length()); + } else { + itemString = context.getInput().substring(2); + } + //? } + + if (count == null) count = 1; + context.getSource().getPlayer().connection.sendCommand( - "give @s " + itemArgument.serialize(registryAccess) + " " + count + "give @s " + itemString + " " + count ); return 0; } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java index c7d7daf5..5a07c000 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java @@ -8,8 +8,13 @@ import tools.redstone.redstonetools.config.option.ConfigMacro; import tools.redstone.redstonetools.features.commands.argument.MacroArgumentType; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } public class MacroFeature { public static final MacroFeature INSTANCE = new MacroFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java index f7b8d928..8baba5a3 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java @@ -6,8 +6,13 @@ import net.minecraft.commands.CommandBuildContext; import net.minecraft.network.chat.Component; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class PrintFeature { public static final PrintFeature INSTANCE = new PrintFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java index 41464c0c..85527699 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java @@ -7,8 +7,13 @@ import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.ClientCommands; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class QuickTpClient { public static final QuickTpClient INSTANCE = new QuickTpClient(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java index e584bfc5..41670ebd 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java @@ -3,13 +3,20 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.context.CommandContext; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.commands.CommandBuildContext; import net.minecraft.world.entity.ai.attributes.Attributes; import tools.redstone.redstonetools.ClientCommands; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } + public class ReachClient { public static final ReachClient INSTANCE = new ReachClient(); @@ -18,16 +25,16 @@ protected ReachClient() { } public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { - dispatcher.register(ClientCommandManager.literal("reach") + dispatcher.register(literal("reach") .requires(ClientCommands.PERMISSION_LEVEL_2) - .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(argument("reach", FloatArgumentType.floatArg(0.0f)) .executes(context -> execute(context, true, true)) ) - .then(ClientCommandManager.literal("reset") + .then(literal("reset") .executes(context -> reset(context, true, true)) ) - .then(ClientCommandManager.literal("block") - .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(literal("block") + .then(argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { builder.suggest(String.valueOf(Attributes.BLOCK_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); @@ -35,8 +42,8 @@ public void registerCommand(CommandDispatcher dispatc .executes(context -> execute(context, true, false)) ) ) - .then(ClientCommandManager.literal("entity") - .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) + .then(literal("entity") + .then(argument("reach", FloatArgumentType.floatArg(0.0f)) .suggests((context, builder) -> { builder.suggest(String.valueOf(Attributes.ENTITY_INTERACTION_RANGE.value().getDefaultValue())); return builder.buildFuture(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java index 56b72607..e677bbee 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java @@ -3,13 +3,17 @@ import com.mojang.brigadier.CommandDispatcher; import kr1v.malilibApi.InternalMalilibApi; import kr1v.malilibApi.MalilibApi; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.RedstoneTools; import tools.redstone.redstonetools.config.Macros; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class RstFeature { public static final RstFeature INSTANCE = new RstFeature(); @@ -18,7 +22,7 @@ protected RstFeature() { } public void registerCommand(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { - dispatcher.register(ClientCommandManager.literal("rst") + dispatcher.register(literal("rst") .executes(commandContext -> { Minecraft.getInstance().execute(() -> { if (InternalMalilibApi.getMod(RedstoneTools.MOD_ID).activeTab() == Macros.getTab()) { diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 41c85750..6a4e97c3 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -6,17 +6,23 @@ //? if <1.21.10 { /*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; - *///?} else { -import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; + *///?} else if <26.1 { +/*import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; -//?} +*///?} else { +import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents; +//? } import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; //? if <=1.21.10 { /*import net.minecraft.client.renderer.RenderType; *///? } else { import net.minecraft.client.renderer.rendertype.RenderTypes; -import net.minecraft.client.renderer.state.BlockOutlineRenderState; +//? if <26.1 { +/*import net.minecraft.client.renderer.state.BlockOutlineRenderState; +*///? } else +import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; //? } //? if =1.21.10 //import net.minecraft.client.renderer.state.BlockOutlineRenderState; @@ -42,7 +48,11 @@ import java.util.function.BiConsumer; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class AirPlaceFeature extends ClientToggleableFeature { public static final AirPlaceFeature INSTANCE = new AirPlaceFeature(); @@ -87,7 +97,10 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { { - BiConsumer listener = (context, crosshairTarget) -> { + //? if <26.1 { + /*BiConsumer listener = (context, crosshairTarget) -> { + *///? } else + BiConsumer listener = (context, crosshairTarget) -> { if (!isEnabled()) return; if (!General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) @@ -131,7 +144,10 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { .position(); //?} - VertexConsumer consumer = context.consumers().getBuffer( + //? if <26.1 { + /*VertexConsumer consumer = context.consumers().getBuffer( + *///? } else + VertexConsumer consumer = context.bufferSource().getBuffer( //? if <=1.21.10 { /*RenderType.lines() *///?} else { @@ -150,8 +166,14 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { CommonColors.BLACK ); *///?} else { - ((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( - context.matrices(), + //? if <26.1 { + /*((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( + *///? } else + ((WorldRendererInvoker) context.levelRenderer()).invokeRenderHitOutline( + //? if <26.1 { + /*context.matrices(), + *///? } else + context.poseStack(), consumer, camPos.x, camPos.y, camPos.z, new BlockOutlineRenderState( @@ -170,8 +192,10 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { listener.accept(context, hitResult); return true; }); + *///?} else if <26.1 { + /*WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); *///?} else { - WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); - //?} + LevelRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + //? } } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java index 56ff4a70..4f747289 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java @@ -6,8 +6,13 @@ import net.minecraft.commands.CommandBuildContext; import tools.redstone.redstonetools.config.Toggles; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +//? if >=26.1 { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +//? } else { +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +*///? } public class BigDustFeature extends ClientToggleableFeature { public static final BigDustFeature INSTANCE = new BigDustFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java index 593aa40d..2bb1348f 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java @@ -43,7 +43,10 @@ public void enable() { public int enable(FabricClientCommandSource source) throws CommandSyntaxException { enable(); - source.getPlayer().displayClientMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + //? if <26.1 { + /*source.getPlayer().displayClientMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + *///? } else + source.getPlayer().sendSystemMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); return 0; } @@ -54,7 +57,10 @@ public void disable() { public int disable(FabricClientCommandSource source) throws CommandSyntaxException { disable(); - source.getPlayer().displayClientMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + //? if <26.1 { + /*source.getPlayer().displayClientMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + *///? } else + source.getPlayer().sendSystemMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); return 0; } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index 6e5c1ca0..bd124212 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -7,14 +7,10 @@ import fi.dy.masa.malilib.gui.button.ConfigButtonBoolean; import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetKeybindSettings; -//? if >=1.21.11 { -import fi.dy.masa.malilib.render.GuiContext; -//?} import fi.dy.masa.malilib.hotkeys.IKeybind; import fi.dy.masa.malilib.hotkeys.KeybindMulti; import kr1v.malilibApi.InternalMalilibApi; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; @@ -54,10 +50,19 @@ public GuiMacroEditor(Component title, ConfigMacro macro, Screen parent) { } @Override - public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { + //? if <26.1 { + /*public void render(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { super.render(context, mouseX, mouseY, deltaTicks); + *///? } else { + public void extractRenderState(net.minecraft.client.gui.GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) { + super.extractRenderState(context, mouseX, mouseY, deltaTicks); + //? } if (errorCountDown > 0.0f) { - context.drawString(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + //? if <26.1 { + /*context.drawString(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + *///? } else { + context.text(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + //? } errorCountDown -= deltaTicks; } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java index abea3b7c..46d5d823 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java @@ -123,16 +123,23 @@ public boolean isFocused() { return false; } - @Override + //? if <26.1 { + /*@Override public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { //? if <=1.21.5 { - /*wrapped.render(mouseX, mouseY, this.isFocused(), context); - *///? } else if <=1.21.10 { - /*wrapped.render(context, mouseX, mouseY, this.isFocused()); - *///? } else { + /^wrapped.render(mouseX, mouseY, this.isFocused(), context); + ^///? } else if <=1.21.10 { + /^wrapped.render(context, mouseX, mouseY, this.isFocused()); + ^///? } else { wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); //? } } + *///? } else { + @Override + public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) { + wrapped.render(GuiContext.fromGuiGraphics(graphics), mouseX, mouseY, this.isFocused()); + } + //? } @Override public NarrationPriority narrationPriority() { diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index 20877f30..daf76433 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -8,7 +8,6 @@ //? } import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ComponentPath; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractSelectionList; import net.minecraft.client.gui.components.CommandSuggestions; import net.minecraft.client.gui.components.EditBox; @@ -85,7 +84,12 @@ public void updateCommandInfo() { } @Override - public void renderUsage(GuiGraphics context) { + //? if <26.1 { + /*public void renderUsage(net.minecraft.client.gui.GuiGraphics context) { + *///? } else { + public void extractUsage(net.minecraft.client.gui.GuiGraphicsExtractor context) { + + //? } //? if >=1.21.8 { context.pose().pushMatrix(); //?} else @@ -93,7 +97,11 @@ public void renderUsage(GuiGraphics context) { var x = 0; var y = entry.commandWidget.getY() + 20 - 72; context.pose().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); - super.renderUsage(context); + //? if <26.1 { + /*super.renderUsage(context); + *///? } else { + super.extractUsage(context); + //? } //? if >=1.21.8 { context.pose().popMatrix(); //?} else @@ -124,7 +132,7 @@ public void setScrollAmount(double scrollY) { if (!this.isFocused()) { return ComponentPath.leaf(this); } - if (!(navigation instanceof FocusNavigationEvent.ArrowNavigation(ScreenDirection navigationDirection))) { + if (!(navigation instanceof FocusNavigationEvent.ArrowNavigation(ScreenDirection navigationDirection/*? if >=26.1 {*/, ScreenRectangle previousFocus/*? }*/))) { return super.nextFocusPath(navigation); } if (navigationDirection.getAxis() == ScreenAxis.HORIZONTAL) { @@ -157,13 +165,23 @@ public boolean keyPressed(/*$ keyinput_params {*/KeyEvent input/*$}*/) { return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); } + //? if >=26.1 { @Override - protected void renderListItems(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { + protected void extractListItems(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) { + super.extractListItems(graphics, mouseX, mouseY, a); + if (this.commandSuggester != null) { + this.commandSuggester.extractRenderState(graphics, mouseX, mouseY); + } + } + //? } else { + /*@Override + protected void renderListItems(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { super.renderListItems(context, mouseX, mouseY, deltaTicks); if (this.commandSuggester != null) { this.commandSuggester.render(context, mouseX, mouseY); } } + *///? } @Override //? if >=1.21.10 { @@ -246,8 +264,12 @@ private void onCommandChanged(String text) { } @Override - public void /*? if <=1.21.8 {*//*render*//*? } else {*/renderContent/*? }*/(GuiGraphics context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { - commandWidget.render(context, mouseX, mouseY, tickProgress); + public void /*? if >=26.1 {*/extractContent/*? } else if <=1.21.8 {*//*render*//*? } else {*//*renderContent*//*? }*/(/*? if <26.1 {*//*net.minecraft.client.gui.GuiGraphics*//*? } else {*/net.minecraft.client.gui.GuiGraphicsExtractor/*? }*/ context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { + //? if <26.1 { + /*commandWidget.render(context, mouseX, mouseY, tickProgress); + *///? } else { + commandWidget.extractRenderState(context, mouseX, mouseY, tickProgress); + //? } //? if <=1.21.5 { /*removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); diff --git a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java index 97f97f7d..25d53f10 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java @@ -1,6 +1,5 @@ package tools.redstone.redstonetools.mixin.blocks; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; @@ -8,7 +7,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import org.lwjgl.util.tinyfd.TinyFileDialogs; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -25,16 +23,6 @@ public class RedstoneHitboxMixin { @Inject(method = "getShape", at = @At("HEAD"), cancellable = true) public void getOutlineShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context, CallbackInfoReturnable cir) { - if (!FabricLoader.getInstance().isModLoaded("malilib")) { - TinyFileDialogs.tinyfd_messageBox( - "Error", - "MaLiLib not present!\nPlease install MaLiLib if you want to use redstonetools", - "ok", - "error", - false - ); - throw new IllegalStateException("MaLiLib not present"); - } if (BigDustFeature.INSTANCE.isEnabled()) { cir.setReturnValue(SHAPES[General.BIGDUST_HEIGHT_IN_PIXELS.getIntegerValue()]); } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java index 986e0353..a68e306e 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java @@ -1,7 +1,10 @@ package tools.redstone.redstonetools.mixin.features; import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.multiplayer.chat.GuiMessageSource; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MessageSignature; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -10,8 +13,15 @@ @Mixin(ChatComponent.class) public class ChatHudMixin { - @Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), cancellable = true) + //? if >=26.1 { + @Inject(method = "addMessage", at = @At("HEAD"), cancellable = true) + private void injected(Component contents, MessageSignature signature, GuiMessageSource source, GuiMessageTag tag, CallbackInfo ci) { + if (MacroManager.shouldMute) ci.cancel(); + } + //? } else { + /*@Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), cancellable = true) private void injected(Component message, CallbackInfo ci) { if (MacroManager.shouldMute) ci.cancel(); } + *///? } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java index 40a2a2a7..b1f89d1d 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java @@ -13,11 +13,17 @@ public class SuggestionWindowMixin { @Shadow @Final - CommandSuggestions field_21615; + //? if <26.1 { + /*CommandSuggestions field_21615; + *///? } else + CommandSuggestions this$0; @WrapMethod(method = "useSuggestion") private void expandVariablesToo(Operation original) { - EditBox textField = ((ChatInputSuggestorAccessor) this.field_21615).getInput(); + //? if <26.1 { + /*EditBox textField = ((ChatInputSuggestorAccessor) this.field_21615).getInput(); + *///? } else + EditBox textField = ((ChatInputSuggestorAccessor) this.this$0).getInput(); String beforeComplete = textField.getValue(); original.call(); if (StringUtils.expand(beforeComplete, textField.getValue()).equals(textField.getValue())) return; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f3a1bfc5..569983a9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,7 +37,7 @@ "depends": { "fabricloader": ">=0.18.1", "fabric-api": "*", - "minecraft": ">=1.21.4 <=1.21.11" + "minecraft": ">=1.21.4 <=26.1.2" }, "recommends": { "worldedit": "*", From 1dd3c618d1f4b1b728a5d90f7577743010a6e0c8 Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sat, 20 Jun 2026 20:52:32 +0200 Subject: [PATCH 7/8] 26.1 time! --- gradle.properties | 2 +- .../redstonetools/RedstoneToolsClient.java | 16 ++--- .../config/option/ConfigMacro.java | 12 ++-- .../features/commands/BaseConvertClient.java | 8 +-- .../features/commands/ClientDataFeature.java | 8 +-- .../features/commands/EditMacroFeature.java | 8 +-- .../features/commands/GiveMeClient.java | 16 ++--- .../features/commands/MacroFeature.java | 8 +-- .../features/commands/PrintFeature.java | 8 +-- .../features/commands/QuickTpClient.java | 8 +-- .../features/commands/ReachClient.java | 8 +-- .../features/commands/RstFeature.java | 8 +-- .../features/toggleable/AirPlaceFeature.java | 65 +++++++++++-------- .../features/toggleable/BigDustFeature.java | 8 +-- .../toggleable/ClientToggleableFeature.java | 12 ++-- .../redstonetools/malilib/GuiMacroEditor.java | 16 ++--- .../malilib/widget/WidgetBaseWrapper.java | 16 ++--- .../widget/action/CommandListWidget.java | 36 +++++----- .../mixin/features/ChatHudMixin.java | 13 ++-- .../mixin/features/SuggestionWindowMixin.java | 12 ++-- .../mixin/features/WorldRendererInvoker.java | 6 +- .../features/commands/ColorCodeFeature.java | 12 ++-- .../features/commands/GiveMeFeature.java | 14 ++-- .../features/commands/ItemBindFeature.java | 18 ++--- .../commands/MinSelectionFeature.java | 6 +- .../features/commands/RStackFeature.java | 6 +- .../packets/RedstoneToolsPackets.java | 8 +-- .../redstonetools/utils/WorldEditUtils.java | 6 +- stonecutter.gradle.kts | 2 +- 29 files changed, 187 insertions(+), 179 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7857aa93..885427a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ maven_group = tools.redstone archives_base_name = redstonetools loader_version=0.18.4 -mod_version = 3.3.0 +mod_version = 3.4.0 loomx.loom_version = 1.16-SNAPSHOT loomx.loom_remap_plugin = net.fabricmc.fabric-loom-remap diff --git a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java index 1e8a4420..550a4b93 100644 --- a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java +++ b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java @@ -3,10 +3,10 @@ import kr1v.malilibApi.MalilibApi; import net.fabricmc.api.ClientModInitializer; //? if >=26.1 { -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; -//? } else { -/*import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents; -*///? } +/*import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; +*///? } else { +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents; +//? } import tools.redstone.redstonetools.config.ClientData; import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets; @@ -21,10 +21,10 @@ public void onInitializeClient() { MalilibApi.registerMod(MOD_ID, MOD_NAME); //? if >=26.1 { - ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((client, clientWorld) -> { - //? } else { - /*ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { - *///? } + /*ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((client, clientWorld) -> { + *///? } else { + ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { + //? } if (client.getConnection() != null) { // dimension change String dimensionChange = ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue(); if (dimensionChange.startsWith("/")) { diff --git a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java index a7ff7a86..2ffa8a11 100644 --- a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java +++ b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java @@ -183,9 +183,9 @@ public void run() { if (layers.getAndSet(layers.get() + 1) > 100) { assert Minecraft.getInstance().player != null; //? if <26.1 { - /*Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); - *///? } else - Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); + Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); + //? } else + //Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); return; } try { @@ -196,9 +196,9 @@ public void run() { try { assert Minecraft.getInstance().player != null; //? if <26.1 { - /*Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); - *///? } else - Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); + Minecraft.getInstance().player.displayClientMessage(Component.literal("Please don't cause a stackoverflow :("), false); + //? } else + //Minecraft.getInstance().player.sendSystemMessage(Component.literal("Please don't cause a stackoverflow :(")); } catch (NoClassDefFoundError e) { // yeah we are absolutely cooked, there is no way to recover from this. I'm not even sure this can happen // actually there's probably a better throwable to be thrown here. whatever. diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java index 852a3d2e..6615f27f 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertClient.java @@ -7,12 +7,12 @@ import net.minecraft.commands.CommandBuildContext; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class BaseConvertClient { public static final BaseConvertClient INSTANCE = new BaseConvertClient(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java index ed2e5fae..24d8b3e7 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ClientDataFeature.java @@ -10,12 +10,12 @@ import java.util.Map; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class ClientDataFeature { public Map variables = new HashMap<>(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java index 2882d1e7..4b375a47 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java @@ -10,10 +10,10 @@ import tools.redstone.redstonetools.config.Macros; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +//? } public class EditMacroFeature { public static final EditMacroFeature INSTANCE = new EditMacroFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java index bc87e240..be4d97bb 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java @@ -10,12 +10,12 @@ import tools.redstone.redstonetools.ClientCommands; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class GiveMeClient { public static final GiveMeClient INSTANCE = new GiveMeClient(); @@ -43,15 +43,15 @@ public void registerCommand(CommandDispatcher dispatc private int execute(CommandContext context, CommandBuildContext registryAccess, ItemInput itemArgument, Integer count) { //? if <26.1 { - /*String itemString = itemArgument.serialize(registryAccess); - *///? } else { - String itemString; + String itemString = itemArgument.serialize(registryAccess); + //? } else { + /*String itemString; if (count != null) { itemString = context.getInput().substring(2, context.getInput().length() - 1 - Integer.toString(count).length()); } else { itemString = context.getInput().substring(2); } - //? } + *///? } if (count == null) count = 1; diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java index 5a07c000..44d1b795 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java @@ -9,12 +9,12 @@ import tools.redstone.redstonetools.features.commands.argument.MacroArgumentType; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class MacroFeature { public static final MacroFeature INSTANCE = new MacroFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java index 8baba5a3..fa563285 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/PrintFeature.java @@ -7,12 +7,12 @@ import net.minecraft.network.chat.Component; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class PrintFeature { public static final PrintFeature INSTANCE = new PrintFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java index 85527699..3e36a552 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java @@ -8,12 +8,12 @@ import tools.redstone.redstonetools.ClientCommands; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class QuickTpClient { public static final QuickTpClient INSTANCE = new QuickTpClient(); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java index 41670ebd..8e3c31d9 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java @@ -10,12 +10,12 @@ import tools.redstone.redstonetools.ClientCommands; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class ReachClient { diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java index e677bbee..5d7ef23e 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java @@ -10,10 +10,10 @@ import tools.redstone.redstonetools.config.Macros; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +//? } public class RstFeature { public static final RstFeature INSTANCE = new RstFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 6a4e97c3..48be91f5 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -7,12 +7,12 @@ /*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; *///?} else if <26.1 { -/*import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; -*///?} else { -import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderContext; +//?} else { +/*import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents; -//? } +*///? } import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; //? if <=1.21.10 { @@ -20,9 +20,9 @@ *///? } else { import net.minecraft.client.renderer.rendertype.RenderTypes; //? if <26.1 { -/*import net.minecraft.client.renderer.state.BlockOutlineRenderState; -*///? } else -import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; +import net.minecraft.client.renderer.state.BlockOutlineRenderState; +//? } else +//import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; //? } //? if =1.21.10 //import net.minecraft.client.renderer.state.BlockOutlineRenderState; @@ -39,6 +39,7 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; import tools.redstone.redstonetools.ClientCommands; import tools.redstone.redstonetools.config.General; import tools.redstone.redstonetools.config.Toggles; @@ -49,10 +50,10 @@ import java.util.function.BiConsumer; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +//? } public class AirPlaceFeature extends ClientToggleableFeature { public static final AirPlaceFeature INSTANCE = new AirPlaceFeature(); @@ -98,9 +99,9 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { { //? if <26.1 { - /*BiConsumer listener = (context, crosshairTarget) -> { - *///? } else - BiConsumer listener = (context, crosshairTarget) -> { + BiConsumer listener = (context, crosshairTarget) -> { + //? } else + //BiConsumer listener = (context, crosshairTarget) -> { if (!isEnabled()) return; if (!General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) @@ -145,9 +146,9 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { //?} //? if <26.1 { - /*VertexConsumer consumer = context.consumers().getBuffer( - *///? } else - VertexConsumer consumer = context.bufferSource().getBuffer( + VertexConsumer consumer = context.consumers().getBuffer( + //? } else + //VertexConsumer consumer = context.bufferSource().getBuffer( //? if <=1.21.10 { /*RenderType.lines() *///?} else { @@ -167,21 +168,31 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { ); *///?} else { //? if <26.1 { - /*((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( - *///? } else - ((WorldRendererInvoker) context.levelRenderer()).invokeRenderHitOutline( + ((WorldRendererInvoker) context.worldRenderer()).invokeRenderHitOutline( + //? } else + //((WorldRendererInvoker) context.levelRenderer()).invokeRenderHitOutline( //? if <26.1 { - /*context.matrices(), - *///? } else - context.poseStack(), + context.matrices(), + //? } else + //context.poseStack(), consumer, camPos.x, camPos.y, camPos.z, + //? if <26.1 { new BlockOutlineRenderState( blockPos, false, false, blockState.getShape(client.level, blockPos) ), + //? } else { + /*// tODO: bug here i cannot figure it out bwaaaaaaaaaaaaaaa + new BlockOutlineRenderState( + blockPos, + false, + false, + blockState.getShape(client.level, blockPos, CollisionContext.of(camera.entity())) + ), + *///? } CommonColors.BLACK/*? if >=1.21.11 {*/, client.getWindow().getAppropriateLineWidth()/*?}*/ ); //?} @@ -193,9 +204,9 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { return true; }); *///?} else if <26.1 { - /*WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); - *///?} else { - LevelRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); - //? } + WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + //?} else { + /*LevelRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + *///? } } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java index 4f747289..11e771d0 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java @@ -7,12 +7,12 @@ import tools.redstone.redstonetools.config.Toggles; //? if >=26.1 { -import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; +/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; -//? } else { -/*import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +*///? } else { +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; -*///? } +//? } public class BigDustFeature extends ClientToggleableFeature { public static final BigDustFeature INSTANCE = new BigDustFeature(); diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java index 2bb1348f..f2478845 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClientToggleableFeature.java @@ -44,9 +44,9 @@ public void enable() { public int enable(FabricClientCommandSource source) throws CommandSyntaxException { enable(); //? if <26.1 { - /*source.getPlayer().displayClientMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); - *///? } else - source.getPlayer().sendSystemMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); + source.getPlayer().displayClientMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + //? } else + //source.getPlayer().sendSystemMessage(Component.literal("Enabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); return 0; } @@ -58,9 +58,9 @@ public void disable() { public int disable(FabricClientCommandSource source) throws CommandSyntaxException { disable(); //? if <26.1 { - /*source.getPlayer().displayClientMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); - *///? } else - source.getPlayer().sendSystemMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); + source.getPlayer().displayClientMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", ""))), false); + //? } else + //source.getPlayer().sendSystemMessage(Component.literal("Disabled %s".formatted(this.getClass().getSimpleName().replace("Feature", "")))); return 0; } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index bd124212..ce602e51 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -51,18 +51,18 @@ public GuiMacroEditor(Component title, ConfigMacro macro, Screen parent) { @Override //? if <26.1 { - /*public void render(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { + public void render(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { super.render(context, mouseX, mouseY, deltaTicks); - *///? } else { - public void extractRenderState(net.minecraft.client.gui.GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) { + //? } else { + /*public void extractRenderState(net.minecraft.client.gui.GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) { super.extractRenderState(context, mouseX, mouseY, deltaTicks); - //? } + *///? } if (errorCountDown > 0.0f) { //? if <26.1 { - /*context.drawString(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); - *///? } else { - context.text(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); - //? } + context.drawString(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + //? } else { + /*context.text(this.font, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); + *///? } errorCountDown -= deltaTicks; } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java index 46d5d823..0d051509 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java @@ -124,22 +124,22 @@ public boolean isFocused() { } //? if <26.1 { - /*@Override + @Override public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { //? if <=1.21.5 { - /^wrapped.render(mouseX, mouseY, this.isFocused(), context); - ^///? } else if <=1.21.10 { - /^wrapped.render(context, mouseX, mouseY, this.isFocused()); - ^///? } else { + /*wrapped.render(mouseX, mouseY, this.isFocused(), context); + *///? } else if <=1.21.10 { + /*wrapped.render(context, mouseX, mouseY, this.isFocused()); + *///? } else { wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); //? } } - *///? } else { - @Override + //? } else { + /*@Override public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) { wrapped.render(GuiContext.fromGuiGraphics(graphics), mouseX, mouseY, this.isFocused()); } - //? } + *///? } @Override public NarrationPriority narrationPriority() { diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index daf76433..060c9206 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -85,11 +85,11 @@ public void updateCommandInfo() { @Override //? if <26.1 { - /*public void renderUsage(net.minecraft.client.gui.GuiGraphics context) { - *///? } else { - public void extractUsage(net.minecraft.client.gui.GuiGraphicsExtractor context) { + public void renderUsage(net.minecraft.client.gui.GuiGraphics context) { + //? } else { + /*public void extractUsage(net.minecraft.client.gui.GuiGraphicsExtractor context) { - //? } + *///? } //? if >=1.21.8 { context.pose().pushMatrix(); //?} else @@ -98,10 +98,10 @@ public void extractUsage(net.minecraft.client.gui.GuiGraphicsExtractor context) var y = entry.commandWidget.getY() + 20 - 72; context.pose().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); //? if <26.1 { - /*super.renderUsage(context); - *///? } else { - super.extractUsage(context); - //? } + super.renderUsage(context); + //? } else { + /*super.extractUsage(context); + *///? } //? if >=1.21.8 { context.pose().popMatrix(); //?} else @@ -132,7 +132,7 @@ public void setScrollAmount(double scrollY) { if (!this.isFocused()) { return ComponentPath.leaf(this); } - if (!(navigation instanceof FocusNavigationEvent.ArrowNavigation(ScreenDirection navigationDirection/*? if >=26.1 {*/, ScreenRectangle previousFocus/*? }*/))) { + if (!(navigation instanceof FocusNavigationEvent.ArrowNavigation(ScreenDirection navigationDirection/*? if >=26.1 {*//*, ScreenRectangle previousFocus*//*? }*/))) { return super.nextFocusPath(navigation); } if (navigationDirection.getAxis() == ScreenAxis.HORIZONTAL) { @@ -166,22 +166,22 @@ public boolean keyPressed(/*$ keyinput_params {*/KeyEvent input/*$}*/) { } //? if >=26.1 { - @Override + /*@Override protected void extractListItems(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) { super.extractListItems(graphics, mouseX, mouseY, a); if (this.commandSuggester != null) { this.commandSuggester.extractRenderState(graphics, mouseX, mouseY); } } - //? } else { - /*@Override + *///? } else { + @Override protected void renderListItems(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float deltaTicks) { super.renderListItems(context, mouseX, mouseY, deltaTicks); if (this.commandSuggester != null) { this.commandSuggester.render(context, mouseX, mouseY); } } - *///? } + //? } @Override //? if >=1.21.10 { @@ -264,12 +264,12 @@ private void onCommandChanged(String text) { } @Override - public void /*? if >=26.1 {*/extractContent/*? } else if <=1.21.8 {*//*render*//*? } else {*//*renderContent*//*? }*/(/*? if <26.1 {*//*net.minecraft.client.gui.GuiGraphics*//*? } else {*/net.minecraft.client.gui.GuiGraphicsExtractor/*? }*/ context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { + public void /*? if >=26.1 {*//*extractContent*//*? } else if <=1.21.8 {*//*render*//*? } else {*/renderContent/*? }*/(/*? if <26.1 {*/net.minecraft.client.gui.GuiGraphics/*? } else {*//*net.minecraft.client.gui.GuiGraphicsExtractor*//*? }*/ context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { //? if <26.1 { - /*commandWidget.render(context, mouseX, mouseY, tickProgress); - *///? } else { - commandWidget.extractRenderState(context, mouseX, mouseY, tickProgress); - //? } + commandWidget.render(context, mouseX, mouseY, tickProgress); + //? } else { + /*commandWidget.extractRenderState(context, mouseX, mouseY, tickProgress); + *///? } //? if <=1.21.5 { /*removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java index a68e306e..cb60d4b4 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java @@ -1,10 +1,7 @@ package tools.redstone.redstonetools.mixin.features; import net.minecraft.client.gui.components.ChatComponent; -import net.minecraft.client.multiplayer.chat.GuiMessageSource; -import net.minecraft.client.multiplayer.chat.GuiMessageTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MessageSignature; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,14 +11,14 @@ @Mixin(ChatComponent.class) public class ChatHudMixin { //? if >=26.1 { - @Inject(method = "addMessage", at = @At("HEAD"), cancellable = true) - private void injected(Component contents, MessageSignature signature, GuiMessageSource source, GuiMessageTag tag, CallbackInfo ci) { + /*@Inject(method = "addMessage", at = @At("HEAD"), cancellable = true) + private void injected(Component contents, net.minecraft.network.chat.MessageSignature signature, net.minecraft.client.multiplayer.chat.GuiMessageSource source, net.minecraft.client.multiplayer.chat.GuiMessageTag tag, CallbackInfo ci) { if (MacroManager.shouldMute) ci.cancel(); } - //? } else { - /*@Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), cancellable = true) + *///? } else { + @Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), cancellable = true) private void injected(Component message, CallbackInfo ci) { if (MacroManager.shouldMute) ci.cancel(); } - *///? } + //? } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java index b1f89d1d..79d133ec 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java @@ -14,16 +14,16 @@ public class SuggestionWindowMixin { @Shadow @Final //? if <26.1 { - /*CommandSuggestions field_21615; - *///? } else - CommandSuggestions this$0; + CommandSuggestions field_21615; + //? } else + //CommandSuggestions this$0; @WrapMethod(method = "useSuggestion") private void expandVariablesToo(Operation original) { //? if <26.1 { - /*EditBox textField = ((ChatInputSuggestorAccessor) this.field_21615).getInput(); - *///? } else - EditBox textField = ((ChatInputSuggestorAccessor) this.this$0).getInput(); + EditBox textField = ((ChatInputSuggestorAccessor) this.field_21615).getInput(); + //? } else + //EditBox textField = ((ChatInputSuggestorAccessor) this.this$0).getInput(); String beforeComplete = textField.getValue(); original.call(); if (StringUtils.expand(beforeComplete, textField.getValue()).equals(textField.getValue())) return; diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java index 9c5291ab..5efd3ac7 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java @@ -4,9 +4,9 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.LevelRenderer; //? if >=26.1.2 { -import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; -//? } else if >=1.21.10 -//import net.minecraft.client.renderer.state.BlockOutlineRenderState; +/*import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; +*///? } else if >=1.21.10 +import net.minecraft.client.renderer.state.BlockOutlineRenderState; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.block.state.BlockState; diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java index 82e74f77..f6fc2078 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java @@ -84,16 +84,16 @@ protected int execute(CommandContext context) throws Command assert player != null; //? if <26.1 { - /*var wePlayer = FabricAdapter.adaptPlayer(player); - *///? } else - var wePlayer = FabricAdapter.get().fromNativePlayer(player); + var wePlayer = FabricAdapter.adaptPlayer(player); + //? } else + //var wePlayer = FabricAdapter.get().fromNativePlayer(player); var playerSession = worldEdit.getSessionManager().get(wePlayer); // for each block in the selection //? if <26.1 { - /*final World world = FabricAdapter.adapt(PlayerUtils.getWorld(player)); - *///? } else - final World world = FabricAdapter.get().fromNativeWorld(PlayerUtils.getWorld(player)); + final World world = FabricAdapter.adapt(PlayerUtils.getWorld(player)); + //? } else + //final World world = FabricAdapter.get().fromNativeWorld(PlayerUtils.getWorld(player)); try (EditSession session = worldEdit.newEditSession(world)) { // create mask and pattern and execute block set int blocksColored = session.replaceBlocks(selection, diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java index 5632c360..5c91bf67 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java @@ -43,17 +43,17 @@ public void registerCommand(CommandDispatcher dispatcher, Co private int execute(CommandContext context, ItemInput itemArgument, int count) throws CommandSyntaxException { //? if <26.1 { - /*MinecraftServer server = context.getSource().getServer(); + MinecraftServer server = context.getSource().getServer(); //? if <26.1 { - /^ItemStack stack = itemArgument.createItemStack(1, false); - ^///? } else - ItemStack stack = itemArgument.createItemStack(1); + ItemStack stack = itemArgument.createItemStack(1, false); + //? } else + //ItemStack stack = itemArgument.createItemStack(1); stack.setCount(count); server.getCommands().performPrefixedCommand( server.createCommandSourceStack(), "/give " + context.getSource().getTextName() + " " + itemArgument.serialize(server.registryAccess()) + " " + count); - *///? } else { - GiveCommandAccessor.invokeGiveItem(context.getSource(), itemArgument, List.of(Objects.requireNonNull(context.getSource().getPlayer())), count); - //? } + //? } else { + /*GiveCommandAccessor.invokeGiveItem(context.getSource(), itemArgument, List.of(Objects.requireNonNull(context.getSource().getPlayer())), count); + *///? } return 0; } } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java index 92e1cf32..3148badf 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java @@ -44,18 +44,18 @@ private static int executeReset(CommandContext context) { mainhand = false; } else { //? if <26.1 { - /*context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); - *///? } else - context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); + context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); + //? } else + //context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("You need to be holding an item with a command in one of your hands!"), false); return 0; } ItemStack stack = mainhand ? player.getMainHandItem() : player.getOffhandItem(); ItemUtils.removeCommand(stack); stack.set(DataComponents.LORE, stack.getItem().getDefaultInstance().get(DataComponents.LORE)); //? if <26.1 { - /*context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); - *///? } else - context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); + context.getSource().getPlayer().displayClientMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); + //? } else + //context.getSource().getPlayer().sendSystemMessage(Component.nullToEmpty("Successfully removed command from the item in your " + (mainhand ? "mainhand" : "offhand")), false); return 1; } @@ -88,9 +88,9 @@ public static void addCommand(String command, ServerPlayer playerI) { playersWaitingForCommand.remove(playerI); //? if <26.1 { - /*playerI.displayClientMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); - *///? } else - playerI.sendSystemMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName(stack).getString())), false); + playerI.displayClientMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName().getString())), false); + //? } else + //playerI.sendSystemMessage(Component.literal("Successfully bound command: '/%s' to this item (%s)!".formatted(command, stack.getItem().getName(stack).getString())), false); } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java index ce60ed4a..3642492d 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java @@ -41,9 +41,9 @@ protected int execute(CommandContext context) throws Command var selectionWorld = selection.getWorld(); //? if <26.1 { - /*var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); - *///? } else - var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); + var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + //? } else + //var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java index a9ee5eb0..be11bf86 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java @@ -69,9 +69,9 @@ protected int execute(CommandContext context, int argCount) protected int execute(CommandContext context, int count, int offset, DirectionArgument direction, boolean moveSelection) throws CommandSyntaxException { //? if <26.1 { - /*var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); - *///? } else - var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); + var actor = FabricAdapter.adaptPlayer(Objects.requireNonNull(context.getSource().getPlayer())); + //? } else + //var actor = FabricAdapter.get().fromNativePlayer(Objects.requireNonNull(context.getSource().getPlayer())); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java b/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java index ef2faf25..57051d12 100644 --- a/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java +++ b/src/main/java/tools/redstone/redstonetools/packets/RedstoneToolsPackets.java @@ -9,12 +9,12 @@ public class RedstoneToolsPackets { public static void registerPackets() { //? if <26.1 { - /*PayloadTypeRegistry.playS2C().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + PayloadTypeRegistry.playS2C().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); PayloadTypeRegistry.playC2S().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); - *///? } else { - PayloadTypeRegistry.serverboundPlay().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); + //? } else { + /*PayloadTypeRegistry.serverboundPlay().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); PayloadTypeRegistry.clientboundPlay().register(SetFeatureEnabledPayload.ID, SetFeatureEnabledPayload.CODEC); - //? } + *///? } ServerPlayNetworking.registerGlobalReceiver(SetFeatureEnabledPayload.ID, (payload, context) -> { String feature = payload.feature(); diff --git a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java index 3968f1b9..88ffa636 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java @@ -16,9 +16,9 @@ public static Region getSelection(ServerPlayer player) throws CommandSyntaxExcep } //? if <26.1 { - /*var actor = FabricAdapter.adaptPlayer(player); - *///? } else - var actor = FabricAdapter.get().fromNativePlayer(player); + var actor = FabricAdapter.adaptPlayer(player); + //? } else + //var actor = FabricAdapter.get().fromNativePlayer(player); var localSession = WorldEdit.getInstance() .getSessionManager() diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index d6b7bffa..28337031 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -2,7 +2,7 @@ plugins { id("dev.kikugie.stonecutter") id("me.modmuss50.mod-publish-plugin") version "1.1.0" } -stonecutter.active("26.1.2") +stonecutter.active("1.21.11") version = "${project.property("mod_version")}+${stonecutter.current?.version}" From b21724dd91bfece3836887fc6fc1ca3e664acddd Mon Sep 17 00:00:00 2001 From: kr1viah Date: Sun, 21 Jun 2026 18:54:11 +0200 Subject: [PATCH 8/8] Fix buge --- .../features/toggleable/AirPlaceFeature.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 48be91f5..f75dde5f 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -39,7 +39,6 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.CollisionContext; import tools.redstone.redstonetools.ClientCommands; import tools.redstone.redstonetools.config.General; import tools.redstone.redstonetools.config.Toggles; @@ -185,12 +184,11 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { blockState.getShape(client.level, blockPos) ), //? } else { - /*// tODO: bug here i cannot figure it out bwaaaaaaaaaaaaaaa - new BlockOutlineRenderState( + /*new BlockOutlineRenderState( blockPos, false, false, - blockState.getShape(client.level, blockPos, CollisionContext.of(camera.entity())) + blockState.getShape(client.level, blockPos, net.minecraft.world.phys.shapes.CollisionContext.of(camera.entity())) ), *///? } CommonColors.BLACK/*? if >=1.21.11 {*/, client.getWindow().getAppropriateLineWidth()/*?}*/ @@ -206,7 +204,7 @@ public static BlockHitResult findAirPlaceBlockHit(Player playerEntity) { *///?} else if <26.1 { WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); //?} else { - /*LevelRenderEvents.END_MAIN.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); + /*LevelRenderEvents.BEFORE_GIZMOS.register(context -> listener.accept(context, Minecraft.getInstance().hitResult)); *///? } } }