From 98cb70ab422ebfe9d56123cc4ce7965844f26fd1 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Thu, 16 Oct 2025 15:32:17 +0200 Subject: [PATCH] chore: Port to V2 mixins --- build.gradle.kts | 1 - .../internal/core/CoreLoadingPlugin.java | 18 +- .../{TargetedMod.java => LateMixins.java} | 32 +-- .../chunk/internal/mixin/plugin/Mixin.java | 99 +++++--- .../{MixinPlugin.java => TargetMod.java} | 36 +-- .../internal/mixin/plugin/fplib/IMixin.java | 77 ------- .../mixin/plugin/fplib/IMixinPlugin.java | 218 ------------------ .../mixin/plugin/fplib/ITargetedMod.java | 59 ----- .../chunk/internal/mixin/plugin/fplib/LICENSE | 19 -- .../mixin/plugin/fplib/MixinHelper.java | 112 +++++++++ .../chunk/internal/mixin/plugin/fplib/README | 1 - ...raftURLClassPath.java => SidedMixins.java} | 24 +- .../fplib/{FileUtil.java => TaggedMod.java} | 32 +-- .../mixin/plugin/fplib/TargetMod.java | 57 +++++ .../internal/mixin/plugin/fplib/UCPImpl.java | 61 ----- .../mixin/plugin/fplib/package-info.java | 12 +- ...unkapi.json => mixins.chunkapi.early.json} | 1 - src/main/resources/mixins.chunkapi.late.json | 9 + 18 files changed, 328 insertions(+), 540 deletions(-) rename src/main/java/com/falsepattern/chunk/internal/mixin/plugin/{TargetedMod.java => LateMixins.java} (61%) rename src/main/java/com/falsepattern/chunk/internal/mixin/plugin/{MixinPlugin.java => TargetMod.java} (50%) delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixin.java delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixinPlugin.java delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/ITargetedMod.java delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/LICENSE create mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MixinHelper.java delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/README rename src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/{MinecraftURLClassPath.java => SidedMixins.java} (68%) rename src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/{FileUtil.java => TaggedMod.java} (64%) create mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TargetMod.java delete mode 100644 src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/UCPImpl.java rename src/main/resources/{mixins.chunkapi.json => mixins.chunkapi.early.json} (75%) create mode 100644 src/main/resources/mixins.chunkapi.late.json diff --git a/build.gradle.kts b/build.gradle.kts index d9849f6..eac6daf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,6 @@ minecraft_fp { mixin { pkg = "internal.mixin.mixins" - pluginClass = "internal.mixin.plugin.MixinPlugin" } core { diff --git a/src/main/java/com/falsepattern/chunk/internal/core/CoreLoadingPlugin.java b/src/main/java/com/falsepattern/chunk/internal/core/CoreLoadingPlugin.java index f3eba34..e8f9fed 100644 --- a/src/main/java/com/falsepattern/chunk/internal/core/CoreLoadingPlugin.java +++ b/src/main/java/com/falsepattern/chunk/internal/core/CoreLoadingPlugin.java @@ -23,13 +23,19 @@ package com.falsepattern.chunk.internal.core; import com.falsepattern.chunk.internal.Tags; +import com.falsepattern.chunk.internal.mixin.plugin.Mixin; +import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader; +import com.gtnewhorizon.gtnhmixins.builders.IMixins; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.Set; @IFMLLoadingPlugin.TransformerExclusions(Tags.ROOT_PKG + ".internal.core") -public class CoreLoadingPlugin implements IFMLLoadingPlugin { +public class CoreLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { @Override public String[] getASMTransformerClass() { return new String[0]; @@ -54,4 +60,14 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin { public String getAccessTransformerClass() { return null; } + + @Override + public String getMixinConfig() { + return "mixins.chunkapi.early.json"; + } + + @Override + public List getMixins(Set loadedCoreMods) { + return IMixins.getEarlyMixins(Mixin.class, loadedCoreMods); + } } diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetedMod.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/LateMixins.java similarity index 61% rename from src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetedMod.java rename to src/main/java/com/falsepattern/chunk/internal/mixin/plugin/LateMixins.java index 7fc9fc1..c51fd5e 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetedMod.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/LateMixins.java @@ -22,23 +22,23 @@ package com.falsepattern.chunk.internal.mixin.plugin; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.ITargetedMod; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import com.gtnewhorizon.gtnhmixins.ILateMixinLoader; +import com.gtnewhorizon.gtnhmixins.LateMixin; +import com.gtnewhorizon.gtnhmixins.builders.IMixins; +import org.jetbrains.annotations.NotNull; -import java.util.function.Predicate; +import java.util.List; +import java.util.Set; -import static com.falsepattern.chunk.internal.mixin.plugin.fplib.ITargetedMod.PredicateHelpers.contains; +@LateMixin +public class LateMixins implements ILateMixinLoader { + @Override + public String getMixinConfig() { + return "mixins.chunkapi.late.json"; + } -@RequiredArgsConstructor -public enum TargetedMod implements ITargetedMod { - LOOKINGGLASS("Looking Glass", false, contains("lookingglass-")) - ; - - @Getter - private final String modName; - @Getter - private final boolean loadInDevelopment; - @Getter - private final Predicate condition; + @Override + public @NotNull List getMixins(Set loadedMods) { + return IMixins.getLateMixins(Mixin.class, loadedMods); + } } diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/Mixin.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/Mixin.java index 1653e15..cabad3d 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/Mixin.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/Mixin.java @@ -22,41 +22,84 @@ package com.falsepattern.chunk.internal.mixin.plugin; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.IMixin; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.ITargetedMod; +import com.falsepattern.chunk.internal.Tags; +import com.falsepattern.chunk.internal.mixin.plugin.fplib.MixinHelper; +import com.falsepattern.chunk.internal.mixin.plugin.fplib.SidedMixins; +import com.falsepattern.chunk.internal.mixin.plugin.fplib.TaggedMod; +import com.gtnewhorizon.gtnhmixins.builders.IMixins; +import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.intellij.lang.annotations.Language; -import java.util.List; -import java.util.function.Predicate; +import java.util.function.BooleanSupplier; -import static com.falsepattern.chunk.internal.mixin.plugin.fplib.IMixin.PredicateHelpers.always; -import static com.falsepattern.chunk.internal.mixin.plugin.fplib.IMixin.PredicateHelpers.require; +import static com.falsepattern.chunk.internal.mixin.plugin.TargetMod.LookingGlass; +import static com.falsepattern.chunk.internal.mixin.plugin.fplib.MixinHelper.avoid; +import static com.falsepattern.chunk.internal.mixin.plugin.fplib.MixinHelper.builder; +import static com.falsepattern.chunk.internal.mixin.plugin.fplib.MixinHelper.mods; +import static com.falsepattern.chunk.internal.mixin.plugin.fplib.MixinHelper.require; @RequiredArgsConstructor -public enum Mixin implements IMixin { - // @formatter:off - AnvilChunkLoaderMixin(Side.COMMON, always(), "vanilla.AnvilChunkLoaderMixin"), - PlayerInstanceMixin(Side.COMMON, always(), "vanilla.PlayerInstanceMixin"), - S21PacketChunkDataMixin(Side.COMMON, always(), "vanilla.S21PacketChunkDataMixin"), - S22PacketMultiBlockChangeMixin(Side.COMMON, always(), "vanilla.S22PacketMultiBlockChangeMixin"), - S23PacketBlockChangeMixin(Side.COMMON, always(), "vanilla.S23PacketBlockChangeMixin"), - S26PacketMapChunkBulkMixin(Side.COMMON, always(), "vanilla.S26PacketMapChunkBulkMixin"), +public enum Mixin implements IMixins { + Core(Phase.EARLY, + common("vanilla.AnvilChunkLoaderMixin", + "vanilla.PlayerInstanceMixin", + "vanilla.S21PacketChunkDataMixin", + "vanilla.S22PacketMultiBlockChangeMixin", + "vanilla.S23PacketBlockChangeMixin", + "vanilla.S26PacketMapChunkBulkMixin"), + client("vanilla.ChunkMixin", + "vanilla.NetHandlerPlayClientMixin")), - ChunkMixin(Side.CLIENT, always(), "vanilla.ChunkMixin"), - NetHandlerPlayClientMixin(Side.CLIENT, always(), "vanilla.NetHandlerPlayClientMixin"), - - //region Looking Glass - PacketChunkInfoMixin(Side.COMMON, require(TargetedMod.LOOKINGGLASS), "lookingglass.PacketChunkInfoMixin"), - //endregion + Compat_LookingGlass(Phase.LATE, + require(LookingGlass), + common("lookingglass.PacketChunkInfoMixin")), + //region boilerplate ; - // @formatter:on + @Getter + private final MixinBuilder builder; - @Getter - private final Side side; - @Getter - private final Predicate> filter; - @Getter - private final String mixin; + Mixin(Phase phase, SidedMixins... mixins) { + this(builder(mixins).setPhase(phase)); + } + + Mixin(Phase phase, BooleanSupplier cond, SidedMixins... mixins) { + this(builder(cond, mixins).setPhase(phase)); + } + + Mixin(Phase phase, TaggedMod mod, SidedMixins... mixins) { + this(builder(mod, mixins).setPhase(phase)); + } + + Mixin(Phase phase, TaggedMod[] mods, SidedMixins... mixins) { + this(builder(mods, mixins).setPhase(phase)); + } + + Mixin(Phase phase, BooleanSupplier cond, TaggedMod mod, SidedMixins... mixins) { + this(builder(cond, mod, mixins).setPhase(phase)); + } + + Mixin(Phase phase, BooleanSupplier cond, TaggedMod[] mods, SidedMixins... mixins) { + this(builder(cond, mods, mixins).setPhase(phase)); + } + + private static SidedMixins common(@Language(value = "JAVA", + prefix = "import " + Tags.ROOT_PKG + ".internal.mixin.mixins.common.", + suffix = ";") String... mixins) { + return MixinHelper.common(mixins); + } + + private static SidedMixins client(@Language(value = "JAVA", + prefix = "import " + Tags.ROOT_PKG + ".internal.mixin.mixins.client.", + suffix = ";") String... mixins) { + return MixinHelper.client(mixins); + } + + private static SidedMixins server(@Language(value = "JAVA", + prefix = "import " + Tags.ROOT_PKG + ".mixin.mixins.server.", + suffix = ";") String... mixins) { + return MixinHelper.server(mixins); + } + //endregion } - diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/MixinPlugin.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetMod.java similarity index 50% rename from src/main/java/com/falsepattern/chunk/internal/mixin/plugin/MixinPlugin.java rename to src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetMod.java index 72a1086..50d844a 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/MixinPlugin.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetMod.java @@ -22,24 +22,34 @@ package com.falsepattern.chunk.internal.mixin.plugin; -import com.falsepattern.chunk.internal.Tags; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.IMixin; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.IMixinPlugin; -import com.falsepattern.chunk.internal.mixin.plugin.fplib.ITargetedMod; +import com.gtnewhorizon.gtnhmixins.builders.ITargetMod; +import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder; import lombok.Getter; -import org.apache.logging.log4j.Logger; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class MixinPlugin implements IMixinPlugin { +import java.util.function.Consumer; + +public enum TargetMod implements ITargetMod { + LookingGlass("com.xcompwiz.lookingglass.LookingGlass"), + ; @Getter - private final Logger logger = IMixinPlugin.createLogger(Tags.MOD_NAME); + private final TargetModBuilder builder; - @Override - public ITargetedMod[] getTargetedModEnumValues() { - return TargetedMod.values(); + TargetMod(@Language(value = "JAVA", + prefix = "import ", + suffix = ";") @NotNull String className) { + this(className, null); } - @Override - public IMixin[] getMixinEnumValues() { - return Mixin.values(); + TargetMod(@Language(value = "JAVA", + prefix = "import ", + suffix = ";") @NotNull String className, @Nullable Consumer cfg) { + builder = new TargetModBuilder(); + builder.setTargetClass(className); + if (cfg != null) { + cfg.accept(builder); + } } } diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixin.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixin.java deleted file mode 100644 index 203ca54..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixin.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of FalsePatternLib. - * - * Copyright (C) 2022-2025 FalsePattern - * All Rights Reserved - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * FalsePatternLib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, only version 3 of the License. - * - * FalsePatternLib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FalsePatternLib. If not, see . - */ -package com.falsepattern.chunk.internal.mixin.plugin.fplib; - -import lombok.val; - -import cpw.mods.fml.relauncher.FMLLaunchHandler; - -import java.util.List; -import java.util.function.Predicate; -import java.util.function.Supplier; - -public interface IMixin { - String getMixin(); - Side getSide(); - Predicate> getFilter(); - - default boolean shouldLoad(List loadedMods) { - val side = getSide(); - return (side == Side.COMMON - || side == Side.SERVER && FMLLaunchHandler.side().isServer() - || side == Side.CLIENT && FMLLaunchHandler.side().isClient()) && getFilter().test(loadedMods); - } - - /** - * @since 0.10.0 - */ - enum Side { - COMMON, - CLIENT, - SERVER - } - - /** - * @since 0.10.0 - */ - final class PredicateHelpers { - public static Predicate> never() { - return (list) -> false; - } - - public static Predicate> condition(Supplier condition) { - return (list) -> condition.get(); - } - - public static Predicate> always() { - return (list) -> true; - } - - public static Predicate> require(ITargetedMod mod) { - return (list) -> list.contains(mod); - } - - public static Predicate> avoid(ITargetedMod mod) { - return (list) -> !list.contains(mod); - } - } -} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixinPlugin.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixinPlugin.java deleted file mode 100644 index 93c7b8d..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/IMixinPlugin.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This file is part of FalsePatternLib. - * - * Copyright (C) 2022-2025 FalsePattern - * All Rights Reserved - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * FalsePatternLib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, only version 3 of the License. - * - * FalsePatternLib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FalsePatternLib. If not, see . - */ -package com.falsepattern.chunk.internal.mixin.plugin.fplib; - -import lombok.val; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.ApiStatus; -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import net.minecraft.launchwrapper.Launch; - -import java.io.File; -import java.net.URL; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static java.nio.file.Files.walk; - -public interface IMixinPlugin extends IMixinConfigPlugin { - Path MODS_DIRECTORY_PATH = FileUtil.getMinecraftHome().toPath().resolve("mods"); - - static Logger createLogger(String modName) { - return LogManager.getLogger(modName + " Mixin Loader"); - } - - /** - * @deprecated since 1.4.0 - */ - @Deprecated - static File findJarOf(final ITargetedMod mod) { - File result = null; - try (val stream = walk(MODS_DIRECTORY_PATH)) { - result = stream.filter(mod::isMatchingJar).map(Path::toFile).findFirst().orElse(null); - } catch (Exception e) { - e.printStackTrace(); - } - if (result == null) { - File found = null; - for (URL url : Launch.classLoader.getURLs()) { - try { - val file = new File(url.toURI()); - Path path = file.toPath(); - if (mod.isMatchingJar(path)) { - found = file; - break; - } - } catch (Exception ignored) { - } - } - result = found; - } - return result; - } - - /** - * @since 1.4.0 - */ - static Set findJarsOf(IMixinPlugin self, final ITargetedMod mod) { - if (!self.useNewFindJar()) { - val jar = findJarOf(mod); - return jar == null ? Collections.emptySet() : Collections.singleton(jar); - } - val results = new HashSet(); - try (val stream = walk(MODS_DIRECTORY_PATH)) { - results.addAll(stream.filter(mod::isMatchingJar).map(Path::toFile).collect(Collectors.toSet())); - } catch (Exception e) { - e.printStackTrace(); - } - for (URL url : Launch.classLoader.getURLs()) { - try { - val file = new File(url.toURI()); - Path path = file.toPath(); - if (mod.isMatchingJar(path)) { - results.add(file); - break; - } - } catch (Exception ignored) { - } - } - return results; - } - - Logger getLogger(); - - IMixin[] getMixinEnumValues(); - - ITargetedMod[] getTargetedModEnumValues(); - - /** - * @since 1.4.0 - */ - default boolean useNewFindJar() { - return false; - } - - @Override - @ApiStatus.Internal - default void onLoad(String mixinPackage) { - - } - - @Override - @ApiStatus.Internal - default String getRefMapperConfig() { - return null; - } - - @Override - @ApiStatus.Internal - default boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return true; - } - - @Override - @ApiStatus.Internal - default void acceptTargets(Set myTargets, Set otherTargets) { - - } - - @Override - @ApiStatus.Internal - default List getMixins() { - val isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); - val targetedMods = getTargetedModEnumValues(); - val loadedMods = Arrays.stream(targetedMods) - //Java 21 compat - .filter(new Predicate() { - @Override - public boolean test(ITargetedMod mod) { - boolean loadJar = IMixinPlugin.this.loadJarOf(mod); - return (mod.isLoadInDevelopment() && isDevelopmentEnvironment) - || loadJar; - } - }) - .collect(Collectors.toList()); - - for (val mod : targetedMods) { - if (loadedMods.contains(mod)) { - getLogger().info("Found " + mod.getModName() + "! Integrating now..."); - } else { - getLogger().info("Could not find " + mod.getModName() + "! Skipping integration...."); - } - } - - List mixins = new ArrayList<>(); - for (val mixin : getMixinEnumValues()) { - if (mixin.shouldLoad(loadedMods)) { - String mixinClass = mixin.getSide().name().toLowerCase() + "." + mixin.getMixin(); - mixins.add(mixinClass); - getLogger().info("Loading mixin: " + mixinClass); - } - } - return mixins; - } - - @ApiStatus.Internal - default boolean loadJarOf(final ITargetedMod mod) { - try { - val jars = findJarsOf(this, mod); - if (jars.isEmpty()) { - getLogger().info("Jar not found for {}", mod); - return false; - } - for (val jar: jars) { - getLogger().info("Attempting to add {} to the URL Class Path", jar); - try { - MinecraftURLClassPath.addJar(jar); - } catch (Throwable e) { - e.printStackTrace(); - } - } - } catch (Throwable e) { - e.printStackTrace(); - } - return true; - } - - @Override - @ApiStatus.Internal - default void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - @ApiStatus.Internal - default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } -} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/ITargetedMod.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/ITargetedMod.java deleted file mode 100644 index 1d651f4..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/ITargetedMod.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of FalsePatternLib. - * - * Copyright (C) 2022-2025 FalsePattern - * All Rights Reserved - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * FalsePatternLib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, only version 3 of the License. - * - * FalsePatternLib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FalsePatternLib. If not, see . - */ - -package com.falsepattern.chunk.internal.mixin.plugin.fplib; - -import com.google.common.io.Files; - -import java.nio.file.Path; -import java.util.function.Predicate; - -public interface ITargetedMod { - String getModName(); - - boolean isLoadInDevelopment(); - - @SuppressWarnings("UnstableApiUsage") - default boolean isMatchingJar(Path path) { - String pathString = path.toString(); - String nameLowerCase = Files.getNameWithoutExtension(pathString).toLowerCase(); - String fileExtension = Files.getFileExtension(pathString); - - return "jar".equals(fileExtension) && getCondition().test(nameLowerCase); - } - - Predicate getCondition(); - - final class PredicateHelpers { - public static Predicate startsWith(String subString) { - return (name) -> name.startsWith(subString.toLowerCase()); - } - - public static Predicate contains(String subString) { - return (name) -> name.contains(subString.toLowerCase()); - } - - public static Predicate matches(String regex) { - return (name) -> name.matches(regex); - } - } -} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/LICENSE b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/LICENSE deleted file mode 100644 index f9a78b9..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -FalsePatternLib - -Copyright (C) 2022-2025 FalsePattern -All Rights Reserved - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions of the Software. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, only version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this program. If not, see . \ No newline at end of file diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MixinHelper.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MixinHelper.java new file mode 100644 index 0000000..30d4022 --- /dev/null +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MixinHelper.java @@ -0,0 +1,112 @@ +/* + * This file is part of FalsePatternLib. + * + * Copyright (C) 2022-2025 FalsePattern + * All Rights Reserved + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * FalsePatternLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * FalsePatternLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with FalsePatternLib. If not, see . + */ + +package com.falsepattern.chunk.internal.mixin.plugin.fplib; + +import com.gtnewhorizon.gtnhmixins.builders.IBaseTransformer; +import com.gtnewhorizon.gtnhmixins.builders.ITargetMod; +import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder; +import lombok.val; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BooleanSupplier; + +public class MixinHelper { + public static @NotNull MixinBuilder builder(@NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(null, null, mixins); + } + + public static @NotNull MixinBuilder builder(@Nullable BooleanSupplier cond, @NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(cond, null, mixins); + } + + public static @NotNull MixinBuilder builder(@NotNull TaggedMod mod, @NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(null, mods(mod), mixins); + } + + public static @NotNull MixinBuilder builder(@NotNull TaggedMod @Nullable [] mods, @NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(null, mods, mixins); + } + + public static @NotNull MixinBuilder builder(@NotNull BooleanSupplier cond, @NotNull TaggedMod mod, @NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(cond, mods(mod), mixins); + } + + public static @NotNull MixinBuilder builder(@NotNull BooleanSupplier cond, @NotNull TaggedMod @NotNull [] mods, @NotNull SidedMixins @NotNull ... mixins) { + return builderImpl(cond, mods, mixins); + } + + private static @NotNull MixinBuilder builderImpl(@Nullable BooleanSupplier cond, @NotNull TaggedMod @Nullable [] requiredMods, @NotNull SidedMixins @NotNull ... mixins) { + val builder = new MixinBuilder(); + if (requiredMods != null) { + for (val mod : requiredMods) { + if (mod.require) { + builder.addRequiredMod(mod.mod); + } else { + builder.addExcludedMod(mod.mod); + } + } + } + for (val mixin : mixins) { + builder.addSidedMixins(mixin.side, mixin.mixins); + } + if (cond != null) { + builder.setApplyIf(cond::getAsBoolean); + } + return builder; + } + + public static @NotNull SidedMixins common(@NotNull String @NotNull ... mixins) { + for (int i = 0; i < mixins.length; i++) { + mixins[i] = "common." + mixins[i]; + } + return new SidedMixins(IBaseTransformer.Side.COMMON, mixins); + } + + public static @NotNull SidedMixins client(@NotNull String @NotNull ... mixins) { + for (int i = 0; i < mixins.length; i++) { + mixins[i] = "client." + mixins[i]; + } + return new SidedMixins(IBaseTransformer.Side.CLIENT, mixins); + } + + public static @NotNull SidedMixins server(@NotNull String @NotNull ... mixins) { + for (int i = 0; i < mixins.length; i++) { + mixins[i] = "server." + mixins[i]; + } + return new SidedMixins(IBaseTransformer.Side.SERVER, mixins); + } + + public static @NotNull TaggedMod require(@NotNull ITargetMod mod) { + return new TaggedMod(true, mod); + } + + public static @NotNull TaggedMod avoid(@NotNull ITargetMod mod) { + return new TaggedMod(false, mod); + } + + public static @NotNull TaggedMod @NotNull [] mods(@NotNull TaggedMod @NotNull ... t) { + return t; + } + +} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/README b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/README deleted file mode 100644 index d1745be..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/README +++ /dev/null @@ -1 +0,0 @@ -Shadowed from FalsePatternLib 1.7.0 \ No newline at end of file diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MinecraftURLClassPath.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/SidedMixins.java similarity index 68% rename from src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MinecraftURLClassPath.java rename to src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/SidedMixins.java index a249f72..648ae16 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/MinecraftURLClassPath.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/SidedMixins.java @@ -19,23 +19,15 @@ * You should have received a copy of the GNU Lesser General Public License * along with FalsePatternLib. If not, see . */ + package com.falsepattern.chunk.internal.mixin.plugin.fplib; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import com.gtnewhorizon.gtnhmixins.builders.IBaseTransformer; +import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; -import java.io.File; - -/** - * Backport from spongemixins 1.3 for compat with the curseforge 1.2.0 version. - *

- * Also added Grimoire protection. - * - * @since 0.10.0 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class MinecraftURLClassPath { - public static void addJar(File pathToJar) throws Exception { - UCPImpl.addJar(pathToJar); - } +@RequiredArgsConstructor +public class SidedMixins { + public final IBaseTransformer.@NotNull Side side; + public final @NotNull String @NotNull [] mixins; } diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/FileUtil.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TaggedMod.java similarity index 64% rename from src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/FileUtil.java rename to src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TaggedMod.java index eafaa77..f91dc50 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/FileUtil.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TaggedMod.java @@ -19,29 +19,15 @@ * You should have received a copy of the GNU Lesser General Public License * along with FalsePatternLib. If not, see . */ + package com.falsepattern.chunk.internal.mixin.plugin.fplib; -import lombok.experimental.UtilityClass; +import com.gtnewhorizon.gtnhmixins.builders.ITargetMod; +import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; -import net.minecraft.launchwrapper.Launch; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; - -/** - * @since 0.8.2 - */ -@UtilityClass -public final class FileUtil { - public static File getMinecraftHome() { - return getMinecraftHomePath().toFile(); - } - - /** - * @since 1.0.0 - */ - public static Path getMinecraftHomePath() { - return Launch.minecraftHome == null ? Paths.get("").toAbsolutePath() : Launch.minecraftHome.toPath(); - } -} +@RequiredArgsConstructor +public class TaggedMod { + public final boolean require; + public final @NotNull ITargetMod mod; +} \ No newline at end of file diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TargetMod.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TargetMod.java new file mode 100644 index 0000000..ba5d175 --- /dev/null +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/TargetMod.java @@ -0,0 +1,57 @@ +/* + * This file is part of FalsePatternLib. + * + * Copyright (C) 2022-2025 FalsePattern + * All Rights Reserved + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * FalsePatternLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * FalsePatternLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with FalsePatternLib. If not, see . + */ + +package com.falsepattern.chunk.internal.mixin.plugin.fplib; + +import com.gtnewhorizon.gtnhmixins.builders.ITargetMod; +import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder; +import lombok.Getter; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; + +public class TargetMod implements ITargetMod { + @Getter + private final TargetModBuilder builder; + + private final String name; + + public TargetMod(@NotNull String name, @Language(value = "JAVA", prefix = "import ", suffix = ";") @NotNull String className) { + this(name, className, null); + } + + public TargetMod(@NotNull String name, @Language(value = "JAVA", prefix = "import ", suffix = ";") @NotNull String className, @Nullable Consumer cfg) { + this.name = name; + builder = new TargetModBuilder(); + builder.setTargetClass(className); + if (cfg != null) { + cfg.accept(builder); + } + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/UCPImpl.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/UCPImpl.java deleted file mode 100644 index 8dc9b2d..0000000 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/UCPImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of FalsePatternLib. - * - * Copyright (C) 2022-2025 FalsePattern - * All Rights Reserved - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * FalsePatternLib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, only version 3 of the License. - * - * FalsePatternLib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FalsePatternLib. If not, see . - */ - -package com.falsepattern.chunk.internal.mixin.plugin.fplib; - -import lombok.val; - -import net.minecraft.launchwrapper.Launch; -import net.minecraft.launchwrapper.LaunchClassLoader; - -import java.io.File; -import java.io.IOException; - -public final class UCPImpl { - private static final boolean GRIMOIRE; - - static { - boolean grimoire = false; - String[] knownGrimoireClassNames = - new String[]{"io.github.crucible.grimoire.Grimoire", "io.github.crucible.grimoire.common.GrimoireCore"}; - for (val className : knownGrimoireClassNames) { - try { - if (Launch.classLoader.getClassBytes(className) != null) { - grimoire = true; - break; - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - GRIMOIRE = grimoire; - } - - public static void addJar(File pathToJar) throws Exception { - if (!GRIMOIRE) { - final LaunchClassLoader loader = Launch.classLoader; - loader.addURL(pathToJar.toURI().toURL()); - // Act as-if we only added the mod to ucp - loader.getSources().remove(loader.getSources().size() - 1); - } - } -} diff --git a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/package-info.java b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/package-info.java index 270bd42..4e2b7a2 100644 --- a/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/package-info.java +++ b/src/main/java/com/falsepattern/chunk/internal/mixin/plugin/fplib/package-info.java @@ -1,23 +1,23 @@ /* - * ChunkAPI + * This file is part of FalsePatternLib. * - * Copyright (C) 2023-2025 FalsePattern, The MEGA Team, LegacyModdingMC contributors + * Copyright (C) 2022-2025 FalsePattern * All Rights Reserved * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * This program is free software: you can redistribute it and/or modify + * FalsePatternLib is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, only version 3 of the License. * - * This program is distributed in the hope that it will be useful, + * FalsePatternLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . + * along with FalsePatternLib. If not, see . */ @ApiStatus.Internal diff --git a/src/main/resources/mixins.chunkapi.json b/src/main/resources/mixins.chunkapi.early.json similarity index 75% rename from src/main/resources/mixins.chunkapi.json rename to src/main/resources/mixins.chunkapi.early.json index 1731b18..0e60fb4 100644 --- a/src/main/resources/mixins.chunkapi.json +++ b/src/main/resources/mixins.chunkapi.early.json @@ -2,7 +2,6 @@ "required": true, "minVersion": "0.8.5", "package": "com.falsepattern.chunk.internal.mixin.mixins", - "plugin": "com.falsepattern.chunk.internal.mixin.plugin.MixinPlugin", "refmap": "mixins.chunkapi.refmap.json", "target": "@env(DEFAULT)", "compatibilityLevel": "JAVA_8" diff --git a/src/main/resources/mixins.chunkapi.late.json b/src/main/resources/mixins.chunkapi.late.json new file mode 100644 index 0000000..0e60fb4 --- /dev/null +++ b/src/main/resources/mixins.chunkapi.late.json @@ -0,0 +1,9 @@ +{ + "required": true, + "minVersion": "0.8.5", + "package": "com.falsepattern.chunk.internal.mixin.mixins", + "refmap": "mixins.chunkapi.refmap.json", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8" +} +