I'M BACK BABY! JSON loading for smelter complete.
parent
4641e15630
commit
7a22bc6cd0
|
@ -3,6 +3,7 @@ package net.einsteinsci.betterbeginnings.config;
|
|||
import net.einsteinsci.betterbeginnings.config.json.BBJsonLoader;
|
||||
import net.einsteinsci.betterbeginnings.config.json.IJsonConfig;
|
||||
import net.einsteinsci.betterbeginnings.config.json.KilnConfig;
|
||||
import net.einsteinsci.betterbeginnings.config.json.SmelterConfig;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
|
@ -24,9 +25,7 @@ public class BBConfigFolderLoader
|
|||
configFolder = new File(e.getModConfigurationDirectory(), FOLDERNAME);
|
||||
|
||||
File file = new File(e.getModConfigurationDirectory(), FOLDERNAME + "/" + CONFIG_FILENAME);
|
||||
Configuration res = new Configuration(file);
|
||||
|
||||
return res;
|
||||
return new Configuration(file);
|
||||
}
|
||||
|
||||
public static void loadRecipes(FMLInitializationEvent e)
|
||||
|
@ -34,6 +33,7 @@ public class BBConfigFolderLoader
|
|||
BBJsonLoader.initialize();
|
||||
|
||||
loadJsonConfig(e, KilnConfig.INSTANCE);
|
||||
loadJsonConfig(e, SmelterConfig.INSTANCE);
|
||||
}
|
||||
|
||||
public static void loadJsonConfig(FMLInitializationEvent e, IJsonConfig config)
|
||||
|
|
|
@ -16,7 +16,7 @@ public class JsonKilnRecipeHandler
|
|||
recipes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY
|
||||
//recipes.add(new JsonKilnRecipe(new ItemStack(Blocks.bedrock), new ItemStack(Items.blaze_rod), 0.5f));
|
||||
recipes.add(new JsonKilnRecipe(new ItemStack(Blocks.bedrock), new ItemStack(Items.blaze_rod), 0.5f));
|
||||
}
|
||||
|
||||
public List<JsonKilnRecipe> getRecipes()
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.register.recipe.KilnRecipeHandler;
|
||||
import net.einsteinsci.betterbeginnings.register.recipe.SmelterRecipeHandler;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonSmelterRecipe
|
||||
{
|
||||
private JsonLoadedItem input;
|
||||
private JsonLoadedItemStack output;
|
||||
private float experience;
|
||||
private int boosterCount;
|
||||
private int bonusPerBoostLevel;
|
||||
|
||||
public JsonSmelterRecipe(JsonLoadedItem input, JsonLoadedItemStack output, float xp, int boosters, int bonus)
|
||||
{
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
experience = xp;
|
||||
boosterCount = boosters;
|
||||
bonusPerBoostLevel = bonus;
|
||||
}
|
||||
public JsonSmelterRecipe(ItemStack input, ItemStack output, float xp, int boosters, int bonus)
|
||||
{
|
||||
this(new JsonLoadedItem(input), new JsonLoadedItemStack(output), xp, boosters, bonus);
|
||||
}
|
||||
|
||||
public JsonLoadedItem getInput()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
public JsonLoadedItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
public int getBoosterCount()
|
||||
{
|
||||
return boosterCount;
|
||||
}
|
||||
|
||||
public int getBonusPerBoostLevel()
|
||||
{
|
||||
return bonusPerBoostLevel;
|
||||
}
|
||||
|
||||
public float getExperience()
|
||||
{
|
||||
return experience;
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
List<ItemStack> possibleOutputs = output.getItemStacks();
|
||||
if (possibleOutputs.isEmpty())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "No matching item found for output '" + output.getItemName() + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.isOreDictionary())
|
||||
{
|
||||
SmelterRecipeHandler.addRecipe(input.getItemName(), possibleOutputs.get(0),
|
||||
experience, boosterCount, bonusPerBoostLevel);
|
||||
LogUtil.logDebug("Successfully loaded smelter recipe (OreDictionary) for " + possibleOutputs.get(0).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ItemStack> possibleInputs = input.getItemStacks();
|
||||
if (possibleInputs.isEmpty())
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "No matching item found for input '" + input.getItemName() + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
SmelterRecipeHandler.addRecipe(possibleInputs.get(0), possibleOutputs.get(0),
|
||||
experience, boosterCount, bonusPerBoostLevel);
|
||||
LogUtil.logDebug("Successfully loaded smelter recipe for " + possibleOutputs.get(0).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonSmelterRecipeHandler
|
||||
{
|
||||
private List<JsonSmelterRecipe> recipes;
|
||||
|
||||
public JsonSmelterRecipeHandler()
|
||||
{
|
||||
recipes = new ArrayList<>();
|
||||
|
||||
// TESTING ONLY
|
||||
recipes.add(new JsonSmelterRecipe(new ItemStack(Blocks.bedrock), new ItemStack(Items.golden_hoe), 0.5f, 1, 0));
|
||||
}
|
||||
|
||||
public List<JsonSmelterRecipe> getRecipes()
|
||||
{
|
||||
return recipes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public class SmelterConfig implements IJsonConfig
|
||||
{
|
||||
public static final SmelterConfig INSTANCE = new SmelterConfig();
|
||||
|
||||
private JsonSmelterRecipeHandler mainRecipes = new JsonSmelterRecipeHandler();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
{
|
||||
return "smelter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainJson(File subfolder)
|
||||
{
|
||||
File mainf = new File(subfolder, "main.json");
|
||||
if (!mainf.exists())
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new String(Files.readAllBytes(mainf.toPath()));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred opening config/betterbeginnings/smelter/main.json!");
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, e.toString());
|
||||
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoJson(File subfolder)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomJson(File subfolder)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyMain()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadJsonConfig(FMLInitializationEvent e, String mainJson, String autoJson, String customJson)
|
||||
{
|
||||
mainRecipes = BBJsonLoader.deserializeObject(mainJson, JsonSmelterRecipeHandler.class);
|
||||
|
||||
for (JsonSmelterRecipe j : mainRecipes.getRecipes())
|
||||
{
|
||||
j.register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
String json = BBJsonLoader.serializeObject(mainRecipes);
|
||||
|
||||
try
|
||||
{
|
||||
File mainf = new File(subfolder, "main.json");
|
||||
Files.write(mainf.toPath(), json.getBytes(), StandardOpenOption.CREATE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "IOException occurred saving config/betterbeginnings/smelter/main.json!");
|
||||
LogUtil.log("");
|
||||
LogUtil.log(Level.ERROR, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public JsonSmelterRecipeHandler getMainRecipes()
|
||||
{
|
||||
return mainRecipes;
|
||||
}
|
||||
}
|
|
@ -104,7 +104,12 @@ public class BBEventHandler
|
|||
|
||||
if (item == RegisterItems.rotisserie)
|
||||
{
|
||||
e.toolTip.add(ChatUtil.WHITE + "Cooks food at the cost of speed");
|
||||
e.toolTip.add(ChatUtil.WHITE + "Cooks food like a pan at the cost of speed");
|
||||
}
|
||||
|
||||
if (item == RegisterItems.roastingStick)
|
||||
{
|
||||
e.toolTip.add(ChatUtil.WHITE + "Right-click to impale a marshmallow.");
|
||||
}
|
||||
|
||||
if (item == Items.sugar)
|
||||
|
|
|
@ -7,7 +7,9 @@ public class SmelterRecipe
|
|||
private ItemStack outputStack;
|
||||
private ItemStack inputStack;
|
||||
private float experienceGiven;
|
||||
// Booster items consumed per smelting operation
|
||||
private int boostersNeeded;
|
||||
// Bonus items given per level of boost upon smelting
|
||||
private int bonusPerBoost;
|
||||
|
||||
public SmelterRecipe(ItemStack output, ItemStack input, float experience, int boosters, int bonus)
|
||||
|
|
Loading…
Reference in New Issue