Rewrite gem recipes to pull from named pools of like items. It's not about the items, it's about the traits.

This commit is contained in:
Sollace 2019-02-20 15:13:04 +02:00
parent 76a725c981
commit 3b2ffc0671
28 changed files with 222 additions and 25 deletions

View file

@ -25,6 +25,7 @@ import com.minelittlepony.jumpingcastle.api.IChannel;
import com.minelittlepony.jumpingcastle.api.JumpingCastle; import com.minelittlepony.jumpingcastle.api.JumpingCastle;
import com.minelittlepony.unicopia.advancements.UAdvancements; import com.minelittlepony.unicopia.advancements.UAdvancements;
import com.minelittlepony.unicopia.command.Commands; import com.minelittlepony.unicopia.command.Commands;
import com.minelittlepony.unicopia.enchanting.AffineIngredients;
import com.minelittlepony.unicopia.enchanting.Pages; import com.minelittlepony.unicopia.enchanting.Pages;
import com.minelittlepony.unicopia.enchanting.SpellRecipe; import com.minelittlepony.unicopia.enchanting.SpellRecipe;
import com.minelittlepony.unicopia.forgebullshit.FBS; import com.minelittlepony.unicopia.forgebullshit.FBS;
@ -104,6 +105,8 @@ public class Unicopia implements IGuiHandler {
super.registerRecipeTypes(types); super.registerRecipeTypes(types);
types.put("unicopia:crafting_spell", SpellRecipe::deserialize); types.put("unicopia:crafting_spell", SpellRecipe::deserialize);
AffineIngredients.instance().load();
} }
}; };

View file

@ -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<ResourceLocation, SpellIngredient> 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()));
}
}
}

View file

@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.minelittlepony.unicopia.enchanting.AffineIngredients.AffineIngredient;
import com.minelittlepony.unicopia.spell.SpellRegistry; import com.minelittlepony.unicopia.spell.SpellRegistry;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -92,7 +93,7 @@ public interface SpellIngredient {
} }
@Nullable @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; Item item = json.has("item") ? Item.getByNameOrId(json.get("item").getAsString()) : null;
if (item != null) { if (item != null) {
@ -109,6 +110,10 @@ public interface SpellIngredient {
return new Single(stack, !json.has("data")); return new Single(stack, !json.has("data"));
} }
if (json.has("id")) {
return AffineIngredient.parse(json);
}
return null; return null;
} }
} }

View file

@ -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" }
]
}

View file

@ -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 }
]
}

View file

@ -0,0 +1,8 @@
{
"items": [
{ "item": "unicopia:zap_apple" },
{ "item": "minecraft:redstone_torch" },
{ "item": "minecraft:redstone_block" },
{ "item": "minecraft:redstone" }
]
}

View file

@ -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" }
]
}

View file

@ -0,0 +1,7 @@
{
"items": [
{ "item": "minecraft:ghast_tear" },
{ "item": "minecraft:water_bucket" },
{ "item": "minecraft:snowball" }
]
}

View file

@ -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" }
]
}

View file

@ -0,0 +1,6 @@
{
"items": [
{ "item": "minecraft:glowstone" },
{ "item": "minecraft:glowstone_dust" }
]
}

View file

@ -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" }
]
}

View file

@ -0,0 +1,7 @@
{
"items": [
{ "item": "minecraft:egg" },
{ "item": "minecraft:coal" },
{ "item": "minecraft:flint" }
]
}

View file

@ -0,0 +1,8 @@
{
"items": [
{ "item": "minecraft:egg" },
{ "item": "minecraft:firework_charge" },
{ "item": "minecraft:ender_eye" },
{ "item": "minecraft:fire_charge" }
]
}

View file

@ -0,0 +1,8 @@
{
"items": [
{ "item": "minecraft:ender_eye" },
{ "item": "minecraft:spider_eye" },
{ "item": "minecraft:speckled_mellon" },
{ "item": "minecraft:ender_pearl" }
]
}

View file

@ -0,0 +1,9 @@
{
"items": [
{ "item": "minecraft:red_flower" },
{ "item": "minecraft:yellow_flower" },
{ "item": "minecraft:tallgrass" },
{ "item": "minecraft:sapling" },
{ "item": "minecraft:stick" }
]
}

View file

