Skip to content

Commit

Permalink
Nice! All 1.18 ore-gen recreated using my data driven system
Browse files Browse the repository at this point in the history
  • Loading branch information
EwyBoy committed Jan 13, 2022
1 parent d7f7885 commit 847243f
Show file tree
Hide file tree
Showing 31 changed files with 79 additions and 747 deletions.
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# 3.0.0 Update
[x] - Create Rarity system
[ ] - Recreate all vanilla features in 1.18 format
[x] - Recreate all vanilla features in 1.18 format
[x] - Dimension Filter
[x] - Reimplement Deepslater
[x] - Filler Tag system
[x] - Clean up legacy stuff
[x] - Capitalize TAGS
[ ] - Clean up Reconstructor
[ ] - Unfuck Mojang's fucked up ore veins
[ ] - Clean up legacy stuff
7 changes: 2 additions & 5 deletions src/main/java/com/ewyboy/oretweaker/OreTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import com.ewyboy.oretweaker.json.InfoHandler;
import com.ewyboy.oretweaker.json.JSONHandler;
import com.ewyboy.oretweaker.json.template.Templates;
import com.ewyboy.oretweaker.config.tweaking.OreManager;
import com.ewyboy.oretweaker.tweaking.OreManager;
import com.ewyboy.oretweaker.util.ModLogger;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.file.Files;

Expand All @@ -31,16 +29,15 @@ public OreTweaker() {
DirectoryHandler.setup();
Settings.setup();
Templates.setup();
JSONHandler.setup();
InfoHandler.setup();
OreManager.setup();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this :: loadComplete);
}

private static void isFirstTimeSetup() {
if (!Files.exists(DirectoryHandler.ORE_TWEAKER_PATH)) {
initSetup = true;
ModLogger.info("Ore Tweaker detected time setup!");
initSetup = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public class DirectoryHandler {

public static final Path ORE_TWEAKER_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath().toString(), OreTweaker.MOD_ID);
public static final Path TEMPLATE_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID, "templates");
public static final Path DATA_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID, "data");
public static final Path BACKUP_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID, "backup");
public static final Path DATA_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID, "data");

public static void setup() {
createDirectories(ORE_TWEAKER_PATH);
createDirectories(TEMPLATE_PATH);
createDirectories(BACKUP_PATH);
createDirectories(DATA_PATH);
}

Expand Down
43 changes: 1 addition & 42 deletions src/main/java/com/ewyboy/oretweaker/json/JSONHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@

