Skip to content

Commit 9ce37f3

Browse files
XxFran10xXclaude
andauthored
feat: tag alloy scrap with the base metal it consumed (#25)
* feat: tag alloy scrap with the base metal it consumed A failed alloy forge now records the base ingredient id on the scrap it drops (PDC key ac_scrap_base). ScrapProvenance reads it back so Recycler can turn scrap into part of that base metal. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: lowercase scrap base ids with Locale.ROOT Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: XxFran10xX <318299142+XxFran10xX@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 9bf45a7 commit 9ce37f3

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎src/main/java/net/tfminecraft/advancedcrafting/objects/alloys/AlloyForger.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.tfminecraft.advancedcrafting.managers.AlloyManager;
1818
import net.tfminecraft.advancedcrafting.objects.crafting.hits.CraftingHit;
1919
import net.tfminecraft.advancedcrafting.objects.data.AlloyRecipe;
20+
import net.tfminecraft.advancedcrafting.objects.data.ScrapProvenance;
2021
import net.tfminecraft.advancedcrafting.objects.data.StatData;
2122
import net.tfminecraft.advancedcrafting.objects.ingredients.Ingredient;
2223
import net.tfminecraft.advancedcrafting.objects.stats.StatModifier;
@@ -86,6 +87,7 @@ public NamableAlloy forge(Player p, int i) {
8687
String scrapId = Cache.scrap.split("\\.")[1].toUpperCase();
8788
ItemManager itemManager = MMOItems.plugin.getItems();
8889
ItemStack template = itemManager.getMMOItem(MMOItems.plugin.getTypes().get(scrapType),scrapId).newBuilder().build();
90+
if(station.getBaseItem() != null) ScrapProvenance.applyTo(template, station.getBaseItem().getId());
8991
loc.getWorld().dropItem(loc, template);
9092
return null;
9193
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.tfminecraft.advancedcrafting.objects.data;
2+
3+
import java.util.Locale;
4+
5+
import org.bukkit.inventory.ItemStack;
6+
import org.bukkit.inventory.meta.ItemMeta;
7+
import org.bukkit.persistence.PersistentDataType;
8+
9+
import net.tfminecraft.advancedcrafting.utils.PDCKeys;
10+
11+
/**
12+
* Records which base ingredient a failed alloy forge consumed, so scrap can be recycled into it.
13+
*/
14+
public final class ScrapProvenance {
15+
private ScrapProvenance() {
16+
}
17+
18+
public static void applyTo(ItemStack item, String baseId) {
19+
if (item == null || baseId == null || baseId.isBlank()) {
20+
return;
21+
}
22+
ItemMeta meta = item.getItemMeta();
23+
if (meta == null) {
24+
return;
25+
}
26+
meta.getPersistentDataContainer().set(PDCKeys.scrapBase(), PersistentDataType.STRING, baseId.toLowerCase(Locale.ROOT));
27+
item.setItemMeta(meta);
28+
}
29+
30+
/** Base ingredient id the scrap came from, or null for untagged items (including scrap forged before tagging). */
31+
public static String readBaseId(ItemStack item) {
32+
if (item == null || !item.hasItemMeta()) {
33+
return null;
34+
}
35+
return item.getItemMeta().getPersistentDataContainer().get(PDCKeys.scrapBase(), PersistentDataType.STRING);
36+
}
37+
}

‎src/main/java/net/tfminecraft/advancedcrafting/utils/PDCKeys.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public static NamespacedKey craftStatTemplateRevision() {
2424
return new NamespacedKey(AdvancedCrafting.plugin, "ac_craft_stat_template_revision");
2525
}
2626

27+
public static NamespacedKey scrapBase() {
28+
return new NamespacedKey(AdvancedCrafting.plugin, "ac_scrap_base");
29+
}
30+
2731
public static NamespacedKey ingredientId() {
2832
return new NamespacedKey(AdvancedCrafting.plugin, "ac_ingredient_id");
2933
}

0 commit comments

Comments
 (0)