|
| 1 | +package net.tfminecraft.advancedcrafting; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import java.util.*; |
| 6 | +import net.tfminecraft.advancedcrafting.loaders.*; |
| 7 | +import net.tfminecraft.advancedcrafting.managers.AlloyManager; |
| 8 | +import net.tfminecraft.advancedcrafting.objects.alloys.Alloy; |
| 9 | +import net.tfminecraft.advancedcrafting.objects.crafting.CraftingRecipe; |
| 10 | +import net.tfminecraft.advancedcrafting.objects.data.*; |
| 11 | +import net.tfminecraft.advancedcrafting.objects.ingredients.*; |
| 12 | +import net.tfminecraft.advancedcrafting.objects.schemes.ModelScheme; |
| 13 | +import net.tfminecraft.advancedcrafting.utils.ModelSchemeResolver; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +class ModelSchemeResolverTest extends CoverageSupport { |
| 17 | + static CraftInput in(String kind, String id, int amount) { |
| 18 | + return new CraftInput(kind, id, amount, 0); |
| 19 | + } |
| 20 | + |
| 21 | + static String scheme(CraftingRecipe recipe, CraftInput... inputs) { |
| 22 | + ModelScheme scheme = ModelSchemeResolver.resolve(recipe, List.of(inputs)); |
| 23 | + return scheme == null ? null : scheme.getId(); |
| 24 | + } |
| 25 | + |
| 26 | + Alloy alloy(String id, Ingredient base) { |
| 27 | + var alloy = new Alloy(id, id, new AlloyData(base, new StatData(), new HashMap<>(), null)); |
| 28 | + AlloyManager.addAlloy(alloy); |
| 29 | + return alloy; |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void recordedCraftsResolveTheSchemeTheirLookCameFromAndAlloysUseTheirBase() throws Exception { |
| 34 | + TypeLoader.map.put("paper", new IngredientType("paper", yaml("name: Paper"))); |
| 35 | + SchemeLoader.models.put("iron", new ModelScheme("iron", yaml("models: ['smith(v.iron_sword.1)']"))); |
| 36 | + SchemeLoader.models.put("own", new ModelScheme("own", yaml("models: ['sword(v.iron_sword.2)']"))); |
| 37 | + SchemeLoader.models.put("cloth", new ModelScheme("cloth", yaml("models: ['smith(v.golden_sword.3)']"))); |
| 38 | + ingredient("iron", "model-scheme: iron"); |
| 39 | + ingredient("own", "model-scheme: own"); |
| 40 | + var cloth = ingredient("cloth", "type: paper\nmodel-scheme: cloth"); |
| 41 | + alloy("darksteel", IngredientLoader.getByString("iron")); |
| 42 | + alloy("clothsteel", cloth); |
| 43 | + var noModel = recipe("recipe: ['metal.1', 'paper.1']\nmodel-type: none"); |
| 44 | + var byPaper = recipe("recipe: ['metal.1', 'paper.1']\nmodel-type: paper"); |
| 45 | + |
| 46 | + assertNull(ModelSchemeResolver.resolve(null, List.of(in("ingredient", "iron", 1)))); |
| 47 | + assertNull(ModelSchemeResolver.resolve(noModel, null)); |
| 48 | + assertNull(ModelSchemeResolver.resolve(noModel, List.of())); |
| 49 | + |
| 50 | + // The main material decides; an alloy wears its base metal's scheme. |
| 51 | + assertEquals("iron", scheme(noModel, in("ingredient", "iron", 3), in("ingredient", "cloth", 1))); |
| 52 | + assertEquals("iron", scheme(noModel, in("alloy", "darksteel", 3))); |
| 53 | + // A model-type material takes over when the main scheme has no model for the recipe ... |
| 54 | + assertEquals("cloth", scheme(byPaper, in("alloy", "darksteel", 3), in("ingredient", "cloth", 1))); |
| 55 | + assertEquals("cloth", scheme(byPaper, in("ingredient", "iron", 3), in("alloy", "clothsteel", 1))); |
| 56 | + // ... but not when it has one of its own. |
| 57 | + assertEquals("own", scheme(byPaper, in("ingredient", "own", 3), in("ingredient", "cloth", 1))); |
| 58 | + // Unknown, malformed and foreign inputs leave the main scheme alone. |
| 59 | + assertEquals( |
| 60 | + "iron", |
| 61 | + scheme( |
| 62 | + byPaper, |
| 63 | + in("ingredient", "iron", 3), |
| 64 | + in("alloy", "darksteel", 1), |
| 65 | + in("ingredient", "gone", 1), |
| 66 | + in("alloy", "gone", 1), |
| 67 | + in("ingredient", "", 1), |
| 68 | + in("misc", "x", 1))); |
| 69 | + assertNull(scheme(noModel, in("ingredient", "gone", 1))); |
| 70 | + assertNull(scheme(noModel, in("alloy", "gone", 1))); |
| 71 | + } |
| 72 | +} |
0 commit comments