From 4675583e1c4fb8e7a02b82ae9d0c4b2171abebaf Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 21 Mar 2024 21:45:17 +0000 Subject: [PATCH] STOP DOING MIXINS (on Forge) BYTECODE WAS NOT SUPPOSED TO BE REWRITTEN YEARS OF DEBUGGING REMAPPING FAILURES yet NO ACTUAL SOLUTION FOUND. Wanted to use Mixins for anyway for a laugh? We had a tool for that: it was called "FABRIC LOOM". "Yes, please produce completely broken jars for no discernable reason" Statements dreamed up by the utterly Deranged. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This removes our two mixins used on Forge: - Breaking progress for cabled/wired modems. - Running client commands from chat click events. We now suggest the command on Forge instead. Occasionally we get issues where the mixin annotation processor doesn't write its tsrg file in time for the reobfJar/reobfJarJar task. I thought we'd fixed that cb8e06af2aefd931b1f6743849a7afb2a25ea0bd, but sometimes we still produce missing jars - I have a feeling this might be to do with incremental compilation. We can maybe re-evaluate this on 1.20.4, where we don't need to worry about remapping any more. --- .../cc-tweaked.java-convention.gradle.kts | 4 -- gradle/libs.versions.toml | 2 - .../shared/command/CommandComputerCraft.java | 2 +- .../shared/command/text/ChatHelpers.java | 8 +++ .../shared/platform/PlatformHelper.java | 9 +++ projects/forge/build.gradle.kts | 19 ------ .../client/BlockRenderDispatcherMixin.java | 66 ------------------- .../client/ClientPacketListenerMixin.java | 26 -------- .../computercraft-client.forge.mixins.json | 14 ---- .../shared/platform/PlatformHelperImpl.java | 5 ++ 10 files changed, 23 insertions(+), 132 deletions(-) delete mode 100644 projects/forge/src/client/java/dan200/computercraft/mixin/client/BlockRenderDispatcherMixin.java delete mode 100644 projects/forge/src/client/java/dan200/computercraft/mixin/client/ClientPacketListenerMixin.java delete mode 100644 projects/forge/src/client/resources/computercraft-client.forge.mixins.json diff --git a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts index ab037b14e6..84029760b3 100644 --- a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts @@ -40,10 +40,6 @@ repositories { val mainMaven = maven("https://squiddev.cc/maven") { name = "SquidDev" - content { - // Until https://github.com/SpongePowered/Mixin/pull/593 is merged - includeModule("org.spongepowered", "mixin") - } } exclusiveContent { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c0b18581ae..f108cea40a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -68,7 +68,6 @@ illuaminate = "0.1.0-69-gf294ab2" librarian = "1.+" lwjgl = "3.3.3" minotaur = "2.+" -mixinGradle = "0.7.38" nullAway = "0.9.9" spotless = "6.23.3" taskTree = "2.1.1" @@ -171,7 +170,6 @@ githubRelease = { id = "com.github.breadmoirai.github-release", version.ref = "g gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" } kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } librarian = { id = "org.parchmentmc.librarian.forgegradle", version.ref = "librarian" } -mixinGradle = { id = "org.spongepowered.mixin", version.ref = "mixinGradle" } taskTree = { id = "com.dorongold.task-tree", version.ref = "taskTree" } versionCatalogUpdate = { id = "nl.littlerobots.version-catalog-update", version.ref = "versionCatalogUpdate" } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java b/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java index 85c95f73d2..de1d5a5f33 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java @@ -385,7 +385,7 @@ private static Component linkPosition(CommandSourceStack context, ServerComputer var file = new File(ServerContext.get(source.getServer()).storageDir().toFile(), "computer/" + id); if (!file.isDirectory()) return null; - return link( + return clientLink( text("\u270E"), "/" + CLIENT_OPEN_FOLDER + " " + id, Component.translatable("commands.computercraft.dump.open_path") diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/text/ChatHelpers.java b/projects/common/src/main/java/dan200/computercraft/shared/command/text/ChatHelpers.java index a3a7434698..8496548754 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/text/ChatHelpers.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/text/ChatHelpers.java @@ -5,6 +5,7 @@ package dan200.computercraft.shared.command.text; import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.platform.PlatformHelper; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.ClickEvent; @@ -54,6 +55,13 @@ public static Component link(MutableComponent component, String command, Compone return link(component, new ClickEvent(ClickEvent.Action.RUN_COMMAND, command), toolTip); } + public static Component clientLink(MutableComponent component, String command, Component toolTip) { + var event = PlatformHelper.get().canClickRunClientCommand() + ? new ClickEvent(ClickEvent.Action.RUN_COMMAND, command) + : new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command); + return link(component, event, toolTip); + } + public static Component link(Component component, ClickEvent click, Component toolTip) { var style = component.getStyle(); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java b/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java index 8ed71f6da0..883a47b396 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java @@ -389,4 +389,13 @@ default double getReachDistance(Player player) { * @see ServerPlayerGameMode#useItemOn(ServerPlayer, Level, ItemStack, InteractionHand, BlockHitResult) */ InteractionResult useOn(ServerPlayer player, ItemStack stack, BlockHitResult hit, Predicate canUseBlock); + + /** + * Whether {@link net.minecraft.network.chat.ClickEvent.Action#RUN_COMMAND} can be used to run client commands. + * + * @return Whether client commands can be triggered from chat components. + */ + default boolean canClickRunClientCommand() { + return true; + } } diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 8561d6c2a9..e99035a5c4 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -8,7 +8,6 @@ import net.minecraftforge.gradle.common.util.RunConfig plugins { id("cc-tweaked.forge") id("cc-tweaked.gametest") - alias(libs.plugins.mixinGradle) id("cc-tweaked.mod-publishing") } @@ -103,12 +102,6 @@ minecraft { } } -mixin { - add(sourceSets.client.get(), "client-computercraft.refmap.json") - - config("computercraft-client.forge.mixins.json") -} - configurations { minecraftLibrary { extendsFrom(minecraftEmbed.get()) } @@ -121,9 +114,6 @@ configurations { } dependencies { - annotationProcessor("org.spongepowered:mixin:0.8.5-SQUID:processor") - clientAnnotationProcessor("org.spongepowered:mixin:0.8.5-SQUID:processor") - compileOnly(libs.jetbrainsAnnotations) annotationProcessorEverywhere(libs.autoService) @@ -246,15 +236,6 @@ modPublishing { output.set(tasks.jarJar) } -// Make sure configureReobfTaskForReobfJarJar runs after compilation -// see - https://github.com/SpongePowered/MixinGradle/pull/51 -tasks.configureEach { - when (name) { - "configureReobfTaskForReobfJar" -> mustRunAfter(tasks.jar) - "configureReobfTaskForReobfJarJar" -> mustRunAfter(tasks.jarJar) - } -} - // Don't publish the slim jar for (cfg in listOf(configurations.apiElements, configurations.runtimeElements)) { cfg.configure { artifacts.removeIf { it.classifier == "slim" } } diff --git a/projects/forge/src/client/java/dan200/computercraft/mixin/client/BlockRenderDispatcherMixin.java b/projects/forge/src/client/java/dan200/computercraft/mixin/client/BlockRenderDispatcherMixin.java deleted file mode 100644 index 2263a0a2ef..0000000000 --- a/projects/forge/src/client/java/dan200/computercraft/mixin/client/BlockRenderDispatcherMixin.java +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.mixin.client; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; -import dan200.computercraft.client.ClientHooks; -import net.minecraft.client.renderer.block.BlockModelShaper; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.block.ModelBlockRenderer; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.core.BlockPos; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Provides custom block breaking progress for modems, so it only applies to the current part. - * - * @see BlockRenderDispatcher#renderBreakingTexture(BlockState, BlockPos, BlockAndTintGetter, PoseStack, VertexConsumer, ModelData) - */ -@Mixin(BlockRenderDispatcher.class) -public class BlockRenderDispatcherMixin { - @Shadow - @Final - private RandomSource random; - - @Shadow - @Final - private BlockModelShaper blockModelShaper; - - @Shadow - @Final - private ModelBlockRenderer modelRenderer; - - @Inject( - method = "name=/^renderBreakingTexture/ desc=/ModelData;\\)V$/", - at = @At("HEAD"), - cancellable = true, - require = 0 // This isn't critical functionality, so don't worry if we can't apply it. - ) - public void renderBlockDamage( - BlockState state, BlockPos pos, BlockAndTintGetter world, PoseStack pose, VertexConsumer buffers, ModelData modelData, - CallbackInfo info - ) { - var newState = ClientHooks.getBlockBreakingState(state, pos); - if (newState != null) { - info.cancel(); - - var model = blockModelShaper.getBlockModel(newState); - modelRenderer.tesselateBlock( - world, model, newState, pos, pose, buffers, true, random, newState.getSeed(pos), - OverlayTexture.NO_OVERLAY, modelData, null - ); - } - } -} diff --git a/projects/forge/src/client/java/dan200/computercraft/mixin/client/ClientPacketListenerMixin.java b/projects/forge/src/client/java/dan200/computercraft/mixin/client/ClientPacketListenerMixin.java deleted file mode 100644 index dd5ecb11b1..0000000000 --- a/projects/forge/src/client/java/dan200/computercraft/mixin/client/ClientPacketListenerMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.mixin.client; - -import dan200.computercraft.shared.command.CommandComputerCraft; -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraftforge.client.ClientCommandHandler; -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.CallbackInfoReturnable; - -/** - * Allows triggering ComputerCraft's client commands from chat components events. - */ -@Mixin(ClientPacketListener.class) -class ClientPacketListenerMixin { - @Inject(method = "sendUnsignedCommand", at = @At("HEAD"), cancellable = true) - void commandUnsigned(String command, CallbackInfoReturnable ci) { - if (command.startsWith(CommandComputerCraft.CLIENT_OPEN_FOLDER) && ClientCommandHandler.runCommand(command)) { - ci.setReturnValue(true); - } - } -} diff --git a/projects/forge/src/client/resources/computercraft-client.forge.mixins.json b/projects/forge/src/client/resources/computercraft-client.forge.mixins.json deleted file mode 100644 index b80be74ac5..0000000000 --- a/projects/forge/src/client/resources/computercraft-client.forge.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "package": "dan200.computercraft.mixin.client", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "injectors": { - "defaultRequire": 1 - }, - "client": [ - "BlockRenderDispatcherMixin", - "ClientPacketListenerMixin" - ], - "refmap": "client-computercraft.refmap.json" -} diff --git a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java index 63bc643044..698c5ce4f9 100644 --- a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java +++ b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java @@ -345,6 +345,11 @@ public InteractionResult useOn(ServerPlayer player, ItemStack stack, BlockHitRes return event.getUseItem() == Event.Result.DENY ? InteractionResult.PASS : stack.useOn(context); } + @Override + public boolean canClickRunClientCommand() { + return false; + } + private record RegistryWrapperImpl( ResourceLocation name, ForgeRegistry registry ) implements RegistryWrappers.RegistryWrapper {