From 74801ef10bc160e395d6025f29d23498d2245082 Mon Sep 17 00:00:00 2001 From: QuImUfu Date: Thu, 6 Jul 2023 00:03:50 +0200 Subject: [PATCH] fix example generation --- .../GenericManualResourceLoader.java | 23 +++++++++++++++---- .../simple_creator/SimpleCreatorMod.java | 12 ++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/quimufu/simple_creator/GenericManualResourceLoader.java b/src/main/java/quimufu/simple_creator/GenericManualResourceLoader.java index 944fc62..049f1cb 100644 --- a/src/main/java/quimufu/simple_creator/GenericManualResourceLoader.java +++ b/src/main/java/quimufu/simple_creator/GenericManualResourceLoader.java @@ -2,15 +2,19 @@ package quimufu.simple_creator; import com.google.gson.Gson; import com.google.gson.JsonObject; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; import org.apache.logging.log4j.Level; import java.io.*; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Optional; +import static quimufu.simple_creator.SimpleCreatorMod.MOD_ID; import static quimufu.simple_creator.SimpleCreatorMod.log; public abstract class GenericManualResourceLoader { @@ -43,7 +47,7 @@ public abstract class GenericManualResourceLoader { public void load() { - if (true) { + if (SimpleCreatorConfig.enableTestThings) { createFromResource("simple_creator/blocks/test_block.json"); createFromResource("simple_creator/items/test_item.json"); } @@ -103,10 +107,21 @@ public abstract class GenericManualResourceLoader { } private static void createFromResource(String path) { - try (InputStream blocks = ClassLoader.getSystemClassLoader().getResourceAsStream("data/" + path)) { + Optional modContainerOp = FabricLoader.getInstance().getModContainer(MOD_ID); + if(modContainerOp.isEmpty()){ + log(Level.ERROR,"ModContainer " + MOD_ID + " not Found" ); + return; + } + Optional nioPath = modContainerOp + .flatMap(modContainer -> modContainer.findPath("data/" + path)); + if(nioPath.isEmpty()){ + log(Level.ERROR,"data/" + path + " Not Found" ); + return; + } + try (InputStream blocks = Files.newInputStream(nioPath.get())) { File file = new File("./simplyCreated/" + path); - if (!file.exists() && blocks != null) { + if (!file.exists()) { File parent = file.getParentFile(); if (parent != null && !parent.exists() && !parent.mkdirs()) { diff --git a/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java b/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java index 919438e..5902df2 100644 --- a/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java +++ b/src/main/java/quimufu/simple_creator/SimpleCreatorMod.java @@ -1,6 +1,12 @@ package quimufu.simple_creator; +import de.siphalor.tweed4.Tweed; +import de.siphalor.tweed4.config.ConfigEnvironment; +import de.siphalor.tweed4.config.ConfigLoader; +import de.siphalor.tweed4.config.TweedRegistry; +import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.util.Pair; import org.apache.logging.log4j.Level; @@ -23,6 +29,12 @@ public class SimpleCreatorMod implements ModInitializer { @Override public void onInitialize() { log(Level.INFO, "Initializing"); + Tweed.runEntryPoints(); + + ConfigLoader.initialReload( + TweedRegistry.getConfigFile(MOD_ID), + FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER ? ConfigEnvironment.SERVER : ConfigEnvironment.UNIVERSAL + ); irl.load(); brl.load(); }