diff --git a/dev/example/assets/extra_recipe/crt/test/test2.zs b/dev/example/assets/extra_recipe/crt/test/test2.zs new file mode 100644 index 0000000..9f616c8 --- /dev/null +++ b/dev/example/assets/extra_recipe/crt/test/test2.zs @@ -0,0 +1,4 @@ +#loader recipeevent crafttweaker +#debug + +recipes.addShapeless( ,[]); \ No newline at end of file diff --git a/dev/example/assets/extra_recipe/crt/test_item.zs b/dev/example/assets/extra_recipe/crt/test/test_item.zs similarity index 98% rename from dev/example/assets/extra_recipe/crt/test_item.zs rename to dev/example/assets/extra_recipe/crt/test/test_item.zs index c729e96..1679f61 100644 --- a/dev/example/assets/extra_recipe/crt/test_item.zs +++ b/dev/example/assets/extra_recipe/crt/test/test_item.zs @@ -1,4 +1,5 @@ #priority 1 +#debug #loader contenttweaker import mods.contenttweaker.VanillaFactory; diff --git a/dev/example/assets/extra_recipe/crt/tests/test2.zs b/dev/example/assets/extra_recipe/crt/tests/test2.zs deleted file mode 100644 index 023c1a6..0000000 --- a/dev/example/assets/extra_recipe/crt/tests/test2.zs +++ /dev/null @@ -1,3 +0,0 @@ -#loader recipeevent - -recipes.addShapeless( ,[]); \ No newline at end of file diff --git a/src/main/java/mods/Hileb/rml/compat/crt/RMLCrTLoader.java b/src/main/java/mods/Hileb/rml/compat/crt/RMLCrTLoader.java index 3f82d3b..8e21201 100644 --- a/src/main/java/mods/Hileb/rml/compat/crt/RMLCrTLoader.java +++ b/src/main/java/mods/Hileb/rml/compat/crt/RMLCrTLoader.java @@ -51,15 +51,16 @@ public class RMLCrTLoader { } } - public static LazyOptional> cachedScriptProviders = LazyOptional.of(() -> { - HashSet cachedScriptProvider = new HashSet<>(); + public static LazyOptional> cachedScriptProviders = LazyOptional.of(() -> { + HashSet cachedScriptProvider = new HashSet<>(); + RMLScriptProvider providerCustom = new RMLScriptProvider(); for(ContainerHolder containerHolder : ResourceModLoader.getCurrentRMLContainerHolders()){ if (containerHolder.modules.contains(ContainerHolder.Modules.MOD_CRT)){ final ModContainer modContainer = containerHolder.container; Loader.instance().setActiveModContainer(modContainer); - ScriptProviderCustom providerCustom=new ScriptProviderCustom(modContainer.getModId()); + FileHelper.findFiles(modContainer, "assets/" + modContainer.getModId() + "/crt", (root, file) -> { @@ -73,18 +74,18 @@ public class RMLCrTLoader { try{ byte[] fileBytes = FileHelper.getByteSource(file).read(); - providerCustom.add(name,fileBytes); + providerCustom.add(name, fileBytes); RMLFMLLoadingPlugin.Container.LOGGER.info("Injected {} for CrT",key); } catch (IOException e) { throw new RuntimeException(e); } }); - cachedScriptProvider.add(providerCustom); Loader.instance().setActiveModContainer(RMLFMLLoadingPlugin.Container.INSTANCE); } } + cachedScriptProvider.add(providerCustom); return cachedScriptProvider; }); diff --git a/src/main/java/mods/Hileb/rml/compat/crt/RMLScriptProvider.java b/src/main/java/mods/Hileb/rml/compat/crt/RMLScriptProvider.java new file mode 100644 index 0000000..ef790fb --- /dev/null +++ b/src/main/java/mods/Hileb/rml/compat/crt/RMLScriptProvider.java @@ -0,0 +1,92 @@ +package mods.Hileb.rml.compat.crt; + +import crafttweaker.runtime.IScriptIterator; +import crafttweaker.runtime.IScriptProvider; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Project ResourceModLoader + * @Author Hileb + * @Date 2024/3/16 20:49 + **/ +public class RMLScriptProvider implements IScriptProvider { + private final List scripts; + + public RMLScriptProvider() { + scripts = new ArrayList<>(); + } + + public void add(String name, byte[] content) { + scripts.add(new CustomScript(name, content)); + } + + @Override + public Iterator getScripts() { + return scripts.stream().map(CustomScript::iterator).collect(Collectors.toSet()).iterator(); + } + + private static class CustomScript { + + private final String name; + private final byte[] content; + + public CustomScript(String name, byte[] content) { + this.name = name; + this.content = content; + } + + public IScriptIterator iterator(){ + return new ScriptIteratorSingle(name, content); + } + } + + static class ScriptIteratorSingle implements IScriptIterator { + + private final byte[] file; + private final String name; + private boolean first = true; + + ScriptIteratorSingle(String name, byte[] file) { + this.file = file; + this.name = name; + } + + @Override + public String getGroupName() { + return name; + } + + @Override + public boolean next() { + if(first) { + first = false; + return true; + } else { + return false; + } + } + + @Override + public String getName() { + return name; + } + + @Override + public InputStream open() throws IOException { + return new BufferedInputStream(new ByteArrayInputStream(file)); + } + + @Override + public IScriptIterator copyCurrent() { + return new ScriptIteratorSingle(name, file); + } + } +} diff --git a/src/main/java/mods/Hileb/rml/core/RMLFMLLoadingPlugin.java b/src/main/java/mods/Hileb/rml/core/RMLFMLLoadingPlugin.java index 13f4e7c..3d74871 100644 --- a/src/main/java/mods/Hileb/rml/core/RMLFMLLoadingPlugin.java +++ b/src/main/java/mods/Hileb/rml/core/RMLFMLLoadingPlugin.java @@ -49,7 +49,7 @@ public class RMLFMLLoadingPlugin implements IFMLLoadingPlugin { public static File source; public static boolean isDebug; - @PublicAPI public static final Logger LOGGER= LogManager.getLogger(ResourceModLoader.MODID); + @PublicAPI public static final Logger LOGGER = LogManager.getLogger(ResourceModLoader.MODID); public RMLFMLLoadingPlugin(){ RMLBus.BUS.register(EventHandler.INSTANCE); @@ -106,7 +106,7 @@ public String getAccessTransformerClass() { @SuppressWarnings("unused") public static class Container extends DummyModContainer{ @PublicAPI public static Container INSTANCE; - @PublicAPI public static final Logger LOGGER= LogManager.getLogger(ResourceModLoader.MODID); + @PublicAPI public static final Logger LOGGER = RMLFMLLoadingPlugin.LOGGER; @PrivateAPI public Container(){ super(new ModMetadata()); ModMetadata metadata=this.getMetadata(); diff --git a/src/main/java/mods/Hileb/rml/core/RMLTransformer.java b/src/main/java/mods/Hileb/rml/core/RMLTransformer.java index 110e95a..92655ca 100644 --- a/src/main/java/mods/Hileb/rml/core/RMLTransformer.java +++ b/src/main/java/mods/Hileb/rml/core/RMLTransformer.java @@ -197,6 +197,12 @@ public int apply(ClassNode cn) { transformers.put("crafttweaker.mc1120.CraftTweaker", (cn)->{ for(MethodNode mn:cn.methods){ + /** + * @EventHandler + * public void onPreInitialization(FMLPreInitializationEvent ev) { + * CrTZenClassRegisterEvent.post(); + * PROXY.registerEvents(); + * **/ if ("onPreInitialization".equals(mn.name)){ InsnList hook = new InsnList(); hook.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/Hileb/rml/compat/crt/CrTZenClassRegisterEvent", "post", "()V", false)); @@ -209,6 +215,11 @@ public int apply(ClassNode cn) { transformers.put("net.minecraft.client.gui.GuiMainMenu", (cn)->{ for(MethodNode mn:cn.methods){ + /** + * try { + * List list = MCMainScreenTextLoader.inject(Lists.newArrayList()); + * iresource = Minecraft.getMinecraft().getResourceManager().getResource(SPLASH_TEXTS); + * **/ if ("".equals(mn.name)){ ListIterator iterator = mn.instructions.iterator(); AbstractInsnNode node; @@ -240,23 +251,6 @@ public int apply(ClassNode cn) { } return -1; }); - transformers.put("com.teamacronymcoders.base.registrysystem.Registry", - (cn)->{ - for(MethodNode mn:cn.methods){ - if ("register".equals(mn.name)){ - InsnList insnList = new InsnList(); - insnList.add(new VarInsnNode(Opcodes.ALOAD, 0)); - insnList.add(new FieldInsnNode(Opcodes.GETFIELD, "com/teamacronymcoders/base/registrysystem/Registry", "entries", "Ljava/util/Map;")); - insnList.add(new VarInsnNode(Opcodes.ALOAD, 1)); - insnList.add(new VarInsnNode(Opcodes.ALOAD, 2)); - insnList.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)); - insnList.add(new InsnNode(Opcodes.POP)); - insnList.add(new InsnNode(Opcodes.RETURN)); - mn.instructions = insnList; - } - } - return -1; - }); } @Override public byte[] transform(String name, String transformedName, byte[] basicClass) {