Add facility to hide mixin options outside dev
This commit is contained in:
parent
5315d80859
commit
4ea7b864a8
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.embeddedt.modernfix.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The config system will ignore mixins with this annotation when generating config options unless running
|
||||||
|
* in a dev environment.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface IgnoreOutsideDev {
|
||||||
|
}
|
||||||
|
|
@ -8,10 +8,14 @@ import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||||
|
import org.embeddedt.modernfix.annotation.IgnoreOutsideDev;
|
||||||
|
import org.embeddedt.modernfix.annotation.RequiresMod;
|
||||||
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.AnnotationNode;
|
import org.objectweb.asm.tree.AnnotationNode;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
@ -47,9 +51,10 @@ public class ModernFixEarlyConfig {
|
||||||
return ModernFixPlatformHooks.modPresent(modId);
|
return ModernFixPlatformHooks.modPresent(modId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String MIXIN_DESC = "Lorg/spongepowered/asm/mixin/Mixin;";
|
private static final String MIXIN_DESC = Mixin.class.descriptorString();
|
||||||
private static final String MIXIN_CLIENT_ONLY_DESC = "Lorg/embeddedt/modernfix/annotation/ClientOnlyMixin;";
|
private static final String MIXIN_CLIENT_ONLY_DESC = ClientOnlyMixin.class.descriptorString();
|
||||||
private static final String MIXIN_REQUIRES_MOD_DESC = "Lorg/embeddedt/modernfix/annotation/RequiresMod;";
|
private static final String MIXIN_REQUIRES_MOD_DESC = RequiresMod.class.descriptorString();
|
||||||
|
private static final String MIXIN_DEV_ONLY_DESC = IgnoreOutsideDev.class.descriptorString();
|
||||||
|
|
||||||
private static final Pattern PLATFORM_PREFIX = Pattern.compile("(forge|fabric|common)\\.");
|
private static final Pattern PLATFORM_PREFIX = Pattern.compile("(forge|fabric|common)\\.");
|
||||||
|
|
||||||
|
|
@ -92,7 +97,7 @@ public class ModernFixEarlyConfig {
|
||||||
reader.accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
|
reader.accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
|
||||||
if(node.invisibleAnnotations == null)
|
if(node.invisibleAnnotations == null)
|
||||||
return;
|
return;
|
||||||
boolean isMixin = false, isClientOnly = false, requiredModPresent = true;
|
boolean isMixin = false, isClientOnly = false, requiredModPresent = true, isDevOnly = false;
|
||||||
String requiredModId = "";
|
String requiredModId = "";
|
||||||
for(AnnotationNode annotation : node.invisibleAnnotations) {
|
for(AnnotationNode annotation : node.invisibleAnnotations) {
|
||||||
if(Objects.equals(annotation.desc, MIXIN_DESC)) {
|
if(Objects.equals(annotation.desc, MIXIN_DESC)) {
|
||||||
|
|
@ -110,9 +115,11 @@ public class ModernFixEarlyConfig {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(Objects.equals(annotation.desc, MIXIN_DEV_ONLY_DESC)) {
|
||||||
|
isDevOnly = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isMixin) {
|
if(isMixin && (!isDevOnly || ModernFixPlatformHooks.isDevEnv())) {
|
||||||
String mixinClassName = sanitize(node.name.replace('/', '.')).replace("org.embeddedt.modernfix.mixin.", "");
|
String mixinClassName = sanitize(node.name.replace('/', '.')).replace("org.embeddedt.modernfix.mixin.", "");
|
||||||
if(!requiredModPresent)
|
if(!requiredModPresent)
|
||||||
mixinsMissingMods.put(mixinClassName, requiredModId);
|
mixinsMissingMods.put(mixinClassName, requiredModId);
|
||||||
|
|
@ -157,9 +164,8 @@ public class ModernFixEarlyConfig {
|
||||||
private static final ImmutableMap<String, Boolean> DEFAULT_SETTING_OVERRIDES = new DefaultSettingMapBuilder()
|
private static final ImmutableMap<String, Boolean> DEFAULT_SETTING_OVERRIDES = new DefaultSettingMapBuilder()
|
||||||
.put("mixin.perf.dynamic_resources", false)
|
.put("mixin.perf.dynamic_resources", false)
|
||||||
.put("mixin.feature.direct_stack_trace", false)
|
.put("mixin.feature.direct_stack_trace", false)
|
||||||
.put("mixin.perf.rewrite_registry", false)
|
.putConditionally(ModernFixPlatformHooks::isDevEnv, "mixin.perf.rewrite_registry", false)
|
||||||
.put("mixin.perf.clear_mixin_classinfo", false)
|
.put("mixin.perf.clear_mixin_classinfo", false)
|
||||||
.put("mixin.perf.compress_blockstate", false)
|
|
||||||
.put("mixin.bugfix.packet_leak", false)
|
.put("mixin.bugfix.packet_leak", false)
|
||||||
.put("mixin.perf.deduplicate_location", false)
|
.put("mixin.perf.deduplicate_location", false)
|
||||||
.put("mixin.feature.integrated_server_watchdog", true)
|
.put("mixin.feature.integrated_server_watchdog", true)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.registries.ForgeRegistry;
|
import net.minecraftforge.registries.ForgeRegistry;
|
||||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||||
|
import org.embeddedt.modernfix.annotation.IgnoreOutsideDev;
|
||||||
import org.embeddedt.modernfix.forge.registry.FastForgeRegistry;
|
import org.embeddedt.modernfix.forge.registry.FastForgeRegistry;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
@ -17,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(value = ForgeRegistry.class, remap = false)
|
@Mixin(value = ForgeRegistry.class, remap = false)
|
||||||
|
@IgnoreOutsideDev
|
||||||
public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
|
public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.registries.ForgeRegistry;
|
import net.minecraftforge.registries.ForgeRegistry;
|
||||||
|
import org.embeddedt.modernfix.annotation.IgnoreOutsideDev;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
|
@ -16,6 +17,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mixin(ForgeRegistry.Snapshot.class)
|
@Mixin(ForgeRegistry.Snapshot.class)
|
||||||
|
@IgnoreOutsideDev
|
||||||
public class ForgeRegistrySnapshotMixin {
|
public class ForgeRegistrySnapshotMixin {
|
||||||
@Shadow @Final @Mutable public Map<ResourceLocation, Integer> ids;
|
@Shadow @Final @Mutable public Map<ResourceLocation, Integer> ids;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user