mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
started work on assembler recipe handler overhaul
This commit is contained in:
parent
752df423fb
commit
e7df37f771
172
src/main/java/com/hbm/inventory/AssemblerRecipes.java
Normal file
172
src/main/java/com/hbm/inventory/AssemblerRecipes.java
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
package com.hbm.inventory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonIOException;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||||
|
import com.hbm.inventory.RecipesCommon.OreDictStack;
|
||||||
|
import com.hbm.main.MainRegistry;
|
||||||
|
|
||||||
|
public class AssemblerRecipes {
|
||||||
|
|
||||||
|
public static File config;
|
||||||
|
public static File template;
|
||||||
|
private static final Gson gson = new Gson();
|
||||||
|
public static HashMap<ComparableStack, Object[]> recipes = new HashMap();
|
||||||
|
public static HashMap<ComparableStack, Integer> time = new HashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-Init phase: Finds the recipe config (if exists) and checks if a template is present, if not it generates one.
|
||||||
|
* @param dir The suggested config folder
|
||||||
|
*/
|
||||||
|
public static void preInit(File dir) {
|
||||||
|
|
||||||
|
if(dir == null || !dir.isDirectory())
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<File> files = Arrays.asList(dir.listFiles());
|
||||||
|
|
||||||
|
boolean needsTemplate = true;
|
||||||
|
|
||||||
|
for(File file : files) {
|
||||||
|
if(file.getName().equals("hbmAssembler.json")) {
|
||||||
|
|
||||||
|
config = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.getName().equals("hbmAssemblerTemplate.json")) {
|
||||||
|
|
||||||
|
needsTemplate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(needsTemplate)
|
||||||
|
saveTemplateJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadRecipes() {
|
||||||
|
|
||||||
|
if(config == null)
|
||||||
|
registerDefaults();
|
||||||
|
else
|
||||||
|
loadJSONRecipes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerDefaults() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* recipes : [
|
||||||
|
* {
|
||||||
|
* output : [ "item", "hbm:tank_steel", 1, 0 ],
|
||||||
|
* duration : 100,
|
||||||
|
* input : [
|
||||||
|
* [ "dict", "plateSteel", 6 ],
|
||||||
|
* [ "dict", "plateTitanium", 2 ],
|
||||||
|
* [ "item", "dye", 1, 15 ],
|
||||||
|
* ]
|
||||||
|
* },
|
||||||
|
* {
|
||||||
|
* output : [ "item", "hbm:plate_gold", 2, 0 ],
|
||||||
|
* duration : 20,
|
||||||
|
* input : [
|
||||||
|
* [ "dict", "ingotGold", 3 ]
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
private static void loadJSONRecipes() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class);
|
||||||
|
|
||||||
|
JsonElement recipes = json.get("recipes");
|
||||||
|
|
||||||
|
if(recipes instanceof JsonArray) {
|
||||||
|
|
||||||
|
JsonArray recArray = recipes.getAsJsonArray();
|
||||||
|
|
||||||
|
//go through the recipes array
|
||||||
|
for(JsonElement recipe : recArray) {
|
||||||
|
|
||||||
|
if(recipe.isJsonObject()) {
|
||||||
|
|
||||||
|
JsonObject recObj = recipe.getAsJsonObject();
|
||||||
|
|
||||||
|
JsonElement input = recObj.get("input");
|
||||||
|
JsonElement output = recObj.get("output");
|
||||||
|
JsonElement duration = recObj.get("duration");
|
||||||
|
|
||||||
|
int time = 100;
|
||||||
|
|
||||||
|
if(duration.isJsonPrimitive()) {
|
||||||
|
if(duration.getAsJsonPrimitive().isNumber()) {
|
||||||
|
time = Math.max(1, duration.getAsJsonPrimitive().getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(input instanceof JsonArray)) {
|
||||||
|
MainRegistry.logger.error("Error reading recipe, no input found!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(output instanceof JsonArray)) {
|
||||||
|
MainRegistry.logger.error("Error reading recipe, no output found!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object outp = parseJsonArray(output.getAsJsonArray());
|
||||||
|
List inp = new ArrayList();
|
||||||
|
|
||||||
|
for(JsonElement in : input.getAsJsonArray()) {
|
||||||
|
|
||||||
|
if(in.isJsonArray()) {
|
||||||
|
Object i = parseJsonArray(in.getAsJsonArray());
|
||||||
|
|
||||||
|
if(i instanceof ComparableStack || i instanceof OreDictStack)
|
||||||
|
inp.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(outp instanceof ComparableStack) {
|
||||||
|
AssemblerRecipes.recipes.put((ComparableStack) outp, inp.toArray());
|
||||||
|
AssemblerRecipes.time.put((ComparableStack) outp, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
//shush
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object parseJsonArray(JsonArray array) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveJSONRecipes() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveTemplateJSON() {
|
||||||
|
|
||||||
|
//TODO: pending
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -132,4 +132,20 @@ public class RecipesCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class OreDictStack {
|
||||||
|
|
||||||
|
public String name;
|
||||||
|
public int stacksize;
|
||||||
|
|
||||||
|
public OreDictStack(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.stacksize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OreDictStack(String name, int stacksize) {
|
||||||
|
this(name);
|
||||||
|
this.stacksize = stacksize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,52 +151,6 @@ public class MainRegistry
|
|||||||
public static CreativeTabs consumableTab = new ConsumableTab(CreativeTabs.getNextID(), "tabConsumable");
|
public static CreativeTabs consumableTab = new ConsumableTab(CreativeTabs.getNextID(), "tabConsumable");
|
||||||
|
|
||||||
//Achievements
|
//Achievements
|
||||||
public static Achievement achCircuit0;
|
|
||||||
public static Achievement achCircuit1;
|
|
||||||
public static Achievement achCircuit2;
|
|
||||||
public static Achievement achCircuit3;
|
|
||||||
public static Achievement achCircuit4;
|
|
||||||
public static Achievement achCircuit5;
|
|
||||||
public static Achievement achJack;
|
|
||||||
public static Achievement achDalekanium;
|
|
||||||
public static Achievement achRefinery;
|
|
||||||
public static Achievement achBattery;
|
|
||||||
public static Achievement achOil;
|
|
||||||
public static Achievement achCatapult1;
|
|
||||||
public static Achievement achCatapult2;
|
|
||||||
public static Achievement achCatapult3;
|
|
||||||
public static Achievement achU235;
|
|
||||||
public static Achievement achPu238;
|
|
||||||
public static Achievement achPu239;
|
|
||||||
public static Achievement achNeptunium;
|
|
||||||
public static Achievement achDesh;
|
|
||||||
public static Achievement achMeteor;
|
|
||||||
public static Achievement achGeiger;
|
|
||||||
public static Achievement achDesignator;
|
|
||||||
public static Achievement achRemote;
|
|
||||||
public static Achievement achOverpowered;
|
|
||||||
public static Achievement achShimSham;
|
|
||||||
public static Achievement achMatchstick;
|
|
||||||
public static Achievement achRails;
|
|
||||||
public static Achievement achFolder;
|
|
||||||
public static Achievement achPress;
|
|
||||||
public static Achievement achFWatz;
|
|
||||||
public static Achievement achTurbofan;
|
|
||||||
public static Achievement achGadget;
|
|
||||||
public static Achievement achBoy;
|
|
||||||
public static Achievement achMan;
|
|
||||||
public static Achievement achMike;
|
|
||||||
public static Achievement achTsar;
|
|
||||||
public static Achievement achFLEIJA;
|
|
||||||
public static Achievement achPrototype;
|
|
||||||
public static Achievement achCustom;
|
|
||||||
public static Achievement achTurret;
|
|
||||||
public static Achievement achMeteorDeath;
|
|
||||||
public static Achievement achXenium;
|
|
||||||
public static Achievement achRadiation;
|
|
||||||
public static Achievement achSchrabidium;
|
|
||||||
public static Achievement achEuphemium;
|
|
||||||
|
|
||||||
public static Achievement achSacrifice;
|
public static Achievement achSacrifice;
|
||||||
public static Achievement achImpossible;
|
public static Achievement achImpossible;
|
||||||
public static Achievement achTOB;
|
public static Achievement achTOB;
|
||||||
@ -379,6 +333,7 @@ public class MainRegistry
|
|||||||
CellularDungeonFactory.init();
|
CellularDungeonFactory.init();
|
||||||
Satellite.register();
|
Satellite.register();
|
||||||
VersionChecker.checkVersion();
|
VersionChecker.checkVersion();
|
||||||
|
AssemblerRecipes.preInit(PreEvent.getModConfigurationDirectory());
|
||||||
|
|
||||||
Library.superuser.add("192af5d7-ed0f-48d8-bd89-9d41af8524f8");
|
Library.superuser.add("192af5d7-ed0f-48d8-bd89-9d41af8524f8");
|
||||||
Library.superuser.add("5aee1e3d-3767-4987-a222-e7ce1fbdf88e");
|
Library.superuser.add("5aee1e3d-3767-4987-a222-e7ce1fbdf88e");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user