fix example generation

This commit is contained in:
QuImUfu 2023-07-06 00:03:50 +02:00
parent 7f2f3692c3
commit 74801ef10b
2 changed files with 31 additions and 4 deletions

View File

@ -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<T> {
@ -43,7 +47,7 @@ public abstract class GenericManualResourceLoader<T> {
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<T> {
}
private static void createFromResource(String path) {
try (InputStream blocks = ClassLoader.getSystemClassLoader().getResourceAsStream("data/" + path)) {
Optional<ModContainer> modContainerOp = FabricLoader.getInstance().getModContainer(MOD_ID);
if(modContainerOp.isEmpty()){
log(Level.ERROR,"ModContainer " + MOD_ID + " not Found" );
return;
}
Optional<Path> 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()) {

View File

@ -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();
}