Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ private StationFeedback createItem(Player p, Double forcedQualityPercent, boolea
mmo.setData(ItemStats.LORE, lore);
ItemStack finalItem = mmo.newBuilder().build();
if(scheme != null) {
if(!recipe.getModelType().equalsIgnoreCase("none")) {
// A recipe-specific model on the main material wins over the secondary model ingredient.
if(scheme.getModel(recipe.getId()) == null && !recipe.getModelType().equalsIgnoreCase("none")) {
for(String s : currentMaterials.keySet()) {
String modeltype = s.split("\\.")[0];
String modelId = s.split("\\.")[1];
Expand Down Expand Up @@ -541,7 +542,11 @@ private StationFeedback createItem(Player p, Double forcedQualityPercent, boolea
// This path mutates the existing ItemStack; replacing it would change aliases held by callers.
@SuppressWarnings("deprecation")
private ItemStack applyModel(ItemStack i, ModelScheme scheme) {
String path = scheme.getModel(recipe.getType());
// A model named after the recipe (e.g. heavy_helmet) wins over the shared type (helmet).
String path = scheme.getModel(recipe.getId());
if(path == null) {
path = scheme.getModel(recipe.getType());
}
if(path == null) {
Bukkit.getLogger().warning("AC: No model in the scheme "+scheme.getId()+" for the recipe type "+recipe.getType());
return i;
Expand Down
100 changes: 100 additions & 0 deletions src/main/resources/model-schemes/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ iron:
- chestplate(v.chainmail_chestplate.0)
- leggings(v.chainmail_leggings.0)
- boots(v.chainmail_boots.0)
- light_helmet(ia.tfmc_armor:iron_light_helmet)
- light_chestplate(ia.tfmc_armor:iron_light_chestplate)
- light_leggings(ia.tfmc_armor:iron_light_leggings)
- light_boots(ia.tfmc_armor:iron_light_boots)
- medium_helmet(ia.tfmc_armor:iron_medium_helmet)
- medium_chestplate(ia.tfmc_armor:iron_medium_chestplate)
- medium_leggings(ia.tfmc_armor:iron_medium_leggings)
- medium_boots(ia.tfmc_armor:iron_medium_boots)
- heavy_helmet(ia.tfmc_armor:iron_heavy_helmet)
- heavy_chestplate(ia.tfmc_armor:iron_heavy_chestplate)
- heavy_leggings(ia.tfmc_armor:iron_heavy_leggings)
- heavy_boots(ia.tfmc_armor:iron_heavy_boots)
- infantry_helmet(ia.tfmc_armor:base_metal_iron_infantry_helmet)
- infantry_chestplate(ia.tfmc_armor:base_metal_iron_infantry_chestplate)
- infantry_leggings(ia.tfmc_armor:base_metal_iron_infantry_leggings)
- infantry_boots(ia.tfmc_armor:base_metal_iron_infantry_boots)
- mage_helmet(ia.tfmc_armor:base_metal_iron_mage_helmet)
- mage_chestplate(ia.tfmc_armor:base_metal_iron_mage_chestplate)
- mage_leggings(ia.tfmc_armor:base_metal_iron_mage_leggings)
- mage_boots(ia.tfmc_armor:base_metal_iron_mage_boots)

steel:
models:
Expand All @@ -36,6 +56,26 @@ steel:
- chestplate(v.iron_chestplate.0)
- leggings(v.iron_leggings.0)
- boots(v.iron_boots.0)
- light_helmet(ia.tfmc_armor:steel_light_helmet)
- light_chestplate(ia.tfmc_armor:steel_light_chestplate)
- light_leggings(ia.tfmc_armor:steel_light_leggings)
- light_boots(ia.tfmc_armor:steel_light_boots)
- medium_helmet(ia.tfmc_armor:steel_medium_helmet)
- medium_chestplate(ia.tfmc_armor:steel_medium_chestplate)
- medium_leggings(ia.tfmc_armor:steel_medium_leggings)
- medium_boots(ia.tfmc_armor:steel_medium_boots)
- heavy_helmet(ia.tfmc_armor:steel_heavy_helmet)
- heavy_chestplate(ia.tfmc_armor:steel_heavy_chestplate)
- heavy_leggings(ia.tfmc_armor:steel_heavy_leggings)
- heavy_boots(ia.tfmc_armor:steel_heavy_boots)
- infantry_helmet(ia.tfmc_armor:base_metal_steel_infantry_helmet)
- infantry_chestplate(ia.tfmc_armor:base_metal_steel_infantry_chestplate)
- infantry_leggings(ia.tfmc_armor:base_metal_steel_infantry_leggings)
- infantry_boots(ia.tfmc_armor:base_metal_steel_infantry_boots)
- mage_helmet(ia.tfmc_armor:base_metal_steel_mage_helmet)
- mage_chestplate(ia.tfmc_armor:base_metal_steel_mage_chestplate)
- mage_leggings(ia.tfmc_armor:base_metal_steel_mage_leggings)
- mage_boots(ia.tfmc_armor:base_metal_steel_mage_boots)

bronze:
models:
Expand All @@ -54,6 +94,26 @@ bronze:
- chestplate(ia.tfmc_armor:bronze_chestplate)
- leggings(ia.tfmc_armor:bronze_leggings)
- boots(ia.tfmc_armor:bronze_boots)
- light_helmet(ia.tfmc_armor:bronze_light_helmet)
- light_chestplate(ia.tfmc_armor:bronze_light_chestplate)
- light_leggings(ia.tfmc_armor:bronze_light_leggings)
- light_boots(ia.tfmc_armor:bronze_light_boots)
- medium_helmet(ia.tfmc_armor:bronze_medium_helmet)
- medium_chestplate(ia.tfmc_armor:bronze_medium_chestplate)
- medium_leggings(ia.tfmc_armor:bronze_medium_leggings)
- medium_boots(ia.tfmc_armor:bronze_medium_boots)
- heavy_helmet(ia.tfmc_armor:bronze_heavy_helmet)
- heavy_chestplate(ia.tfmc_armor:bronze_heavy_chestplate)
- heavy_leggings(ia.tfmc_armor:bronze_heavy_leggings)
- heavy_boots(ia.tfmc_armor:bronze_heavy_boots)
- infantry_helmet(ia.tfmc_armor:base_metal_bronze_infantry_helmet)
- infantry_chestplate(ia.tfmc_armor:base_metal_bronze_infantry_chestplate)
- infantry_leggings(ia.tfmc_armor:base_metal_bronze_infantry_leggings)
- infantry_boots(ia.tfmc_armor:base_metal_bronze_infantry_boots)
- mage_helmet(ia.tfmc_armor:base_metal_bronze_mage_helmet)
- mage_chestplate(ia.tfmc_armor:base_metal_bronze_mage_chestplate)
- mage_leggings(ia.tfmc_armor:base_metal_bronze_mage_leggings)
- mage_boots(ia.tfmc_armor:base_metal_bronze_mage_boots)

abyssalite:
models:
Expand All @@ -72,6 +132,26 @@ abyssalite:
- chestplate(v.netherite_chestplate.0)
- leggings(v.netherite_leggings.0)
- boots(v.netherite_boots.0)
- light_helmet(ia.tfmc_armor:abyssalite_light_helmet)
- light_chestplate(ia.tfmc_armor:abyssalite_light_chestplate)
- light_leggings(ia.tfmc_armor:abyssalite_light_leggings)
- light_boots(ia.tfmc_armor:abyssalite_light_boots)
- medium_helmet(ia.tfmc_armor:abyssalite_medium_helmet)
- medium_chestplate(ia.tfmc_armor:abyssalite_medium_chestplate)
- medium_leggings(ia.tfmc_armor:abyssalite_medium_leggings)
- medium_boots(ia.tfmc_armor:abyssalite_medium_boots)
- heavy_helmet(ia.tfmc_armor:abyssalite_heavy_helmet)
- heavy_chestplate(ia.tfmc_armor:abyssalite_heavy_chestplate)
- heavy_leggings(ia.tfmc_armor:abyssalite_heavy_leggings)
- heavy_boots(ia.tfmc_armor:abyssalite_heavy_boots)
- infantry_helmet(ia.tfmc_armor:base_metal_abyssalite_infantry_helmet)
- infantry_chestplate(ia.tfmc_armor:base_metal_abyssalite_infantry_chestplate)
- infantry_leggings(ia.tfmc_armor:base_metal_abyssalite_infantry_leggings)
- infantry_boots(ia.tfmc_armor:base_metal_abyssalite_infantry_boots)
- mage_helmet(ia.tfmc_armor:base_metal_abyssalite_mage_helmet)
- mage_chestplate(ia.tfmc_armor:base_metal_abyssalite_mage_chestplate)
- mage_leggings(ia.tfmc_armor:base_metal_abyssalite_mage_leggings)
- mage_boots(ia.tfmc_armor:base_metal_abyssalite_mage_boots)

mythril:
models:
Expand All @@ -90,6 +170,26 @@ mythril:
- chestplate(v.diamond_chestplate.0)
- leggings(v.diamond_leggings.0)
- boots(v.diamond_boots.0)
- light_helmet(ia.tfmc_armor:mythril_light_helmet)
- light_chestplate(ia.tfmc_armor:mythril_light_chestplate)
- light_leggings(ia.tfmc_armor:mythril_light_leggings)
- light_boots(ia.tfmc_armor:mythril_light_boots)
- medium_helmet(ia.tfmc_armor:mythril_medium_helmet)
- medium_chestplate(ia.tfmc_armor:mythril_medium_chestplate)
- medium_leggings(ia.tfmc_armor:mythril_medium_leggings)
- medium_boots(ia.tfmc_armor:mythril_medium_boots)
- heavy_helmet(ia.tfmc_armor:mythril_heavy_helmet)
- heavy_chestplate(ia.tfmc_armor:mythril_heavy_chestplate)
- heavy_leggings(ia.tfmc_armor:mythril_heavy_leggings)
- heavy_boots(ia.tfmc_armor:mythril_heavy_boots)
- infantry_helmet(ia.tfmc_armor:base_metal_mythril_infantry_helmet)
- infantry_chestplate(ia.tfmc_armor:base_metal_mythril_infantry_chestplate)
- infantry_leggings(ia.tfmc_armor:base_metal_mythril_infantry_leggings)
- infantry_boots(ia.tfmc_armor:base_metal_mythril_infantry_boots)
- mage_helmet(ia.tfmc_armor:base_metal_mythril_mage_helmet)
- mage_chestplate(ia.tfmc_armor:base_metal_mythril_mage_chestplate)
- mage_leggings(ia.tfmc_armor:base_metal_mythril_mage_leggings)
- mage_boots(ia.tfmc_armor:base_metal_mythril_mage_boots)

infantry:
models:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,20 @@ void modelApplicationHandlesVanillaItemsAdderMissingAndOtherSchemes() throws Exc
new Class[] {ItemStack.class, ModelScheme.class},
original,
ia));
var perRecipe =
new ModelScheme(
"per-recipe", yaml("models: ['smith(v.golden_sword.7)', 'sword(v.iron_sword.9)']"));
var weighted = new ItemStack(Material.STONE_SWORD);
assertSame(
weighted,
invoke(
station,
"applyModel",
new Class[] {ItemStack.class, ModelScheme.class},
weighted,
perRecipe));
assertEquals(Material.IRON_SWORD, weighted.getType());
models.verify(() -> LegacyModelData.set(any(), eq(9)));
for (String path : List.of("models: ['smith(other.item)']", "models: []"))
assertSame(
original,
Expand All @@ -340,6 +354,82 @@ void modelApplicationHandlesVanillaItemsAdderMissingAndOtherSchemes() throws Exc
}
}

@Test
void mainMaterialRecipeModelWinsAndSecondaryIngredientRemainsFallback() throws Exception {
var p = server.addPlayer();
QualityLoader.map.put("fine", new Quality("fine", yaml("name: Fine\namount: 0\nvalue: 0")));
TypeLoader.map.put(
"paper",
new net.tfminecraft.advancedcrafting.objects.ingredients.IngredientType(
"paper", yaml("name: Paper")));
for (boolean specific : List.of(true, false)) {
SchemeLoader.models.put(
"metal-look",
new ModelScheme(
"metal-look",
yaml(
"models: ['smith(v.iron_sword.1)'"
+ (specific ? ", 'sword(v.diamond_sword.2)'" : "")
+ "]")));
SchemeLoader.models.put(
"cloth-look",
new ModelScheme("cloth-look", yaml("models: ['smith(v.golden_sword.3)']")));
var metal = ingredient("metal-" + specific, "model-scheme: metal-look");
var cloth = ingredient("cloth-" + specific, "type: paper\nmodel-scheme: cloth-look");
var alloy =
new Alloy(
"metal-" + specific,
"Metal",
new AlloyData(
metal,
new net.tfminecraft.advancedcrafting.objects.data.StatData(),
new HashMap<>(),
null));
AlloyManager.addAlloy(alloy);
var clothAlloy =
new Alloy(
"cloth-" + specific,
"Cloth",
new AlloyData(
cloth,
new net.tfminecraft.advancedcrafting.objects.data.StatData(),
new HashMap<>(),
null));
AlloyManager.addAlloy(clothAlloy);
for (String key : List.of("ingredient." + metal.getId(), "alloy." + alloy.getId()))
for (String secondary : List.of("ingredient." + cloth.getId(), "alloy." + clothAlloy.getId()))
for (String modelType : List.of("paper", "none")) {
int expectedModel = specific ? 2 : modelType.equals("none") ? 1 : 3;
Material expectedMaterial =
specific
? Material.DIAMOND_SWORD
: modelType.equals("none") ? Material.IRON_SWORD : Material.GOLDEN_SWORD;
var station =
new CraftingStation(
loc(),
recipe("recipe: ['metal.1', 'paper.1']\nmodel-type: " + modelType),
new HashMap<>(Map.of(key, 1, secondary, 1)),
new HashMap<>());
station.getCurrentMaterials().put("unknown.removed", 1);
try (var nbt = mockStatic(NBTItem.class);
var models = mockStatic(LegacyModelData.class);
var mmos =
mockConstruction(
LiveMMOItem.class,
withSettings().defaultAnswer(RETURNS_DEEP_STUBS),
(mmo, ctx) -> {
when(mmo.getData(ItemStats.NAME)).thenReturn(new StringData("Old"));
when(mmo.computeStatHistory(ItemStats.NAME)).thenReturn(null);
when(mmo.newBuilder().build()).thenReturn(new ItemStack(Material.IRON_SWORD));
})) {
var result = station.buildCompletedItem(p, 50.);
assertEquals(expectedMaterial, result.getType());
models.verify(() -> LegacyModelData.set(any(), eq(expectedModel)));
}
}
}
}

@Test
void experienceAggregatesOnlyExistingPositiveValidDefinitions() throws Exception {
var p = server.addPlayer();
Expand Down
Loading