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 @@ -247,23 +247,17 @@ public StationFeedback addMaterial(Player p, ItemStack i) {
return StationFeedback.SUCCESS;
}

/** Lines the branding tool shows on right-click: recipe, materials, and the current count of every configured hit. */
/**
* Lines the branding tool shows on right-click: the recipe and the material groups still to fill.
* Players have to find the hits themselves, so per-hit counts stay out of it.
*/
public List<String> getStatusLines() {
List<String> lines = new ArrayList<>();
lines.add("§7Recipe: " + recipe.getCleanedName());
for (Map.Entry<IngredientType, IntCounter> e : types.entrySet()) {
if (e.getKey() == null) continue;
lines.add(e.getKey().getName() + "§7: §e" + e.getValue().getCurrent() + "/" + e.getValue().getNeeded());
}
// Counted by id: a reload replaces the hit objects this station was keyed with.
Map<String, Integer> done = new HashMap<>();
for (Map.Entry<CraftingHit, IntCounter> e : hits.entrySet()) {
if (e.getKey() == null) continue;
done.merge(e.getKey().getId(), e.getValue().getCurrent(), Integer::sum);
}
for (CraftingHit hit : HitLoader.get().values()) {
lines.add(hit.getName() + "§7: §e" + done.getOrDefault(hit.getId(), 0));
}
lines.add("§7Left-click branding to finish");
lines.add("§cSHIFT + LEFT CLICK with the branding tool to cancel the project!");
return lines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ void rightClickWithBrandingShowsStatusInsteadOfAddingIt() throws Exception {
var m = new CraftingManager();
var s = station(m, b);
when(s.hasRecipe()).thenReturn(true);
when(s.getStatusLines()).thenReturn(List.of("§7Recipe: Sword", "Strike§7: §e3"));
when(s.getStatusLines()).thenReturn(List.of("§7Recipe: Sword", "Metal§7: §e1/2"));
p.getInventory().setItemInMainHand(new ItemStack(Material.STICK));
Cache.brandingTool = "v.stick";
when(items.getChecker().checkItemWithPath(any(), eq(Cache.brandingTool))).thenReturn(true);
m.openStation(event(p, b, Action.RIGHT_CLICK_BLOCK));
verify(s, never()).addMaterial(any(), any());
verify(p).sendMessage("§7Recipe: Sword");
verify(p).sendMessage("Strike§7: §e3");
verify(p).sendMessage("Metal§7: §e1/2");
when(items.getChecker().checkItemWithPath(any(), eq(Cache.brandingTool))).thenReturn(false);
when(s.addMaterial(eq(p), any())).thenReturn(StationFeedback.NOT_INGREDIENT);
map(m, "cooldown").clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,21 @@ void materialAdmissionChecksItemTypePermissionsRecipeAndCapacity() throws Except
}

@Test
void statusLinesListEveryConfiguredHitWithItsCount() throws Exception {
void statusLinesShowMaterialsButNoHitCounts() throws Exception {
var p = server.addPlayer();
HitLoader.map.put("tap", new CraftingHit("tap", yaml("name: Tap\ntype: hammer\ntool: v.stick")));
var station = new CraftingStation(loc());
station.setRecipe(recipe("recipe: ['metal.2']"));
var item = ingredient("iron", "hits: ['strike.2']").build();
p.getInventory().setItemInMainHand(item);
assertEquals(StationFeedback.SUCCESS, station.addMaterial(p, item));
station.getHits().get(HitLoader.map.get("strike")).setCurrent(3);
// A reload swaps in new hit objects; counts must still match by id.
HitLoader.map.put(
"strike", new CraftingHit("strike", yaml("name: Strike\ntype: hammer\ntool: v.iron_axe")));
// Unknown types or hits from a stale config are skipped, not printed as "null".
// Unknown types from a stale config are skipped, not printed as "null".
station.getTypes().put(null, new IntCounter());
station.getHits().put(null, new IntCounter());
// Players have to find the hits themselves, so no hit counts are listed.
assertEquals(
List.of(
"§7Recipe: Sword",
"Metal§7: §e1/2",
"Strike§7: §e3",
"Tap§7: §e0",
"§7Left-click branding to finish",
"§cSHIFT + LEFT CLICK with the branding tool to cancel the project!"),
station.getStatusLines());
Expand Down
Loading