public class JSONHandler {

public static boolean isAutoUpdating = false;

private static final Gson gson = new Gson();
public static final File OLD_JSON = new File(FMLPaths.CONFIGDIR.get() + "/oretweaker/OreTweaker.json");

public static OreConfig oreConfig = new OreConfig(new ArrayList<>());

public static void loadComplete() {
if (Settings.SETTINGS.regenerateDefaultSettings.get() && !isAutoUpdating) {
if (Settings.SETTINGS.regenerateDefaultSettings.get()) {
Templates.regenerateDefaultDataFromTemplate();
}

Expand All @@ -52,44 +49,6 @@ public static void readAllFiles() {
ModLogger.info(oreConfig.toString());
}

private static void autoUpdater() {
if (OLD_JSON.exists()) {
isAutoUpdating = true;
ModLogger.info("Auto updating OreTweaker to v2 data structure!");
try (Reader reader = new FileReader(OLD_JSON)) {
OreConfig oldConfig = gson.fromJson(reader, OreConfig.class);
oldConfig.getOreConfig().forEach(JSONHandler :: generateJSON);
} catch (IOException e) {
e.printStackTrace();
}
DirectoryHandler.createDirectories(DirectoryHandler.BACKUP_PATH);
OLD_JSON.renameTo(new File(FMLPaths.CONFIGDIR.get() + "/oretweaker/backup/OreTweaker.json"));
}
}

public static void generateJSON(OreEntry entry) {
String fileName = entry.getOre().split(":")[1].toLowerCase(Locale.ROOT);
File file = new File(FMLPaths.CONFIGDIR.get() + "/oretweaker/data/" + fileName + ".json");
List<OreEntry> oreList = new ArrayList<>();

if (file.exists()) {
try (Reader reader = new FileReader(file)) {
OreConfig config = gson.fromJson(reader, OreConfig.class);
oreList.addAll(config.getOreConfig());
} catch (IOException e) {
e.printStackTrace();
}
}

ModLogger.info("Creating Ore Tweaker Data File: " + fileName);
oreList.add(entry);
JSONHandler.writeJson(file, new OreConfig(oreList));
}

public static void setup() {
autoUpdater();
}

public static boolean containsEntry(OreEntry entry) {
for (OreEntry ore : oreConfig.getOreConfig()) {
if (ore.getOre().equals(entry.getOre()) && ore.isReplace()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import com.ewyboy.oretweaker.json.objects.OreEntry;

import java.nio.file.Path;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public interface ITemplate {

List<String> emptyList = new LinkedList<>();
List<String> emptyList = Collections.emptyList();

public String templateName();

Expand Down
16 changes: 5 additions & 11 deletions src/main/java/com/ewyboy/oretweaker/json/template/Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import com.ewyboy.oretweaker.json.DirectoryHandler;
import com.ewyboy.oretweaker.json.JSONHandler;
import com.ewyboy.oretweaker.json.objects.OreConfig;
import com.ewyboy.oretweaker.json.template.templates.collectives.DefaultNetherTemplate;
import com.ewyboy.oretweaker.json.template.templates.collectives.DefaultOverworldTemplate;
import com.ewyboy.oretweaker.json.template.templates.collectives.DefaultTemplate;
import com.ewyboy.oretweaker.json.template.templates.defaults.common.GravelTweak;
import com.ewyboy.oretweaker.json.template.templates.defaults.nether.ore.AncientDebrisTweak;
import com.ewyboy.oretweaker.json.template.templates.defaults.nether.ore.NetherGoldOreTweak;
Expand Down Expand Up @@ -45,9 +42,6 @@ public class Templates {
public static final List<String> BADLANDS = Arrays.asList("minecraft:badlands", "minecraft:eroded_badlands", "minecraft:wooded_badlands");

public static final class GeneratedTemplates {
public static final DefaultTemplate DEFAULT_TEMPLATE = new DefaultTemplate();
public static final DefaultNetherTemplate DEFAULT_NETHER_TEMPLATE = new DefaultNetherTemplate();
public static final DefaultOverworldTemplate DEFAULT_OVERWORLD_TEMPLATE = new DefaultOverworldTemplate();

public static final RemoveAllOres REMOVE_ALL_ORES = new RemoveAllOres();
public static final RemoveAllOresNether REMOVE_ALL_ORES_NETHER = new RemoveAllOresNether();
Expand Down Expand Up @@ -121,15 +115,15 @@ public static final class DefaultData {
public static final GravelTweak GRAVEL_TWEAK = new GravelTweak();
}

private static final String Templates = FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID + "/templates";

public static final class Directories {
public static final Path COLLECTIVES_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID + "/templates", "collectives");
public static final Path DEFAULTS_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID + "/templates", "defaults");
public static final Path REMOVE_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID + "/templates", "remove");
public static final Path OTHER_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath() + "/" + OreTweaker.MOD_ID + "/templates", "other");
public static final Path DEFAULTS_PATH = Paths.get(Templates, "defaults");
public static final Path REMOVE_PATH = Paths.get(Templates, "remove");
public static final Path OTHER_PATH = Paths.get(Templates, "other");
}

public static void setupDirectories() {
DirectoryHandler.createDirectories(Directories.COLLECTIVES_PATH);
DirectoryHandler.createDirectories(Directories.DEFAULTS_PATH);
DirectoryHandler.createDirectories(Directories.REMOVE_PATH);
DirectoryHandler.createDirectories(Directories.OTHER_PATH);
Expand Down

This file was deleted.

Loading

0 comments on commit 847243f

Please sign in to comment.