From 3b2ffc06716433fcf84de2b078f08e24076744d0 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 20 Feb 2019 15:13:04 +0200 Subject: [PATCH] Rewrite gem recipes to pull from named pools of like items. It's not about the items, it's about the traits. --- .../com/minelittlepony/unicopia/Unicopia.java | 3 + .../enchanting/AffineIngredients.java | 64 +++++++++++++++++++ .../unicopia/enchanting/SpellIngredient.java | 7 +- .../enchanting/ingredients/blood.json | 11 ++++ .../unicopia/enchanting/ingredients/dark.json | 9 +++ .../enchanting/ingredients/energy.json | 8 +++ .../unicopia/enchanting/ingredients/fire.json | 10 +++ .../unicopia/enchanting/ingredients/ice.json | 7 ++ .../unicopia/enchanting/ingredients/life.json | 10 +++ .../enchanting/ingredients/light.json | 6 ++ .../unicopia/enchanting/ingredients/rot.json | 10 +++ .../enchanting/ingredients/shard.json | 7 ++ .../enchanting/ingredients/shell.json | 8 +++ .../enchanting/ingredients/sight.json | 8 +++ .../enchanting/ingredients/unaligned.json | 9 +++ .../unicopia/enchanting/recipes/awkward.json | 15 +++++ .../unicopia/enchanting/recipes/charge.json | 4 +- .../unicopia/enchanting/recipes/drake.json | 1 + .../unicopia/enchanting/recipes/fire.json | 6 +- .../unicopia/enchanting/recipes/ice.json | 6 +- .../unicopia/enchanting/recipes/inferno.json | 4 +- .../unicopia/enchanting/recipes/light.json | 9 ++- .../enchanting/recipes/necromancy.json | 6 +- .../unicopia/enchanting/recipes/portal.json | 4 +- .../enchanting/recipes/repulsion.json | 6 +- .../unicopia/enchanting/recipes/shield.json | 6 +- .../enchanting/recipes/suffering.json | 1 + .../unicopia/enchanting/recipes/vortex.json | 2 +- 28 files changed, 222 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/enchanting/AffineIngredients.java create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/blood.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/dark.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/energy.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/fire.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/ice.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/life.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/light.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/rot.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/shard.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/shell.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/sight.json create mode 100644 src/main/resources/assets/unicopia/enchanting/ingredients/unaligned.json create mode 100644 src/main/resources/assets/unicopia/enchanting/recipes/awkward.json diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index 9f7e7c0c..c9d3d8f9 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -25,6 +25,7 @@ import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.jumpingcastle.api.JumpingCastle; import com.minelittlepony.unicopia.advancements.UAdvancements; import com.minelittlepony.unicopia.command.Commands; +import com.minelittlepony.unicopia.enchanting.AffineIngredients; import com.minelittlepony.unicopia.enchanting.Pages; import com.minelittlepony.unicopia.enchanting.SpellRecipe; import com.minelittlepony.unicopia.forgebullshit.FBS; @@ -104,6 +105,8 @@ public class Unicopia implements IGuiHandler { super.registerRecipeTypes(types); types.put("unicopia:crafting_spell", SpellRecipe::deserialize); + + AffineIngredients.instance().load(); } }; diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/AffineIngredients.java b/src/main/java/com/minelittlepony/unicopia/enchanting/AffineIngredients.java new file mode 100644 index 00000000..6c195f2d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/AffineIngredients.java @@ -0,0 +1,64 @@ +package com.minelittlepony.unicopia.enchanting; + +import java.util.Map; + +import javax.annotation.Nonnull; + +import com.google.common.collect.Maps; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.util.AssetWalker; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +public class AffineIngredients { + + private static final AffineIngredients instance = new AffineIngredients(); + + public static AffineIngredients instance() { + return instance; + } + + private final Map storedIngredients = Maps.newHashMap(); + + private final AssetWalker walker = new AssetWalker(new ResourceLocation(Unicopia.MODID, "enchanting/ingredients"), this::handleJson); + + public void load() { + storedIngredients.clear(); + + walker.walk(); + } + + public SpellIngredient getIngredient(ResourceLocation res) { + return storedIngredients.get(res); + } + + protected void handleJson(ResourceLocation id, JsonObject json) throws JsonParseException { + SpellIngredient ingredient = SpellIngredient.parse(json.get("items")); + + if (ingredient != null) { + storedIngredients.put(id, ingredient); + } + } + + static class AffineIngredient implements SpellIngredient { + + private final ResourceLocation res; + + AffineIngredient(ResourceLocation res) { + this.res = res; + } + + @Override + public boolean matches(ItemStack other, int materialMult) { + return instance().getIngredient(res).matches(other, materialMult); + } + + @Nonnull + static SpellIngredient parse(JsonObject json) { + return new AffineIngredient(new ResourceLocation(json.get("id").getAsString())); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellIngredient.java b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellIngredient.java index e2524254..102b248a 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellIngredient.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellIngredient.java @@ -8,6 +8,7 @@ import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.minelittlepony.unicopia.enchanting.AffineIngredients.AffineIngredient; import com.minelittlepony.unicopia.spell.SpellRegistry; import net.minecraft.item.Item; @@ -92,7 +93,7 @@ public interface SpellIngredient { } @Nullable - public static Single parse(JsonObject json) { + public static SpellIngredient parse(JsonObject json) { Item item = json.has("item") ? Item.getByNameOrId(json.get("item").getAsString()) : null; if (item != null) { @@ -109,6 +110,10 @@ public interface SpellIngredient { return new Single(stack, !json.has("data")); } + if (json.has("id")) { + return AffineIngredient.parse(json); + } + return null; } } diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/blood.json b/src/main/resources/assets/unicopia/enchanting/ingredients/blood.json new file mode 100644 index 00000000..70545d6c --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/blood.json @@ -0,0 +1,11 @@ +{ + "items": [ + { "item": "minecraft:red_glazed_terracotta" }, + { "item": "minecraft:dye", "data": 1 }, + { "item": "minecraft:redstone_block" }, + { "item": "minecraft:redstone" }, + { "item": "minecraft:emerald" }, + { "item": "minecraft:ghast_tear" }, + { "item": "minecraft:red_nether_brick" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/dark.json b/src/main/resources/assets/unicopia/enchanting/ingredients/dark.json new file mode 100644 index 00000000..1530a6eb --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/dark.json @@ -0,0 +1,9 @@ +{ + "items": [ + { "item": "minecraft:netherbrick" }, + { "item": "minecraft:brick" }, + { "item": "minecraft:red_nether_brick" }, + { "item": "minecraft:coal_block" }, + { "item": "minecraft:coal", "data": 0 } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/energy.json b/src/main/resources/assets/unicopia/enchanting/ingredients/energy.json new file mode 100644 index 00000000..ff91f0a9 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/energy.json @@ -0,0 +1,8 @@ +{ + "items": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:redstone_torch" }, + { "item": "minecraft:redstone_block" }, + { "item": "minecraft:redstone" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/fire.json b/src/main/resources/assets/unicopia/enchanting/ingredients/fire.json new file mode 100644 index 00000000..9adff9d6 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/fire.json @@ -0,0 +1,10 @@ +{ + "items": [ + { "item": "minecraft:fire_charge" }, + { "item": "minecraft:magma_cream" }, + { "item": "minecraft:blaze_powder" }, + { "item": "minecraft:blaze_rod" }, + { "item": "minecraft:gold_nugget" }, + { "item": "minecraft:lava_bucket" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/ice.json b/src/main/resources/assets/unicopia/enchanting/ingredients/ice.json new file mode 100644 index 00000000..a215ee3d --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/ice.json @@ -0,0 +1,7 @@ +{ + "items": [ + { "item": "minecraft:ghast_tear" }, + { "item": "minecraft:water_bucket" }, + { "item": "minecraft:snowball" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/life.json b/src/main/resources/assets/unicopia/enchanting/ingredients/life.json new file mode 100644 index 00000000..d6e07eb0 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/life.json @@ -0,0 +1,10 @@ +{ + "items": [ + { "item": "minecraft:brown_mushroom" }, + { "item": "unicopia:rotten_apple" }, + { "item": "minecraft:golden_carrot" }, + { "item": "minecraft:wheat" }, + { "item": "minecraft:grain" }, + { "item": "minecraft:alfalfa_leaves" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/light.json b/src/main/resources/assets/unicopia/enchanting/ingredients/light.json new file mode 100644 index 00000000..60c30fdb --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/light.json @@ -0,0 +1,6 @@ +{ + "items": [ + { "item": "minecraft:glowstone" }, + { "item": "minecraft:glowstone_dust" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/rot.json b/src/main/resources/assets/unicopia/enchanting/ingredients/rot.json new file mode 100644 index 00000000..34bb0443 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/rot.json @@ -0,0 +1,10 @@ +{ + "items": [ + { "item": "minecraft:rotten_flesh" }, + { "item": "unicopia:cloudsdale_tomato", "data": 1 }, + { "item": "unicopia:tomato", "data": 1 }, + { "item": "unicopia:rotten_apple" }, + { "item": "minecraft:red_mushroom" }, + { "item": "minecraft:brown_mushroom" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/shard.json b/src/main/resources/assets/unicopia/enchanting/ingredients/shard.json new file mode 100644 index 00000000..073026fd --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/shard.json @@ -0,0 +1,7 @@ +{ + "items": [ + { "item": "minecraft:egg" }, + { "item": "minecraft:coal" }, + { "item": "minecraft:flint" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/shell.json b/src/main/resources/assets/unicopia/enchanting/ingredients/shell.json new file mode 100644 index 00000000..b182c106 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/shell.json @@ -0,0 +1,8 @@ +{ + "items": [ + { "item": "minecraft:egg" }, + { "item": "minecraft:firework_charge" }, + { "item": "minecraft:ender_eye" }, + { "item": "minecraft:fire_charge" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/sight.json b/src/main/resources/assets/unicopia/enchanting/ingredients/sight.json new file mode 100644 index 00000000..327ab39f --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/sight.json @@ -0,0 +1,8 @@ +{ + "items": [ + { "item": "minecraft:ender_eye" }, + { "item": "minecraft:spider_eye" }, + { "item": "minecraft:speckled_mellon" }, + { "item": "minecraft:ender_pearl" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/ingredients/unaligned.json b/src/main/resources/assets/unicopia/enchanting/ingredients/unaligned.json new file mode 100644 index 00000000..b7627d30 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/ingredients/unaligned.json @@ -0,0 +1,9 @@ +{ + "items": [ + { "item": "minecraft:red_flower" }, + { "item": "minecraft:yellow_flower" }, + { "item": "minecraft:tallgrass" }, + { "item": "minecraft:sapling" }, + { "item": "minecraft:stick" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/awkward.json b/src/main/resources/assets/unicopia/enchanting/recipes/awkward.json new file mode 100644 index 00000000..17cccde8 --- /dev/null +++ b/src/main/resources/assets/unicopia/enchanting/recipes/awkward.json @@ -0,0 +1,15 @@ +{ + "type": "unicopia:crafting_spell", + "ingredients": [ + { "id": "unicopia:unaligned" }, + { "id": "unicopia:unaligned" }, + { "id": "unicopia:unaligned" } + ], + "result": { + "item": [ + { "item": "unicopia:gem" }, + { "item": "unicopia:corrupted_gem" } + ], + "spell": "awkward" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/charge.json b/src/main/resources/assets/unicopia/enchanting/recipes/charge.json index d51350c2..a6cd9e59 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/charge.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/charge.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "unicopia:zap_apple" }, + { "id": "unicopia:energy" }, { "item": "unicopia:gem", "spell": "fire" }, - { "item": "minecraft:redstone" } + { "id": "unicopia:fire" } ], "result": { "item": { "item": "unicopia:gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/drake.json b/src/main/resources/assets/unicopia/enchanting/recipes/drake.json index 67f2e0e0..254ada88 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/drake.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/drake.json @@ -3,6 +3,7 @@ "ingredients": [ { "item": "unicopia:gem", "spell": "charge" }, { "item": "unicopia:corrupted_gem" }, + { "id": "unicopia:life" }, { "item": "minecraft:red_flower", "data": 0 } ], "result": { diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/fire.json b/src/main/resources/assets/unicopia/enchanting/recipes/fire.json index 6b60b6ba..29013561 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/fire.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/fire.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:fire_charge" }, - { "item": "minecraft:fire_charge" }, - { "item": "minecraft:lava_bucket" } + { "id": "unicopia:fire" }, + { "id": "unicopia:fire" }, + { "id": "unicopia:fire" } ], "result": { "item": { "item": "unicopia:gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/ice.json b/src/main/resources/assets/unicopia/enchanting/recipes/ice.json index 90b6b775..456761cf 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/ice.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/ice.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:snowball" }, - { "item": "minecraft:snowball" }, - { "item": "minecraft:water_bucket" } + { "id": "unicopia:ice" }, + { "id": "unicopia:ice" }, + { "id": "unicopia:ice" } ], "result": { "item": { "item": "unicopia:gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/inferno.json b/src/main/resources/assets/unicopia/enchanting/recipes/inferno.json index 76787208..0d5036c4 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/inferno.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/inferno.json @@ -2,8 +2,8 @@ "type": "unicopia:crafting_spell", "ingredients": [ { "item": "unicopia:gem", "spell": "fire" }, - { "item": "minecraft:redstone" }, - { "item": "minecraft:lava_bucket" } + { "id": "unicopia:fire" }, + { "id": "unicopia:fire" } ], "result": { "item": { "item": "unicopia:corrupted_gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/light.json b/src/main/resources/assets/unicopia/enchanting/recipes/light.json index 1ad4859c..7f49690e 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/light.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/light.json @@ -1,9 +1,14 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:glowstone_dust" }, + { "id": "unicopia:light" }, { "item": "unicopia:gem", "spell": "fire" }, - { "item": "unicopia:apple_green" } + [ + { "item": "minecraft:apple" }, + { "item": "unicopia:apple_green" }, + { "item": "unicopia:apple_sweet" }, + { "item": "unicopia:apple_sour" } + ] ], "result": { "item": { "item": "unicopia:gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/necromancy.json b/src/main/resources/assets/unicopia/enchanting/recipes/necromancy.json index 5b0780e7..6f4a5aec 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/necromancy.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/necromancy.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:dye", "data": 1 }, - { "item": "minecraft:redstone" }, - { "item": "minecraft:rotten_flesh" } + { "id": "unicopia:blood" }, + { "id": "unicopia:energy" }, + { "id": "unicopia:rot" } ], "result": { "item": { "item": "unicopia:corrupted_gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/portal.json b/src/main/resources/assets/unicopia/enchanting/recipes/portal.json index 4def4794..442d3e7b 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/portal.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/portal.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:ender_pearl" }, + { "id": "unicopia:sight" }, { "item": "minecraft:ghast_tear" }, - { "item": "minecraft:redstone" }, + { "id": "unicopia:energy" }, { "item": "unicopia:gem", "spell": "fire" } ], "result": { diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/repulsion.json b/src/main/resources/assets/unicopia/enchanting/recipes/repulsion.json index 498adc45..bef53703 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/repulsion.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/repulsion.json @@ -1,10 +1,10 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:firework_charge" }, - { "item": "minecraft:fire_charge" }, + { "id": "unicopia:fire" }, + { "id": "unicopia:shell" }, { "item": "unicopia:gem", "spell": "shield" }, - { "item": "minecraft:egg" } + { "id": "unicopia:shell" } ], "result": { "item": { "item": "unicopia:corrupted_gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/shield.json b/src/main/resources/assets/unicopia/enchanting/recipes/shield.json index 5d922157..1fa35b37 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/shield.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/shield.json @@ -1,9 +1,9 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:egg" }, - { "item": "minecraft:coal" }, - { "item": "minecraft:blaze_powder" } + { "id": "unicopia:shell" }, + { "id": "unicopia:shell" }, + { "id": "unicopia:shard" } ], "result": { "item": { "item": "unicopia:gem" }, diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/suffering.json b/src/main/resources/assets/unicopia/enchanting/recipes/suffering.json index d5c272cd..4a1cdcdd 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/suffering.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/suffering.json @@ -2,6 +2,7 @@ "type": "unicopia:crafting_spell", "ingredients": [ { "item": "minecraft:fire_charge" }, + { "id": "unicopia:bloood" }, { "item": "unicopia:gem", "spell": "fire" } ], "result": { diff --git a/src/main/resources/assets/unicopia/enchanting/recipes/vortex.json b/src/main/resources/assets/unicopia/enchanting/recipes/vortex.json index eb1b6727..f2ee039e 100644 --- a/src/main/resources/assets/unicopia/enchanting/recipes/vortex.json +++ b/src/main/resources/assets/unicopia/enchanting/recipes/vortex.json @@ -1,7 +1,7 @@ { "type": "unicopia:crafting_spell", "ingredients": [ - { "item": "minecraft:egg" }, + { "id": "unicopia:shell" }, { "item": "unicopia:gem", "spell": "shield" }, { "item": "unicopia:gem", "spell": "portal" } ],