Added JSON loading for Infusion Repair enchantment associations.
parent
ab663d10e4
commit
6c771e90b0
|
@ -9,6 +9,7 @@ import net.einsteinsci.betterbeginnings.network.PacketNetherBrickOvenFuelLevel;
|
|||
import net.einsteinsci.betterbeginnings.network.ServerProxy;
|
||||
import net.einsteinsci.betterbeginnings.register.*;
|
||||
import net.einsteinsci.betterbeginnings.register.achievement.RegisterAchievements;
|
||||
import net.einsteinsci.betterbeginnings.util.InfusionRepairUtil;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -87,6 +88,7 @@ public class ModMain
|
|||
RegisterRecipes.addShapedRecipes();
|
||||
RegisterRecipes.addAdvancedRecipes();
|
||||
RegisterRecipes.addFurnaceRecipes();
|
||||
InfusionRepairUtil.registerVanillaEnchantsConfig();
|
||||
|
||||
BBConfigFolderLoader.loadRecipes(e);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ public class BBConfigFolderLoader
|
|||
loadJsonConfig(e, BrickOvenConfig.INSTANCE);
|
||||
loadJsonConfig(e, AdvancedCraftingConfig.INSTANCE);
|
||||
loadJsonConfig(e, CampfireConfig.INSTANCE);
|
||||
loadJsonConfig(e, RepairInfusionConfig.INSTANCE);
|
||||
}
|
||||
|
||||
public static void loadJsonConfig(FMLInitializationEvent e, IJsonConfig config)
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.recipe.JsonRepairInfusionAssociation;
|
||||
import net.einsteinsci.betterbeginnings.config.json.recipe.JsonRepairInfusionHandler;
|
||||
import net.einsteinsci.betterbeginnings.util.FileUtil;
|
||||
import net.einsteinsci.betterbeginnings.util.LogUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RepairInfusionConfig implements IJsonConfig
|
||||
{
|
||||
public static final RepairInfusionConfig INSTANCE = new RepairInfusionConfig();
|
||||
|
||||
private static JsonRepairInfusionHandler initialAssociations = new JsonRepairInfusionHandler();
|
||||
|
||||
private JsonRepairInfusionHandler mainAssociations = new JsonRepairInfusionHandler();
|
||||
private JsonRepairInfusionHandler customAssociations = new JsonRepairInfusionHandler();
|
||||
|
||||
private List<JsonRepairInfusionHandler> includes = new ArrayList<>();
|
||||
|
||||
public static void registerEnchantment(int enchID, ItemStack associatedItem)
|
||||
{
|
||||
initialAssociations.getEnchantmentAssociations().add(new JsonRepairInfusionAssociation(enchID, associatedItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubFolder()
|
||||
{
|
||||
return "repairinfusion";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainJson(File subfolder)
|
||||
{
|
||||
File mainf = new File(subfolder, "main.json");
|
||||
String json = FileUtil.readAllText(mainf);
|
||||
if (json == null)
|
||||
{
|
||||
// Kind of inefficient, but it's easiest this way.
|
||||
json = BBJsonLoader.serializeObject(initialAssociations);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@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 : customAssociations.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)
|
||||
{
|
||||
mainAssociations = BBJsonLoader.deserializeObject(mainJson, JsonRepairInfusionHandler.class);
|
||||
for (JsonRepairInfusionAssociation j : mainAssociations.getEnchantmentAssociations())
|
||||
{
|
||||
j.register();
|
||||
}
|
||||
|
||||
customAssociations = BBJsonLoader.deserializeObject(customJson, JsonRepairInfusionHandler.class);
|
||||
for (JsonRepairInfusionAssociation r : customAssociations.getEnchantmentAssociations())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIncludedConfig(FMLInitializationEvent e, List<String> includedJsons)
|
||||
{
|
||||
for (String json : includedJsons)
|
||||
{
|
||||
JsonRepairInfusionHandler handler = BBJsonLoader.deserializeObject(json, JsonRepairInfusionHandler.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 (JsonRepairInfusionAssociation r : handler.getEnchantmentAssociations())
|
||||
{
|
||||
r.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePostLoad(File subfolder)
|
||||
{
|
||||
String json = BBJsonLoader.serializeObject(mainAssociations);
|
||||
File mainf = new File(subfolder, "main.json");
|
||||
FileUtil.overwriteAllText(mainf, json);
|
||||
}
|
||||
|
||||
public JsonRepairInfusionHandler getMainAssociations()
|
||||
{
|
||||
return mainAssociations;
|
||||
}
|
||||
|
||||
public JsonRepairInfusionHandler getCustomAssociations()
|
||||
{
|
||||
return customAssociations;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json.recipe;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.JsonLoadedItemStack;
|
||||
import net.einsteinsci.betterbeginnings.util.InfusionRepairUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class JsonRepairInfusionAssociation
|
||||
{
|
||||
private int enchantmentID;
|
||||
private JsonLoadedItemStack associatedItem;
|
||||
|
||||
public JsonRepairInfusionAssociation(int enchID, ItemStack stack)
|
||||
{
|
||||
enchantmentID = enchID;
|
||||
associatedItem = new JsonLoadedItemStack(stack);
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
InfusionRepairUtil.registerEnchantment(enchantmentID, associatedItem.getFirstItemStackOrNull());
|
||||
}
|
||||
|
||||
public int getEnchantmentID()
|
||||
{
|
||||
return enchantmentID;
|
||||
}
|
||||
|
||||
public JsonLoadedItemStack getAssociatedItem()
|
||||
{
|
||||
return associatedItem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package net.einsteinsci.betterbeginnings.config.json.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonRepairInfusionHandler
|
||||
{
|
||||
private List<JsonRepairInfusionAssociation> enchantmentAssociations = new ArrayList<>();
|
||||
|
||||
private List<String> includes = new ArrayList<>();
|
||||
private List<String> modDependencies = new ArrayList<>();
|
||||
|
||||
public List<JsonRepairInfusionAssociation> getEnchantmentAssociations()
|
||||
{
|
||||
return enchantmentAssociations;
|
||||
}
|
||||
|
||||
public List<String> getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
|
||||
public List<String> getModDependencies()
|
||||
{
|
||||
return modDependencies;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package net.einsteinsci.betterbeginnings.util;
|
||||
|
||||
import net.einsteinsci.betterbeginnings.config.json.RepairInfusionConfig;
|
||||
import net.einsteinsci.betterbeginnings.inventory.InventoryInfusionRepair;
|
||||
import net.einsteinsci.betterbeginnings.register.RegisterItems;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -9,12 +10,55 @@ import net.minecraft.item.*;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InfusionRepairUtil
|
||||
{
|
||||
public static Map<Integer, ItemStack> enchantmentMapping = new HashMap<>();
|
||||
|
||||
public static void registerVanillaEnchantsConfig()
|
||||
{
|
||||
RepairInfusionConfig.registerEnchantment(0, new ItemStack(Blocks.iron_bars, 2));
|
||||
RepairInfusionConfig.registerEnchantment(1, new ItemStack(Items.bucket));
|
||||
RepairInfusionConfig.registerEnchantment(2, new ItemStack(Items.feather, 2));
|
||||
RepairInfusionConfig.registerEnchantment(3, new ItemStack(Blocks.cobblestone, 8));
|
||||
RepairInfusionConfig.registerEnchantment(4, new ItemStack(Items.snowball, 4));
|
||||
RepairInfusionConfig.registerEnchantment(5, new ItemStack(Items.glass_bottle));
|
||||
RepairInfusionConfig.registerEnchantment(6, new ItemStack(Blocks.clay));
|
||||
RepairInfusionConfig.registerEnchantment(7, new ItemStack(Blocks.cactus, 4));
|
||||
RepairInfusionConfig.registerEnchantment(8, new ItemStack(Blocks.prismarine));
|
||||
|
||||
RepairInfusionConfig.registerEnchantment(16, new ItemStack(Items.quartz, 4));
|
||||
RepairInfusionConfig.registerEnchantment(17, new ItemStack(Blocks.soul_sand, 2));
|
||||
RepairInfusionConfig.registerEnchantment(18, new ItemStack(Items.fermented_spider_eye));
|
||||
RepairInfusionConfig.registerEnchantment(19, new ItemStack(Blocks.piston));
|
||||
RepairInfusionConfig.registerEnchantment(20, new ItemStack(Items.blaze_powder, 2));
|
||||
RepairInfusionConfig.registerEnchantment(21, new ItemStack(Items.gold_ingot, 2));
|
||||
|
||||
RepairInfusionConfig.registerEnchantment(32, new ItemStack(Items.sugar, 4));
|
||||
RepairInfusionConfig.registerEnchantment(33, new ItemStack(RegisterItems.cloth, 8));
|
||||
RepairInfusionConfig.registerEnchantment(34, new ItemStack(Blocks.obsidian));
|
||||
RepairInfusionConfig.registerEnchantment(35, new ItemStack(Items.dye, 4, 4));
|
||||
|
||||
RepairInfusionConfig.registerEnchantment(48, new ItemStack(RegisterItems.leatherStrip));
|
||||
RepairInfusionConfig.registerEnchantment(49, new ItemStack(Items.gunpowder));
|
||||
RepairInfusionConfig.registerEnchantment(50, new ItemStack(Items.fire_charge));
|
||||
RepairInfusionConfig.registerEnchantment(51, new ItemStack(Items.arrow, 16));
|
||||
|
||||
RepairInfusionConfig.registerEnchantment(61, new ItemStack(Blocks.waterlily));
|
||||
RepairInfusionConfig.registerEnchantment(62, new ItemStack(Items.fish, 1, 3));
|
||||
}
|
||||
|
||||
public static void registerEnchantment(int enchID, ItemStack stack)
|
||||
{
|
||||
enchantmentMapping.put(enchID, stack);
|
||||
}
|
||||
|
||||
public static boolean canRepair(InventoryInfusionRepair repairTable, EntityPlayer player)
|
||||
{
|
||||
return canRepairIgnoreXp(repairTable) && player.experienceLevel >= getNeededLevels(repairTable);
|
||||
|
@ -346,108 +390,22 @@ public class InfusionRepairUtil
|
|||
int enchId = enchant.getInteger("id");
|
||||
int level = enchant.getInteger("lvl");
|
||||
|
||||
switch (enchId)
|
||||
ItemStack associated = enchantmentMapping.get(enchId);
|
||||
|
||||
if (associated != null)
|
||||
{
|
||||
case 0: // Protection
|
||||
requiredItems.add(new ItemStack(Blocks.iron_bars, 2 * level));
|
||||
break;
|
||||
case 1: // Fire Protection
|
||||
requiredItems.add(new ItemStack(Items.bucket, level));
|
||||
break;
|
||||
case 2: // Feather Falling
|
||||
requiredItems.add(new ItemStack(Items.feather, 2 * level));
|
||||
break;
|
||||
case 3: // Blast Protection
|
||||
requiredItems.add(new ItemStack(Blocks.cobblestone, 8 * level));
|
||||
break;
|
||||
case 4: // Projectile Protection
|
||||
requiredItems.add(new ItemStack(Items.snowball, 4 * level));
|
||||
break;
|
||||
case 5: // Respiration
|
||||
requiredItems.add(new ItemStack(Items.glass_bottle, level));
|
||||
break;
|
||||
case 6: // Aqua Affinity
|
||||
requiredItems.add(new ItemStack(Blocks.clay, level));
|
||||
break;
|
||||
case 7: // Thorns
|
||||
requiredItems.add(new ItemStack(Blocks.cactus, 4 * level));
|
||||
break;
|
||||
case 8: // Depth Strider
|
||||
requiredItems.add(new ItemStack(Blocks.prismarine, level));
|
||||
break;
|
||||
case 16: // Sharpness
|
||||
requiredItems.add(new ItemStack(Items.quartz, 4 * level));
|
||||
break;
|
||||
case 17: // Smite
|
||||
requiredItems.add(new ItemStack(Blocks.soul_sand, 2 * level));
|
||||
break;
|
||||
case 18: // Anthropods
|
||||
requiredItems.add(new ItemStack(Items.fermented_spider_eye, level));
|
||||
break;
|
||||
case 19: // Knockback
|
||||
requiredItems.add(new ItemStack(Blocks.piston, level));
|
||||
break;
|
||||
case 20: // Fire Aspect
|
||||
requiredItems.add(new ItemStack(Items.blaze_powder, 2 * level));
|
||||
break;
|
||||
case 21: // Looting
|
||||
requiredItems.add(new ItemStack(Items.gold_ingot, 2 * level));
|
||||
break;
|
||||
case 32: // Efficiency
|
||||
requiredItems.add(new ItemStack(Items.sugar, 4 * level));
|
||||
break;
|
||||
case 33: // Silk Touch
|
||||
requiredItems.add(new ItemStack(RegisterItems.cloth, 8 * level));
|
||||
break;
|
||||
case 34: // Unbreaking
|
||||
requiredItems.add(new ItemStack(Blocks.obsidian, level));
|
||||
break;
|
||||
case 35: // Fortune
|
||||
requiredItems.add(new ItemStack(Items.dye, 4 * level, 4));
|
||||
break;
|
||||
case 48: // Power
|
||||
requiredItems.add(new ItemStack(RegisterItems.leatherStrip, level));
|
||||
break;
|
||||
case 49: // Punch
|
||||
requiredItems.add(new ItemStack(Items.gunpowder, level));
|
||||
break;
|
||||
case 50: // Flame
|
||||
requiredItems.add(new ItemStack(Items.fire_charge, level));
|
||||
break;
|
||||
case 51: // Infinity
|
||||
requiredItems.add(new ItemStack(Items.arrow, 16 * level));
|
||||
break;
|
||||
case 61: // Luck of the Sea
|
||||
requiredItems.add(new ItemStack(Blocks.waterlily, level));
|
||||
break;
|
||||
case 62: // Lure
|
||||
requiredItems.add(new ItemStack(Items.fish, level, 3));
|
||||
break;
|
||||
ItemStack req = new ItemStack(associated.getItem(), associated.stackSize * level, associated.getMetadata());
|
||||
requiredItems.add(req);
|
||||
}
|
||||
else
|
||||
{
|
||||
//LogUtil.log(Level.ERROR, "No repair infusion item associated with enchantment #" + enchId); // This spams the console
|
||||
}
|
||||
}
|
||||
|
||||
return requiredItems;
|
||||
}
|
||||
|
||||
/* // unsure
|
||||
public static List<ItemStack> getItemsFromEnchants(ItemStack stack)
|
||||
{
|
||||
if (stack.isItemEnchanted())
|
||||
{
|
||||
if (stack.getTagCompound() != null)
|
||||
{
|
||||
if (stack.getTagCompound().getTag("ench") != null)
|
||||
{
|
||||
NBTTagList enchants = (NBTTagList)stack.getTagCompound().getTag("ench");
|
||||
return getEnchantmentItems(enchants);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(); // empty
|
||||
}
|
||||
*/
|
||||
|
||||
public static boolean isToolValidForDiffusion(ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
|
|
Loading…
Reference in New Issue