@ -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"
}
}

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "unicopia:zap_apple" }, { "id": "unicopia:energy" },
{ "item": "unicopia:gem", "spell": "fire" }, { "item": "unicopia:gem", "spell": "fire" },
{ "item": "minecraft:redstone" } { "id": "unicopia:fire" }
], ],
"result": { "result": {
"item": { "item": "unicopia:gem" }, "item": { "item": "unicopia:gem" },

View file

@ -3,6 +3,7 @@
"ingredients": [ "ingredients": [
{ "item": "unicopia:gem", "spell": "charge" }, { "item": "unicopia:gem", "spell": "charge" },
{ "item": "unicopia:corrupted_gem" }, { "item": "unicopia:corrupted_gem" },
{ "id": "unicopia:life" },
{ "item": "minecraft:red_flower", "data": 0 } { "item": "minecraft:red_flower", "data": 0 }
], ],
"result": { "result": {

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:fire_charge" }, { "id": "unicopia:fire" },
{ "item": "minecraft:fire_charge" }, { "id": "unicopia:fire" },
{ "item": "minecraft:lava_bucket" } { "id": "unicopia:fire" }
], ],
"result": { "result": {
"item": { "item": "unicopia:gem" }, "item": { "item": "unicopia:gem" },

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:snowball" }, { "id": "unicopia:ice" },
{ "item": "minecraft:snowball" }, { "id": "unicopia:ice" },
{ "item": "minecraft:water_bucket" } { "id": "unicopia:ice" }
], ],
"result": { "result": {
"item": { "item": "unicopia:gem" }, "item": { "item": "unicopia:gem" },

View file

@ -2,8 +2,8 @@
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "unicopia:gem", "spell": "fire" }, { "item": "unicopia:gem", "spell": "fire" },
{ "item": "minecraft:redstone" }, { "id": "unicopia:fire" },
{ "item": "minecraft:lava_bucket" } { "id": "unicopia:fire" }
], ],
"result": { "result": {
"item": { "item": "unicopia:corrupted_gem" }, "item": { "item": "unicopia:corrupted_gem" },

View file

@ -1,9 +1,14 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:glowstone_dust" }, { "id": "unicopia:light" },
{ "item": "unicopia:gem", "spell": "fire" }, { "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": { "result": {
"item": { "item": "unicopia:gem" }, "item": { "item": "unicopia:gem" },

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:dye", "data": 1 }, { "id": "unicopia:blood" },
{ "item": "minecraft:redstone" }, { "id": "unicopia:energy" },
{ "item": "minecraft:rotten_flesh" } { "id": "unicopia:rot" }
], ],
"result": { "result": {
"item": { "item": "unicopia:corrupted_gem" }, "item": { "item": "unicopia:corrupted_gem" },

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:ender_pearl" }, { "id": "unicopia:sight" },
{ "item": "minecraft:ghast_tear" }, { "item": "minecraft:ghast_tear" },
{ "item": "minecraft:redstone" }, { "id": "unicopia:energy" },
{ "item": "unicopia:gem", "spell": "fire" } { "item": "unicopia:gem", "spell": "fire" }
], ],
"result": { "result": {

View file

@ -1,10 +1,10 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:firework_charge" }, { "id": "unicopia:fire" },
{ "item": "minecraft:fire_charge" }, { "id": "unicopia:shell" },
{ "item": "unicopia:gem", "spell": "shield" }, { "item": "unicopia:gem", "spell": "shield" },
{ "item": "minecraft:egg" } { "id": "unicopia:shell" }
], ],
"result": { "result": {
"item": { "item": "unicopia:corrupted_gem" }, "item": { "item": "unicopia:corrupted_gem" },

View file

@ -1,9 +1,9 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:egg" }, { "id": "unicopia:shell" },
{ "item": "minecraft:coal" }, { "id": "unicopia:shell" },
{ "item": "minecraft:blaze_powder" } { "id": "unicopia:shard" }
], ],
"result": { "result": {
"item": { "item": "unicopia:gem" }, "item": { "item": "unicopia:gem" },

View file

@ -2,6 +2,7 @@
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:fire_charge" }, { "item": "minecraft:fire_charge" },
{ "id": "unicopia:bloood" },
{ "item": "unicopia:gem", "spell": "fire" } { "item": "unicopia:gem", "spell": "fire" }
], ],
"result": { "result": {

View file

@ -1,7 +1,7 @@
{ {
"type": "unicopia:crafting_spell", "type": "unicopia:crafting_spell",
"ingredients": [ "ingredients": [
{ "item": "minecraft:egg" }, { "id": "unicopia:shell" },
{ "item": "unicopia:gem", "spell": "shield" }, { "item": "unicopia:gem", "spell": "shield" },
{ "item": "unicopia:gem", "spell": "portal" } { "item": "unicopia:gem", "spell": "portal" }
], ],