Added JSON config support for removing furnace and vanilla crafting recipes.
parent
461a2f3040
commit
ad869b89a9
|
@ -84,7 +84,14 @@ public class ModMain
|
|||
{
|
||||
proxy.init(e);
|
||||
|
||||
BBConfigFolderLoader.loadRemovedRecipes(e);
|
||||
|
||||
RemoveRecipes.remove();
|
||||
if (BBConfig.moduleFurnaces)
|
||||
{
|
||||
RemoveRecipes.removeFurnaceRecipes();
|
||||
}
|
||||
|
||||
RegisterRecipes.addShapelessRecipes();
|
||||
RegisterRecipes.addShapedRecipes();
|
||||
RegisterRecipes.addAdvancedRecipes();
|
||||
|
@ -94,11 +101,6 @@ public class ModMain
|
|||
|
||||
BBConfigFolderLoader.loadRecipes(e);
|
||||
|
||||
if (BBConfig.moduleFurnaces)
|
||||
{
|
||||
RemoveRecipes.removeFurnaceRecipes();
|
||||
}
|
||||
|
||||
if (e.getSide() == Side.CLIENT)
|
||||
{
|
||||
RegisterModels.register();
|
||||
|
|
|
@ -28,8 +28,6 @@ public class BBConfigFolderLoader
|
|||
|
||||
public static void loadRecipes(FMLInitializationEvent e)
|
||||
{
|
||||
BBJsonLoader.initialize();
|
||||
|
||||
loadJsonConfig(e, KilnConfig.INSTANCE);
|
||||
loadJsonConfig(e, SmelterConfig.INSTANCE);
|
||||
loadJsonConfig(e, BrickOvenConfig.INSTANCE);
|
||||
|
@ -39,6 +37,14 @@ public class BBConfigFolderLoader
|
|||
loadJsonConfig(e, BoosterConfig.INSTANCE);
|
||||
}
|
||||
|
||||
// Should be run before RemoveRecipes.remove() and .removeFurnaceRecipes()
|
||||
public static void loadRemovedRecipes(FMLInitializationEvent e)
|
||||
{
|
||||
BBJsonLoader.initialize();
|
||||
|
||||
loadJsonConfig(e, RemovalConfig.INSTANCE);
|
||||
}
|
||||
|
||||
public static void loadJsonConfig(FMLInitializationEvent e, IJsonConfig config)
|
||||
{
|
||||
File subfolder = new File(configFolder, config.getSubFolder());
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.recipe.JsonRemoveRecipesHandler;
|
||||
import net.einsteinsci.betterbeginnings.config.json.recipe.JsonRemovedCraftingRecipe;
|
||||
import net.einsteinsci.betterbeginnings.config.json.recipe.JsonRemovedSmeltingRecipe;
|
||||
import net.einsteinsci.betterbeginnings.util.FileUtil;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemovalConfig implements IJsonConfig
|
||||
{
|
||||
public static final RemovalConfig INSTANCE = new RemovalConfig();
|
||||
|
||||
private JsonRemoveRecipesHandler customRecipes = new JsonRemoveRecipesHandler();
|
||||
|
||||
private List<JsonRemoveRecipesHandler> includes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
{
|
||||
return "Remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainJson(File subfolder)
|
||||
{
|
||||
return "{}"; // No main, only custom.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoJson(File subfolder)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomJson(File subfolder)
|
||||
{
|
||||
File customf = new File(subfolder, "custom.json");
|
||||
String json = FileUtil.readAllText(customf);
|
||||
if (json == null)
|
||||
{
|
||||
json = "{}";
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludedJson(File subfolder)
|
||||
{
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String fileName : customRecipes.getIncludes())
|
||||
{
|
||||
File incf = new File(subfolder, fileName);
|
||||
String json = FileUtil.readAllText(incf);
|
||||
res.add(json);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadJsonConfig(FMLInitializationEvent e, String mainJson, String autoJson, String customJson)
|
||||
{
|
||||
// no main, only custom.
|
||||
|
||||
customRecipes = BBJsonLoader.deserializeObject(customJson, JsonRemoveRecipesHandler.class);
|
||||
for (JsonRemovedCraftingRecipe r : customRecipes.getCraftingRemoved())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
for (JsonRemovedSmeltingRecipe r : customRecipes.getSmeltingRemoved())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonRemoveRecipesHandler handler = BBJsonLoader.deserializeObject(json, JsonRemoveRecipesHandler.class);
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
LogUtil.log(Level.ERROR, "Could not deserialize included json.");
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean missingDependencies = false;
|
||||
for (String mod : handler.getModDependencies())
|
||||
{
|
||||
if (!Loader.isModLoaded(mod))
|
||||
{
|
||||
LogUtil.log(Level.WARN, "Mod '" + mod + "' missing, skipping all recipes in file.");
|
||||
missingDependencies = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (missingDependencies)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
includes.add(handler);
|
||||
|
||||
for (JsonRemovedCraftingRecipe r : handler.getCraftingRemoved())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
for (JsonRemovedSmeltingRecipe r : handler.getSmeltingRemoved())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
String json = BBJsonLoader.serializeObject(customRecipes);
|
||||
File customf = new File(subfolder, "custom.json");
|
||||
if (Files.notExists(customf.toPath()))
|
||||
{
|
||||
FileUtil.overwriteAllText(customf, json);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonRemoveRecipesHandler getCustomRecipes()
|
||||
{
|
||||
return customRecipes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json.recipe;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.register.RegisterItems;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonRemoveRecipesHandler
|
||||
{
|
||||
List<JsonRemovedCraftingRecipe> craftingRemoved = new ArrayList<>();
|
||||
List<JsonRemovedSmeltingRecipe> smeltingRemoved = new ArrayList<>();
|
||||
|
||||
List<String> includes = new ArrayList<>();
|
||||
List<String> modDependencies = new ArrayList<>();
|
||||
|
||||
String __COMMENT = "Add items whose recipes you want to remove below. This does not affect recipes removed by " +
|
||||
"BetterBeginnings through regular config. Some examples are provided above (both of which have no recipe already).";
|
||||
|
||||
public JsonRemoveRecipesHandler()
|
||||
{
|
||||
// Some examples
|
||||
craftingRemoved.add(new JsonRemovedCraftingRecipe(new ItemStack(Blocks.barrier)));
|
||||
smeltingRemoved.add(new JsonRemovedSmeltingRecipe(new ItemStack(RegisterItems.testItem)));
|
||||
}
|
||||
|
||||
public List<JsonRemovedCraftingRecipe> getCraftingRemoved()
|
||||
{
|
||||
return craftingRemoved;
|
||||
}
|
||||
|
||||
public List<JsonRemovedSmeltingRecipe> getSmeltingRemoved()
|
||||
{
|
||||
return smeltingRemoved;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
|
||||
public List<String> getModDependencies()
|
||||
{
|
||||
return modDependencies;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json.recipe;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.JsonLoadedItem;
|
||||
import net.einsteinsci.betterbeginnings.register.RemoveRecipes;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class JsonRemovedCraftingRecipe
|
||||
{
|
||||
public JsonLoadedItem removedItem;
|
||||
|
||||
public JsonRemovedCraftingRecipe(ItemStack stack)
|
||||
{
|
||||
removedItem = new JsonLoadedItem(stack);
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
for (ItemStack rem : removedItem.getItemStacks())
|
||||
{
|
||||
RemoveRecipes.getCustomRemovedCraftingRecipes().add(rem);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonLoadedItem getRemovedItem()
|
||||
{
|
||||
return removedItem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json.recipe;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.JsonLoadedItem;
|
||||
import net.einsteinsci.betterbeginnings.register.RemoveRecipes;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class JsonRemovedSmeltingRecipe
|
||||
{
|
||||
public JsonLoadedItem removedItem;
|
||||
|
||||
public JsonRemovedSmeltingRecipe(ItemStack stack)
|
||||
{
|
||||
removedItem = new JsonLoadedItem(stack);
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
for (ItemStack rem : removedItem.getItemStacks())
|
||||
{
|
||||
RemoveRecipes.getCustomRemovedFurnaceRecipes().add(rem);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonLoadedItem getRemovedItem()
|
||||
{
|
||||
return removedItem;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,22 @@
|
|||
package net.einsteinsci.betterbeginnings.register;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.BBConfig;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.einsteinsci.betterbeginnings.util.RegistryUtil;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.*;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RemoveRecipes
|
||||
{
|
||||
static List<ItemStack> customRemovedCraftingRecipes = new ArrayList<>();
|
||||
static List<ItemStack> customRemovedFurnaceRecipes = new ArrayList<>();
|
||||
|
||||
public static void remove()
|
||||
{
|
||||
List<Item> removedRecipes = new ArrayList<>();
|
||||
|
@ -158,11 +164,11 @@ public class RemoveRecipes
|
|||
while (iterator.hasNext())
|
||||
{
|
||||
IRecipe recipe = iterator.next();
|
||||
ItemStack stack = recipe.getRecipeOutput();
|
||||
ItemStack result = recipe.getRecipeOutput();
|
||||
|
||||
if (stack != null)
|
||||
if (result != null)
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
Item item = result.getItem();
|
||||
if (item == Item.getItemFromBlock(Blocks.crafting_table) &&
|
||||
recipe.getRecipeSize() != 4)
|
||||
{
|
||||
|
@ -170,6 +176,24 @@ public class RemoveRecipes
|
|||
}
|
||||
|
||||
if (item != null && removedRecipes.contains(item))
|
||||
{
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean removeMe = false;
|
||||
for (ItemStack customRemoved : customRemovedCraftingRecipes)
|
||||
{
|
||||
if (RegistryUtil.areItemStacksEqualIgnoreSize(customRemoved, result))
|
||||
{
|
||||
LogUtil.logDebug(Level.INFO, "Custom removed crafting recipe for " + result.getDisplayName());
|
||||
|
||||
removeMe = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeMe)
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
|
@ -230,8 +254,38 @@ public class RemoveRecipes
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map recipes = FurnaceRecipes.instance().getSmeltingList();
|
||||
Iterator iterator = recipes.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)iterator.next();
|
||||
ItemStack result = (ItemStack)entry.getValue();
|
||||
boolean removeMe = false;
|
||||
for (ItemStack customRemoved : customRemovedFurnaceRecipes)
|
||||
{
|
||||
if (RegistryUtil.areItemStacksEqualIgnoreSize(customRemoved, result))
|
||||
{
|
||||
removeMe = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeMe)
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ItemStack> getCustomRemovedCraftingRecipes()
|
||||
{
|
||||
return customRemovedCraftingRecipes;
|
||||
}
|
||||
|
||||
// Buffer
|
||||
public static List<ItemStack> getCustomRemovedFurnaceRecipes()
|
||||
{
|
||||
return customRemovedFurnaceRecipes;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class RegistryUtil
|
||||
{
|
||||
|
@ -62,4 +63,19 @@ public class RegistryUtil
|
|||
|
||||
return getForgeName(stack.getItem());
|
||||
}
|
||||
|
||||
public static boolean areItemStacksEqualIgnoreSize(ItemStack template, ItemStack tested)
|
||||
{
|
||||
if (template == null)
|
||||
{
|
||||
return tested == null;
|
||||
}
|
||||
else if (tested == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return template.getItem() == tested.getItem() && (template.getMetadata() == tested.getMetadata() ||
|
||||
template.getMetadata() == OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue