Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ dependencies {
lwjglNative "org.lwjgl:lwjgl-freetype:${lwjgl_version}"
}

apply from: 'build_modpatches.gradle'

tasks.withType(Test).configureEach {
maxParallelForks = 1
jvmArgs open_arguments + export_arguments
Expand Down
41 changes: 41 additions & 0 deletions build_modpatches.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Applied below dependencies block in build.gradle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to src/module/modpatches/build.gradle ?


repositories {
exclusiveContent {
forRepository {
maven {
name 'CleanroomMC CurseMaven'
url 'https://curse.cleanroommc.com'
}
}
filter {
includeGroup 'curse.maven'
}
}
}

dependencies {
compileOnly 'curse.maven:armourers-workshop-229523:3101995'
compileOnly 'curse.maven:better-records-222722:2930159'
compileOnly 'curse.maven:carry-on-274259:4507139'
compileOnly 'curse.maven:charset-284523:3656492'
compileOnly 'curse.maven:codechicken-lib-242818:2779848'
compileOnly 'curse.maven:creativecore-257814:4722163'
compileOnly 'curse.maven:custom-main-menu-226406:2857869'
compileOnly 'curse.maven:custom-npcs-221826:2996912'
compileOnly 'curse.maven:dark-theme-323440:3146120'
compileOnly 'curse.maven:requiem-265729:2942107'
compileOnly 'curse.maven:ender-utilities-224320:2977010'
compileOnly 'curse.maven:howling-moon-236149:2567452'
compileOnly 'curse.maven:little-tiles-257818:5180387'
compileOnly 'curse.maven:lockdown-244019:2477270'
compileOnly 'curse.maven:mcjty-lib-233105:2745846'
compileOnly 'curse.maven:cb-multipart-258426:2755790'
compileOnly 'curse.maven:project-red-core-228702:2745545'
compileOnly 'curse.maven:recurrent-complex-223150:8562927'
compileOnly 'curse.maven:refined-storage-243076:2940914'
compileOnly 'curse.maven:water-power-224579:2464789'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:2.3.10'
compileOnly 'curse.maven:xaero-plus-866084:9067807'
compileOnly 'curse.maven:mpm-221939:2837187'
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,68 @@ public final class CompatibilityConfig {
@Config.Comment("(X[]) collection.toArray() becomes collection.toArray(new X[0]).")
public static boolean toArrayCast = true;

@Config.Comment("Compatibility patches for mods") public static final Mods mods = new Mods();

public static final class Mods {

@Config.Comment({ "Patch Better Sprinting", "https://www.curseforge.com/minecraft/mc-mods/better-sprinting" })
public boolean betterSprinting = true;

@Config.Comment({ "Patch Ears", "https://www.curseforge.com/minecraft/mc-mods/ears" })
public boolean ears = true;

@Config.Comment(
{ "Patch Enchantments Control", "https://www.curseforge.com/minecraft/mc-mods/enchantments-control" }
) public boolean enchantmentsControl = true;

@Config.Comment({ "Patch Ender Core", "https://www.curseforge.com/minecraft/mc-mods/endercore" })
public boolean enderCore = true;

@Config.Comment({ "Patch Future MC", "https://www.curseforge.com/minecraft/mc-mods/future-mc" })
public boolean futureMC = true;

@Config.Comment({ "Patch More Sound Config", "https://www.curseforge.com/minecraft/mc-mods/more-sound-config" })
public boolean moreSoundConfig = true;

@Config.Comment({ "Patch Serene Seasons", "https://www.curseforge.com/minecraft/mc-mods/serene-seasons" })
public boolean sereneSeasons = true;

@Config.Comment({ "Patch Subaquatic", "https://modrinth.com/project/GjqoNelE" })
public boolean subaquatic = true;

@Config.Comment({ "Patch Better Records", "https://www.curseforge.com/minecraft/mc-mods/better-records" })
public boolean betterRecords = true;

@Config.Comment({ "Patch CodeChickenLib", "https://www.curseforge.com/minecraft/mc-mods/codechicken-lib-1-8" })
public boolean codeChickenLib = true;

@Config.Comment({ "Patch CreativeCore", "https://www.curseforge.com/minecraft/mc-mods/creativecore" })
public boolean creativeCore = true;

@Config.Comment({ "Patch Crossbow", "https://modrinth.com/mod/crossbow" }) public boolean crossbow = true;

@Config.Comment({ "Patch Custom Main Menu", "https://www.curseforge.com/minecraft/mc-mods/custom-main-menu" })
public boolean customMainMenu = true;

@Config.Comment({ "Patch Lockdown", "https://www.curseforge.com/minecraft/mc-mods/lockdown" })
public boolean lockdown = true;

@Config.Comment({ "Patch McJtyLib", "https://www.curseforge.com/minecraft/mc-mods/mcjtylib" })
public boolean mcjtyLib = true;

@Config.Comment({ "Patch Project Red - Core", "https://www.curseforge.com/minecraft/mc-mods/project-red-core" })
public boolean projectRedCore = true;

@Config.Comment({ "Patch Water Power", "https://www.curseforge.com/minecraft/mc-mods/water-power" })
public boolean waterPower = true;

@Config.Comment({ "Patch XaeroPlus", "https://www.curseforge.com/minecraft/mc-mods/xaeroplus" })
public boolean xaeroPlus = true;

private Mods() { }

}

private CompatibilityConfig() { }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2026 CleanroomMC contributors
*
* This file is licensed under the CleanroomMC License Version 1.0.
* See the applicable LICENSE file in this directory or a parent directory
* for the full licence terms.
*
* This is visible-source software and is not open-source software.
*/

package com.cleanroommc.cleanroom.modpatch;

import com.cleanroommc.cleanroom.compatibility.CompatibilityConfig;

import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;

public final class ModPatchMixinPlugin implements IMixinConfigPlugin {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return switch (mixinClassName.split("\\.")[5]) {
case "betterrecords" -> CompatibilityConfig.mods.betterRecords;
case "codechickenlib" -> CompatibilityConfig.mods.codeChickenLib;
case "creativecore" -> CompatibilityConfig.mods.creativeCore;
case "custommainmenu" -> CompatibilityConfig.mods.customMainMenu;
case "lockdown" -> CompatibilityConfig.mods.lockdown;
case "mcjtylib" -> CompatibilityConfig.mods.mcjtyLib;
case "projectred_core" -> CompatibilityConfig.mods.projectRedCore;
case "waterpower" -> CompatibilityConfig.mods.waterPower;
case "xaeroplus" -> CompatibilityConfig.mods.xaeroPlus;
default ->
throw new UnsupportedOperationException("Mod " + mixinClassName.split("\\.")[5] + " is not supported");
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2026 CleanroomMC contributors
*
* This file is licensed under the CleanroomMC License Version 1.0.
* See the applicable LICENSE file in this directory or a parent directory
* for the full licence terms.
*
* This is visible-source software and is not open-source software.
*/

package com.cleanroommc.cleanroom.modpatch;

import com.cleanroommc.cleanroom.modpatch.transformer.ModTransformers;
import com.cleanroommc.discovery.CleanroomModDiscoverer;
import top.outlands.foundation.boot.ActualClassLoader;
import top.outlands.foundation.boot.TransformerHolder;
import top.outlands.foundation.function.ExplicitTransformerFunction;

import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.edit.MixinEdits;

import net.minecraftforge.fml.relauncher.FMLLaunchHandler;

public final class ModPatchTransformer {

private ModPatchTransformer() { }

public static byte[] transform(String name, byte[] bytes) {
if (bytes == null || name.startsWith("com.cleanroommc.cleanroom.")) {
return bytes;
}
if (isJava9OrHigher(bytes)) {
return bytes;
}
bytes = ModTransformers.transform(name, bytes);
return bytes;
}

public static void install() {
if (FMLLaunchHandler.side().isClient()) {
MixinEdits.of("org.embeddedt.vintagefix.mixin.bugfix.tab_complete_ddos.ChatTabCompleterMixin").cancel();
}
TransformerHolder holder = ActualClassLoader.getTransformerHolder();
ExplicitTransformerFunction previous = holder.runExplicitTransformersFunction;
holder.runExplicitTransformersFunction = (name, bytes) -> transform(name, previous.apply(name, bytes));
Mixins.addConfiguration("mixin.cleanroom.modpatch.json");
}

private static boolean isJava9OrHigher(byte[] bytes) {
return (short) (((bytes[6] & 0xFF) << 8) | (bytes[7] & 0xFF)) > 52;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2026 CleanroomMC contributors
*
* This file is licensed under the CleanroomMC License Version 1.0.
* See the applicable LICENSE file in this directory or a parent directory
* for the full licence terms.
*
* This is visible-source software and is not open-source software.
*/

package com.cleanroommc.cleanroom.modpatch.mixin.betterrecords;

import tech.feldman.betterrecords.api.sound.Sound;
import tech.feldman.betterrecords.client.sound.SoundManager;
import tech.feldman.betterrecords.client.sound.SoundPlayer;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.util.math.BlockPos;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

@Mixin(value = SoundManager.class, remap = false)
public class SoundManagerMixin {

@Unique private static final Map<Thread, AtomicBoolean> threads = new ConcurrentHashMap<>();

@Redirect(method = "stopQueueAt", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;stop()V"))
private void stopQueueAt(Thread thread) {
Optional.ofNullable(threads.get(thread)).ifPresent(t -> t.set(false));
thread.interrupt();
threads.remove(thread);
}

@Inject(
method = "queueSongsAt",
at = @At(
value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"
)
)
private void hackThread(
BlockPos pos, int dimension, List<Sound> sounds, boolean shuffle, boolean repeat, CallbackInfo ci,
@Local LocalRef<Thread> job) {
AtomicBoolean interrupted = new AtomicBoolean(false);
Thread thread = new SoundThread(interrupted, sounds, pos, dimension, repeat);
job.set(thread);
threads.put(thread, interrupted);
}

public static class SoundThread extends Thread {

private final AtomicBoolean interrupted;
private final List<Sound> sounds;
private final BlockPos pos;
private final int dim;
private final boolean repeat;

public SoundThread(AtomicBoolean interrupted, List<Sound> sounds, BlockPos pos, int dim, boolean repeat) {
super("Better Records Sound Thread");
this.interrupted = interrupted;
this.sounds = sounds;
this.pos = pos;
this.dim = dim;
this.repeat = repeat;
}

@Override
public void interrupt() {
interrupted.set(true);
}

@Override
public void run() {
while (!interrupted.get()) {
sounds.forEach(sound -> SoundPlayer.INSTANCE.playSound(pos, dim, sound));
if (!repeat) {
return;
}
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2026 CleanroomMC contributors
*
* This file is licensed under the CleanroomMC License Version 1.0.
* See the applicable LICENSE file in this directory or a parent directory
* for the full licence terms.
*
* This is visible-source software and is not open-source software.
*/

package com.cleanroommc.cleanroom.modpatch.mixin.codechickenlib;

import codechicken.lib.reflect.ObfMapping;
import codechicken.lib.reflect.ReflectionManager;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.lang.reflect.Field;

@Mixin(value = ReflectionManager.class, remap = false)
public class ReflectionManagerMixin {

@Redirect(
method = "removeFinal",
at = @At(
value = "INVOKE",
target = "Lcodechicken/lib/reflect/ReflectionManager;getField(Lcodechicken/lib/reflect/ObfMapping;)Ljava/lang/reflect/Field;"
)
)
private static Field getField(ObfMapping e) {
try {
return Field.class.getDeclaredField("modifiers");
} catch (NoSuchFieldException nsfe) {
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2026 CleanroomMC contributors
*
* This file is licensed under the CleanroomMC License Version 1.0.
* See the applicable LICENSE file in this directory or a parent directory
* for the full licence terms.
*
* This is visible-source software and is not open-source software.
*/

package com.cleanroommc.cleanroom.modpatch.mixin.creativecore;

import com.creativemd.creativecore.common.config.event.ConfigEventHandler;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Mixin(value = ConfigEventHandler.class, remap = false)
public class ConfigEventHandlerMixin {

@Redirect(method = "saveClientFields", at = @At(value = "NEW", target = "(Ljava/io/File;)Ljava/io/FileWriter;"))
private static FileWriter fixCharset(File file) throws IOException {
return new FileWriter(file, StandardCharsets.UTF_8);
}

@Redirect(
method = "save(Ljava/lang/String;Lnet/minecraftforge/fml/relauncher/Side;)V",
at = @At(value = "NEW", target = "(Ljava/io/File;)Ljava/io/FileWriter;")
)
private static FileWriter fixCharset2(File file) throws IOException {
return new FileWriter(file, StandardCharsets.UTF_8);
}

}
Loading
Loading