Merge pull request 'Support all wood types in the stonecutter and classify crafted materials' (#512) from release/woodcutting-grades-20261123 into main
This commit is contained in:
commit
683095bcda
12 changed files with 1865 additions and 227 deletions
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "0.5.18"
|
||||
version = "0.5.18-wood1"
|
||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/") }
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
|
|
@ -12,3 +12,4 @@ tasks.test { useJUnitPlatform() }
|
|||
java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) }
|
||||
tasks.withType<JavaCompile> { options.encoding = "UTF-8" }
|
||||
tasks.jar { archiveFileName.set("jarvistranslator.jar") }
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.dunerealms.jarvis;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** Canonical material grades, never per-craft provenance: equal materials keep stacking. */
|
||||
final class CraftingGrades {
|
||||
record Recipe(String result,List<Set<String>> ingredients){}
|
||||
static Map<String,Integer> resolve(Map<String,Integer> nativeMarks,Map<String,Integer> fixed,List<Recipe> recipes){
|
||||
Set<String> outputs=new HashSet<>();for(var recipe:recipes)outputs.add(recipe.result());
|
||||
Map<String,Integer> marks=new HashMap<>(fixed);
|
||||
nativeMarks.forEach((material,mark)->{if(!outputs.contains(material))marks.putIfAbsent(material,mark);});
|
||||
boolean changed;
|
||||
do{
|
||||
changed=false;
|
||||
for(var recipe:recipes){
|
||||
if(fixed.containsKey(recipe.result())||recipe.ingredients().isEmpty())continue;
|
||||
int highest=-1;boolean ready=true;
|
||||
for(var choices:recipe.ingredients()){
|
||||
int lowest=15;
|
||||
for(String choice:choices)if(!choice.equals(recipe.result())&&marks.containsKey(choice))lowest=Math.min(lowest,marks.get(choice));
|
||||
if(lowest==15){ready=false;break;}highest=Math.max(highest,lowest);
|
||||
}
|
||||
if(!ready)continue;
|
||||
int next=Math.min(14,highest+1),old=marks.getOrDefault(recipe.result(),15);
|
||||
if(next<old){marks.put(recipe.result(),next);changed=true;}
|
||||
}
|
||||
}while(changed);
|
||||
// A cycle without any obtainable base material is not an upgrade source.
|
||||
nativeMarks.forEach(marks::putIfAbsent);return Map.copyOf(marks);
|
||||
}
|
||||
static String quality(int mark){return List.of("common","uncommon","rare","very_rare","legendary").get(mark/3);}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ final class ItemMetadataOverlay implements Listener {
|
|||
private final Plugin plugin;
|
||||
private final ItemMetadataPolicy policy;
|
||||
private final Map<Material,ItemMetadataPolicy.Grade> nativeGrades=new EnumMap<>(Material.class);
|
||||
private final Map<Material,ItemMetadataPolicy.Grade> craftingGrades=new EnumMap<>(Material.class);
|
||||
private final Set<UUID> pending=new HashSet<>();
|
||||
ItemMetadataOverlay(Plugin plugin)throws IOException {
|
||||
this.plugin=plugin;policy=new ItemMetadataPolicy(plugin.getResource("item-templates.json"));
|
||||
|
|
@ -58,6 +59,7 @@ final class ItemMetadataOverlay implements Listener {
|
|||
var grade=engine==null?null:policy.template(engine,item.getType().name());
|
||||
if(grade==null&&"spice".equals(legacy))grade=policy.template("spice",item.getType().name());
|
||||
if(grade==null&&engine==null&&legacy==null)grade=policy.materialGrade(item.getType().name());
|
||||
if(grade==null&&engine==null&&legacy==null)grade=craftingGrades.get(item.getType());
|
||||
if(grade==null&&ItemMetadataPolicy.VERSION.equals(data.get(POLICY,PersistentDataType.STRING))){
|
||||
String mark=data.has(MARK,PersistentDataType.STRING)?data.get(MARK,PersistentDataType.STRING):null;
|
||||
Integer oldMark=data.has(MARK,PersistentDataType.INTEGER)?data.get(MARK,PersistentDataType.INTEGER):null;
|
||||
|
|
@ -121,7 +123,32 @@ final class ItemMetadataOverlay implements Listener {
|
|||
else throw new IllegalArgumentException("Unsupported native cooking recipe");
|
||||
copy.setGroup(source.getGroup());copy.setCategory(source.getCategory());return copy;
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void serverLoaded(org.bukkit.event.server.ServerLoadEvent e){cookingRecipes();}
|
||||
private static Set<String> materials(RecipeChoice choice){
|
||||
if(choice instanceof RecipeChoice.MaterialChoice material)return new HashSet<>(material.getChoices().stream().map(Enum::name).toList());
|
||||
return Set.of(); // Exact/custom item recipes own their issued metadata.
|
||||
}
|
||||
private void craftingRecipes(){
|
||||
Map<String,Integer> baseline=new HashMap<>(),fixed=new HashMap<>();var recipes=new ArrayList<CraftingGrades.Recipe>();
|
||||
for(Material material:Material.values())if(material.isItem()&&!material.isAir()){
|
||||
baseline.put(material.name(),Integer.parseInt(nativeGrade(material).mark()));
|
||||
var grade=policy.materialGrade(material.name());if(grade!=null&&!grade.mark().equals("infinite"))fixed.put(material.name(),Integer.parseInt(grade.mark()));
|
||||
}
|
||||
var iterator=Bukkit.recipeIterator();while(iterator.hasNext()){
|
||||
var recipe=iterator.next();if(!(recipe instanceof Keyed keyed))continue;
|
||||
if(!keyed.getKey().getNamespace().equals("minecraft")&&(!(recipe instanceof StonecuttingRecipe)||recipe.getResult().hasItemMeta()))continue;
|
||||
List<RecipeChoice> inputs;
|
||||
if(recipe instanceof ShapedRecipe shaped)inputs=new ArrayList<>(shaped.getChoiceMap().values());
|
||||
else if(recipe instanceof ShapelessRecipe shapeless)inputs=shapeless.getChoiceList();
|
||||
else if(recipe instanceof StonecuttingRecipe stone)inputs=List.of(stone.getInputChoice());
|
||||
else if(recipe instanceof SmithingTransformRecipe smith)inputs=List.of(smith.getBase(),smith.getAddition(),smith.getTemplate());
|
||||
else continue;
|
||||
var choices=inputs.stream().filter(Objects::nonNull).map(ItemMetadataOverlay::materials).toList();
|
||||
if(!choices.isEmpty()&&choices.stream().noneMatch(Set::isEmpty))recipes.add(new CraftingGrades.Recipe(recipe.getResult().getType().name(),choices));
|
||||
}
|
||||
var resolved=CraftingGrades.resolve(baseline,fixed,recipes);craftingGrades.clear();
|
||||
resolved.forEach((name,mark)->{if(!fixed.containsKey(name))craftingGrades.put(Material.valueOf(name),new ItemMetadataPolicy.Grade(CraftingGrades.quality(mark),String.valueOf(mark),"resource"));});
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void serverLoaded(org.bukkit.event.server.ServerLoadEvent e){craftingRecipes();cookingRecipes();for(Player p:Bukkit.getOnlinePlayers())later(p);}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void join(PlayerJoinEvent e){later(e.getPlayer());}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void open(InventoryOpenEvent e){if(e.getPlayer() instanceof Player p)later(p);}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void close(InventoryCloseEvent e){if(e.getPlayer() instanceof Player p)later(p);}
|
||||
|
|
@ -136,6 +163,10 @@ final class ItemMetadataOverlay implements Listener {
|
|||
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public void moved(InventoryMoveItemEvent e){Bukkit.getScheduler().runTask(plugin,()->{inventory(e.getSource());inventory(e.getDestination());});}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void smelt(FurnaceSmeltEvent e){var result=e.getResult().clone();stamp(result);e.setResult(result);}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void craft(PrepareItemCraftEvent e){var result=e.getInventory().getResult();if(result!=null){result=result.clone();stamp(result);e.getInventory().setResult(result);}}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void stonecut(io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent e){
|
||||
var source=e.getStonecuttingRecipe();var result=source.getResult().clone();stamp(result);
|
||||
var recipe=new StonecuttingRecipe(source.getKey(),result,source.getInputChoice());recipe.setGroup(source.getGroup());e.setStonecuttingRecipe(recipe);
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void died(EntityDeathEvent e){for(var item:e.getDrops())stamp(item);}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void creative(InventoryCreativeEvent e){if(e.getWhoClicked() instanceof Player p)later(p);}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
@Override public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(this,this);
|
||||
new EquipmentLoreStyle(this);
|
||||
new WoodcuttingSupport(this);
|
||||
WorldDefaults.start(this);
|
||||
TerrainAuthority.start(this);
|
||||
try { itemMetadata=new ItemMetadataOverlay(this);exchangeInventory=new ExchangeInventory(item->itemMetadata.stamp(item));itemPreview=new ItemDesignPreview(new ItemMetadataPolicy(getResource("item-templates.json"))); }
|
||||
|
|
@ -147,3 +148,4 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
|
|||
}
|
||||
@Override public void onDisable() { if(questObservations!=null)questObservations.close();if(nativeKeys!=null)nativeKeys.close();if (actions != null) actions.close(); if (api != null) api.close(); }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.dunerealms.jarvis;
|
||||
import java.util.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/** Complete missing native WoodCutting recipes without replacing its existing recipes. */
|
||||
final class WoodcuttingSupport implements Listener {
|
||||
private final Plugin plugin;
|
||||
WoodcuttingSupport(Plugin plugin){this.plugin=plugin;Bukkit.getPluginManager().registerEvents(this,plugin);}
|
||||
@EventHandler(priority=EventPriority.LOWEST) public void loaded(org.bukkit.event.server.ServerLoadEvent event){
|
||||
if(!Bukkit.getPluginManager().isPluginEnabled("wood_cutting"))return;
|
||||
Set<String> existing=new HashSet<>();var iterator=Bukkit.recipeIterator();
|
||||
while(iterator.hasNext())if(iterator.next() instanceof StonecuttingRecipe recipe&&recipe.getInputChoice() instanceof RecipeChoice.MaterialChoice input)for(Material source:input.getChoices())existing.add(source+":"+recipe.getResult().getType());
|
||||
Map<String,Integer> counts=new LinkedHashMap<>();counts.put("PLANKS",4);counts.put("STAIRS",4);counts.put("SLAB",8);counts.put("FENCE",3);counts.put("FENCE_GATE",1);counts.put("DOOR",2);counts.put("TRAPDOOR",2);counts.put("PRESSURE_PLATE",2);counts.put("BUTTON",4);counts.put("SIGN",2);
|
||||
int added=0;
|
||||
for(String wood:List.of("OAK","SPRUCE","BIRCH","JUNGLE","ACACIA","DARK_OAK","MANGROVE","CHERRY","PALE_OAK","CRIMSON","WARPED","BAMBOO")){
|
||||
String[] suffixes=wood.equals("BAMBOO")?new String[]{"BLOCK"}:wood.equals("CRIMSON")||wood.equals("WARPED")?new String[]{"STEM","HYPHAE"}:new String[]{"LOG","WOOD"};
|
||||
for(String suffix:suffixes)for(String prefix:List.of("","STRIPPED_")){
|
||||
Material source=Material.matchMaterial(prefix+wood+"_"+suffix);if(source==null)continue;
|
||||
for(var output:counts.entrySet()){
|
||||
Material target=Material.matchMaterial(wood+"_"+output.getKey());if(target==null||existing.contains(source+":"+target))continue;
|
||||
int count=wood.equals("BAMBOO")?Math.max(1,output.getValue()/2):output.getValue();
|
||||
var key=new NamespacedKey("dunerealms","woodcutting/"+source.name().toLowerCase(Locale.ROOT)+"/"+target.name().toLowerCase(Locale.ROOT));
|
||||
if(Bukkit.getRecipe(key)==null&&Bukkit.addRecipe(new StonecuttingRecipe(key,new ItemStack(target,count),source))){existing.add(source+":"+target);added++;}
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLogger().info("WoodCutting native recipe complements registered: "+added);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
name: JarvisTranslator
|
||||
main: com.dunerealms.jarvis.JarvisTranslator
|
||||
version: 0.5.18
|
||||
version: 0.5.18-wood1
|
||||
api-version: '1.21.8'
|
||||
description: Shared J.A.R.V.I.S. website API and native server action translator.
|
||||
softdepend: [SCore, ExecutableItems, ExecutableCrafting, DuneEss, ImageFrame, DecentHolograms, MedievalFactions, Towny, WorldGuard]
|
||||
|
|
@ -12,3 +12,4 @@ commands:
|
|||
permissions:
|
||||
dunerealms.jarvis.status:
|
||||
default: op
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.dunerealms.jarvis;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class CraftingGradesTest {
|
||||
private CraftingGrades.Recipe recipe(String output,String...inputs){return new CraftingGrades.Recipe(output,Arrays.stream(inputs).map(Set::of).toList());}
|
||||
@Test void processingAddsOneAndRaisesQualityWithoutPromotingReverseRecipes(){
|
||||
var recipes=List.of(recipe("powder","rod"),recipe("eye","powder","pearl"),recipe("crystal","eye","tear"),recipe("rod","powder"));
|
||||
var grades=CraftingGrades.resolve(Map.of("rod",1,"powder",1,"eye",1,"pearl",1,"crystal",1,"tear",1),Map.of("rod",6,"pearl",6,"tear",8),recipes);
|
||||
assertEquals(7,grades.get("powder"));assertEquals(8,grades.get("eye"));assertEquals(9,grades.get("crystal"));assertEquals("very_rare",CraftingGrades.quality(grades.get("crystal")));assertEquals(6,grades.get("rod"));
|
||||
}
|
||||
@Test void alternativeRecipesHaveOneStableMaterialGradeAndRespectSeasonCap(){
|
||||
var grades=CraftingGrades.resolve(Map.of("cheap",1,"costly",14,"output",1,"final",1),Map.of("cheap",2,"costly",14),List.of(recipe("output","costly"),recipe("output","cheap"),recipe("final","costly")));
|
||||
assertEquals(3,grades.get("output"));assertEquals(14,grades.get("final"));
|
||||
}
|
||||
@Test void unanchoredCyclesCannotManufactureMarks(){
|
||||
assertEquals(Map.of("a",1,"b",1),CraftingGrades.resolve(Map.of("a",1,"b",1),Map.of(),List.of(recipe("a","b"),recipe("b","a"))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20,12 +20,20 @@ class ItemMetadataPolicyTest {
|
|||
assertEquals(new ItemMetadataPolicy.Grade("very_rare","9","resource"),p.materialGrade("ANCIENT_DEBRIS"));
|
||||
assertEquals(new ItemMetadataPolicy.Grade("very_rare","10","resource"),p.materialGrade("NETHERITE_SCRAP"));
|
||||
assertEquals(new ItemMetadataPolicy.Grade("legendary","14","resource"),p.materialGrade("NETHERITE_INGOT"));
|
||||
assertNull(p.materialGrade("DIAMOND_SWORD"));assertNull(p.materialGrade("BONE"));
|
||||
assertNull(p.materialGrade("DIAMOND_SWORD"));assertEquals("3",p.materialGrade("BONE").mark());
|
||||
}
|
||||
@Test void compactedResourcesAdvanceOneMarkAndCrossQualityBoundaries()throws Exception{
|
||||
var p=policy();
|
||||
String[][] pairs={{"COPPER_INGOT","COPPER_BLOCK"},{"IRON_INGOT","IRON_BLOCK"},{"GOLD_INGOT","GOLD_BLOCK"},{"LAPIS_LAZULI","LAPIS_BLOCK"},{"REDSTONE","REDSTONE_BLOCK"},{"EMERALD","EMERALD_BLOCK"},{"DIAMOND","DIAMOND_BLOCK"},{"COAL","COAL_BLOCK"},{"NETHERITE_INGOT","NETHERITE_BLOCK"}};
|
||||
String[] qualities={"common","uncommon","rare","very_rare","legendary"};
|
||||
for(var pair:pairs){int mark=Math.min(14,Integer.parseInt(p.materialGrade(pair[0]).mark())+1);assertEquals(new ItemMetadataPolicy.Grade(qualities[mark/3],String.valueOf(mark),"resource"),p.materialGrade(pair[1]));}
|
||||
// A named pet memorial remains distinct from the ordinary skeleton drop.
|
||||
assertEquals("uncommon",p.materialGrade("BONE").quality());
|
||||
}
|
||||
@Test void workstationsAndRedstoneHaveTheirAssignedMarks()throws Exception{
|
||||
var p=policy();
|
||||
for(String material:new String[]{"BLAST_FURNACE","SMOKER","CARTOGRAPHY_TABLE","BREWING_STAND","COMPOSTER","BARREL","FLETCHING_TABLE","CAULDRON","LECTERN","STONECUTTER","LOOM","SMITHING_TABLE","GRINDSTONE"})assertEquals(new ItemMetadataPolicy.Grade("common","2","resource"),p.materialGrade(material));
|
||||
for(String material:new String[]{"REDSTONE","REDSTONE_ORE","PISTON","HOPPER","RAIL","REPEATER","OAK_BUTTON","WAXED_OXIDIZED_COPPER_BULB"})assertEquals(new ItemMetadataPolicy.Grade("uncommon","3","resource"),p.materialGrade(material));
|
||||
for(String material:new String[]{"REDSTONE","REDSTONE_ORE","PISTON","HOPPER","RAIL","REPEATER","WAXED_OXIDIZED_COPPER_BULB"})assertEquals(new ItemMetadataPolicy.Grade("uncommon","3","resource"),p.materialGrade(material));
|
||||
}
|
||||
@Test void vanillaExamplesCoverEveryMark()throws Exception{
|
||||
var p=policy();String[] items={"DIRT",null,"STONECUTTER","REDSTONE","RAW_IRON","RAW_GOLD","COPPER_INGOT","IRON_INGOT","GOLD_INGOT","ANCIENT_DEBRIS","NETHERITE_SCRAP","ENCHANTED_GOLDEN_APPLE","NETHERITE_PICKAXE","NETHERITE_HELMET","NETHERITE_INGOT"};
|
||||
|
|
|
|||
11
tools/woodcutting-config.yml
Normal file
11
tools/woodcutting-config.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Native WoodCutting config; missing/stripped/bamboo recipes completed by JarvisTranslator.
|
||||
BUTTON: 4
|
||||
FENCE: 3
|
||||
FENCE_GATE: 1
|
||||
PLANKS: 4
|
||||
PRESSURE_PLAT: 2
|
||||
SIGN: 2
|
||||
SLAB: 8
|
||||
STAIRS: 4
|
||||
TRAPDOOR: 2
|
||||
DOOR: 2
|
||||
File diff suppressed because it is too large
Load diff
20
website/tests/material-processing-grades.test.mjs
Normal file
20
website/tests/material-processing-grades.test.mjs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {MATERIAL_ITEM_GRADES as grades,itemTemplateCatalogue} from '../control-panel/public/item-metadata-policy.mjs';
|
||||
import {qualityForMark} from '../control-panel/public/equipment-template-policy.mjs';
|
||||
test('compressed resources use the next mark and its matching quality, capped at S1 MK14',()=>{
|
||||
for(const [base,block] of Object.entries({COPPER_INGOT:'COPPER_BLOCK',IRON_INGOT:'IRON_BLOCK',GOLD_INGOT:'GOLD_BLOCK',NETHERITE_INGOT:'NETHERITE_BLOCK',LAPIS_LAZULI:'LAPIS_BLOCK',REDSTONE:'REDSTONE_BLOCK',EMERALD:'EMERALD_BLOCK',DIAMOND:'DIAMOND_BLOCK',COAL:'COAL_BLOCK'})){
|
||||
const mark=Math.min(14,grades[base].equipmentMark+1);
|
||||
assert.deepEqual(grades[block],{quality:qualityForMark(mark),equipmentMark:mark,itemClass:'resource'});
|
||||
}
|
||||
});
|
||||
test('mob processing advances grades without changing custom item identities',()=>{
|
||||
assert.equal(grades.BLAZE_POWDER.equipmentMark,7);
|
||||
assert.equal(grades.ENDER_EYE.equipmentMark,8);
|
||||
assert.equal(grades.END_CRYSTAL.equipmentMark,9);
|
||||
assert.equal(grades.END_CRYSTAL.quality,'very_rare');
|
||||
assert.equal(grades.BONE.quality,'uncommon');
|
||||
const catalogue=itemTemplateCatalogue();
|
||||
assert.equal(catalogue.templates.refined_spice.quality,'rare');
|
||||
assert.equal(catalogue.templates.dr_imperial_codex.equipmentMark,1);
|
||||
});
|
||||
Loading…
Reference in a new issue

Staff