Rename the DuneChest devices to their Ixian labels
Some checks failed
Planet DuneChest Build / dunechest (push) Successful in 54s
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-11-30 19:44:35 +01:00
commit 83deb2c051
8 changed files with 83 additions and 24 deletions

View file

@ -1,6 +1,6 @@
plugins { java }
group = "com.example"
version = "1.0.6"
version = "1.0.7"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")

View file

@ -13,6 +13,13 @@ import org.bukkit.plugin.Plugin;
/** The three custom items, their recipes, and how to recognise them. */
public final class StorageItems {
public static final String ENDER = "ender_chest", HOPPER = "speed_hopper", CRAFTER = "auto_crafter", WRENCH = "wrench", BEACON = "dune_beacon";
static final String POWERCORE_NAME = "Ixian Powercore MK XIV";
static final String REPLICATOR_NAME = "Ixian Replicator MK XIV";
static String hopperName(int tier) {
return "Ixian sorting devices MK " + (StorageRules.Tier.of(tier).ordinal() + 1);
}
private final Plugin plugin; final NamespacedKey type, tier, colors, owner, priv, filter, whitelist, primary, secondary;
StorageItems(Plugin plugin) {
@ -33,13 +40,13 @@ public final class StorageItems {
lore.add(gray("Chests with the same three colours share one inventory."));
lore.add(gray("Right-click a dye on a pad, or use the colour menu.")); lore.add(gray("Right-click a diamond to make it private.")); lore.add(gray("Sneak + empty hand: colour menu.")); m.setItemModel(new NamespacedKey("dunerealms", "ender_chest")); }
case HOPPER -> { int t = Math.max(1, Math.min(3, tierNumber)); var tr = StorageRules.Tier.of(t); pdc.set(tier, PersistentDataType.INTEGER, t);
m.displayName(name("Speed Hopper Mk " + "I".repeat(t), t == 1 ? NamedTextColor.GOLD : t == 2 ? NamedTextColor.AQUA : NamedTextColor.LIGHT_PURPLE));
m.displayName(name(hopperName(t), hopperColour(t)));
lore.add(gray(String.format(Locale.ROOT, "%.0f items/s (vanilla 2.5)", tr.itemsPerSecond()))); lore.add(gray("Sneak + empty hand: item filter.")); lore.add(gray("Or left-click with a Wrench.")); m.setItemModel(new NamespacedKey("dunerealms", "speed_hopper_" + t)); }
case BEACON -> { m.displayName(name("Dune Beacon", NamedTextColor.AQUA));
case BEACON -> { m.displayName(name(POWERCORE_NAME, NamedTextColor.AQUA));
lore.add(gray("Works like a vanilla beacon, but with no beam")); lore.add(gray("and no need for open sky.")); lore.add(gray("Right-click to choose its effects."));
m.setItemModel(new NamespacedKey("dunerealms", "dune_beacon")); }
case WRENCH -> { m.displayName(name("Wrench", NamedTextColor.GOLD)); lore.add(gray("Left-click an Ender Chest, Speed Hopper or Auto Crafter")); lore.add(gray("to open its panel. Works on Bedrock too.")); m.setItemModel(new NamespacedKey("dunerealms", "wrench")); m.setMaxStackSize(1); }
default -> { m.displayName(name("Auto Crafter", NamedTextColor.GREEN)); lore.add(gray("Crafts from the container above into the container below.")); lore.add(gray("Right-click to set the recipe.")); }
case WRENCH -> { m.displayName(name("Wrench", NamedTextColor.GOLD)); lore.add(gray("Left-click a DuneChest device to open its panel.")); lore.add(gray("Works on Bedrock too.")); m.setItemModel(new NamespacedKey("dunerealms", "wrench")); m.setMaxStackSize(1); }
default -> { m.displayName(name(REPLICATOR_NAME, NamedTextColor.GREEN)); lore.add(gray("Crafts from the container above into the container below.")); lore.add(gray("Right-click to set the recipe.")); }
}
m.lore(lore); m.setEnchantmentGlintOverride(true);
item.setItemMeta(m); return item;
@ -52,6 +59,41 @@ public final class StorageItems {
it.setItemMeta(m); return it;
}
private static NamedTextColor hopperColour(int tier) {
return tier == 1 ? NamedTextColor.GOLD : tier == 2 ? NamedTextColor.AQUA : NamedTextColor.LIGHT_PURPLE;
}
private static Component legacyHopperName(int tier) {
return name("Speed Hopper Mk " + "I".repeat(tier), hopperColour(tier));
}
private static ItemStack withDisplayName(ItemStack original, Component label) {
ItemStack copy = original.asOne();
ItemMeta meta = copy.getItemMeta();
meta.displayName(label);
copy.setItemMeta(meta);
return copy;
}
private static RecipeChoice.ExactChoice hopperChoice(ItemStack current, int tier) {
return new RecipeChoice.ExactChoice(current, withDisplayName(current, legacyHopperName(tier)));
}
boolean matchesCraftingIngredient(ItemStack template, ItemStack source) {
if (template.isSimilar(source)) return true;
if (template.getType() != Material.HOPPER || source.getType() != Material.HOPPER
|| !HOPPER.equals(typeOf(template)) || !HOPPER.equals(typeOf(source))) return false;
int tier = tierOf(template);
if (tier < 1 || tier > 3 || tierOf(source) != tier) return false;
Component oldName = legacyHopperName(tier);
Component currentName = name(hopperName(tier), hopperColour(tier));
Component templateName = template.getItemMeta().displayName();
Component sourceName = source.getItemMeta().displayName();
boolean sameTierRename = oldName.equals(templateName) && currentName.equals(sourceName)
|| currentName.equals(templateName) && oldName.equals(sourceName);
return sameTierRename && withDisplayName(template, sourceName).isSimilar(source);
}
private static Component name(String s, NamedTextColor c) { return Component.text(s, c).decoration(TextDecoration.ITALIC, false); }
private static Component gray(String s) { return Component.text(s, NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false); }
@ -93,8 +135,8 @@ public final class StorageItems {
ItemStack ender = create(ENDER, 1), mk1 = create(HOPPER, 1), mk2 = create(HOPPER, 2), mk3 = create(HOPPER, 3), crafter = create(CRAFTER, 1);
shaped("ender_chest", ender, new String[]{"OEO", "OBO", "OOO"}, 'O', Material.OBSIDIAN, 'E', Material.ENDER_EYE, 'B', Material.BARREL);
shaped("speed_hopper_1", mk1, new String[]{"GRG", "RHR", "GRG"}, 'G', Material.GOLD_INGOT, 'R', Material.REDSTONE, 'H', Material.HOPPER);
shaped("speed_hopper_2", mk2, new String[]{"DRD", "RIR", "DRD"}, 'D', Material.DIAMOND, 'R', Material.REDSTONE_BLOCK, 'I', new RecipeChoice.ExactChoice(mk1));
shaped("speed_hopper_3", mk3, new String[]{"NRN", "RIR", "NRN"}, 'N', Material.NETHERITE_INGOT, 'R', Material.REDSTONE_BLOCK, 'I', new RecipeChoice.ExactChoice(mk2));
shaped("speed_hopper_2", mk2, new String[]{"DRD", "RIR", "DRD"}, 'D', Material.DIAMOND, 'R', Material.REDSTONE_BLOCK, 'I', hopperChoice(mk1, 1));
shaped("speed_hopper_3", mk3, new String[]{"NRN", "RIR", "NRN"}, 'N', Material.NETHERITE_INGOT, 'R', Material.REDSTONE_BLOCK, 'I', hopperChoice(mk2, 2));
var bk = new NamespacedKey(plugin, "dune_beacon"); Bukkit.removeRecipe(bk);
var br = new org.bukkit.inventory.ShapelessRecipe(bk, create(BEACON, 1)); br.addIngredient(Material.BEACON); br.addIngredient(Material.ENDER_EYE); Bukkit.addRecipe(br);
shaped("wrench", create(WRENCH, 1), new String[]{"I I", " I ", " S "}, 'I', Material.IRON_INGOT, 'S', Material.STICK);

View file

@ -243,7 +243,7 @@ public final class StorageModule implements Listener, CommandExecutor {
}
private void openFilter(Player pl, String key, StorageData.Placed p) {
Inventory inv = menu("filter", key, 9, "Hopper Filter");
Inventory inv = menu("filter", key, 9, StorageItems.hopperName(p.tier));
for (int i = 0; i < 5 && i < p.filter.size(); i++) inv.setItem(i, new ItemStack(p.filter.get(i)));
inv.setItem(6, icon(p.whitelist ? Material.LIME_DYE : Material.RED_DYE, p.whitelist ? "Whitelist" : "Blacklist", "Click to switch", "Empty filter accepts everything."));
inv.setItem(8, icon(Material.PAPER, "Click a slot with an item to set it", "Click with an empty cursor to clear"));
@ -261,7 +261,7 @@ public final class StorageModule implements Listener, CommandExecutor {
private Inventory recipePreview(Menu holder, World world) {
StorageData.Placed placed = holder.recipeBlock;
Inventory preview = Bukkit.createInventory(holder, InventoryType.WORKBENCH, Component.text("Auto Crafter Recipe"));
Inventory preview = Bukkit.createInventory(holder, InventoryType.WORKBENCH, Component.text(StorageItems.REPLICATOR_NAME));
holder.inventory = preview;
for (int g = 0; g < placed.recipe.length; g++) {
ItemStack item = placed.recipe[g];
@ -437,7 +437,7 @@ public final class StorageModule implements Listener, CommandExecutor {
Recipe r = Bukkit.getCraftingRecipe(p.recipe.clone(), b.getWorld()); if (r == null) return;
ItemStack[] ingredients = src.getStorageContents();
ItemStack[] actualGrid = new ItemStack[p.recipe.length];
int[] consumption = StorageRules.matchIngredients(p.recipe, ingredients, actualGrid);
int[] consumption = StorageRules.matchIngredients(p.recipe, ingredients, actualGrid, items::matchesCraftingIngredient);
if (consumption == null) return;
Recipe actual = Bukkit.getCraftingRecipe(actualGrid, b.getWorld());
if (!(r instanceof Keyed expected) || !(actual instanceof Keyed matched)
@ -514,13 +514,13 @@ public final class StorageModule implements Listener, CommandExecutor {
int level = beaconLevel(b);
Inventory model = Bukkit.createInventory(null, 27); Map<Integer, Runnable> actions = new HashMap<>();
String now = p.primary == null ? "No effect set" : pretty(p.primary) + (p.secondary == null ? "" : " + " + (p.secondary.equals(p.primary) ? "power II" : pretty(p.secondary)));
model.setItem(4, legacyIcon(Material.SEA_LANTERN, "Dune Beacon", level == 0 ? "No pyramid below - build iron, gold, emerald, diamond or netherite blocks" : "Level " + level + " - range " + BeaconRules.range(level) + " blocks", now));
model.setItem(4, legacyIcon(Material.SEA_LANTERN, StorageItems.POWERCORE_NAME, level == 0 ? "No pyramid below - build iron, gold, emerald, diamond or netherite blocks" : "Level " + level + " - range " + BeaconRules.range(level) + " blocks", now));
var options = BeaconRules.primaries(level); int slot = 10;
for (String name : options) { final String choice = name; int sl = slot++;
model.setItem(sl, legacyIcon(effectIcon(name), pretty(name), level >= 4 ? "Choose, then pick a secondary" : "Click to set", level >= 4 ? "" : payText()));
actions.put(sl, () -> { if (level >= 4) beaconSecondary(pl, key, p, choice); else beaconConfirm(pl, key, p, choice, null); });
}
com.example.dunegui.NativeMenus.inventory(plugin, pl, "Dune Beacon", model, actions);
com.example.dunegui.NativeMenus.inventory(plugin, pl, StorageItems.POWERCORE_NAME, model, actions);
}
private void beaconSecondary(Player pl, String key, StorageData.Placed expected, String primary) {
Block block = currentBeacon(pl, key, expected);
@ -535,7 +535,7 @@ public final class StorageModule implements Listener, CommandExecutor {
actions.put(sl, () -> beaconConfirm(pl, key, expected, primary, choice)); }
model.setItem(slot, legacyIcon(Material.BARRIER, "No secondary", "Primary only"));
actions.put(slot, () -> beaconConfirm(pl, key, expected, primary, null));
com.example.dunegui.NativeMenus.inventory(plugin, pl, "Dune Beacon", model, actions);
com.example.dunegui.NativeMenus.inventory(plugin, pl, StorageItems.POWERCORE_NAME, model, actions);
}
private static boolean beaconPayment(ItemStack item) {
if (item == null || item.isEmpty() || !PAYMENT.contains(item.getType())) return false;
@ -574,7 +574,7 @@ public final class StorageModule implements Listener, CommandExecutor {
inventory.setItem(paymentSlot, payment.getAmount() == 1 ? null : payment.asQuantity(payment.getAmount() - 1));
}
p.primary = primary; p.secondary = secondary; data.dirty = true;
say(pl, "Beacon set: " + pretty(primary) + (secondary == null ? "" : " + " + (secondary.equals(primary) ? "power II" : pretty(secondary))) + ".");
say(pl, StorageItems.POWERCORE_NAME + " set: " + pretty(primary) + (secondary == null ? "" : " + " + (secondary.equals(primary) ? "power II" : pretty(secondary))) + ".");
beaconPulse(block, p);
}
@ -644,13 +644,13 @@ public final class StorageModule implements Listener, CommandExecutor {
/** Click-free way in for clients that cannot sneak-click: opens the settings of the storage block being looked at (within 5 blocks). */
private void settingsAtCrosshair(Player pl) {
Block b = pl.getTargetBlockExact(5); var p = b == null ? null : data.at(b);
if (p == null) { say(pl, "Look at an Ender Chest or Speed Hopper (within 5 blocks), or left-click it with a Wrench."); return; }
if (p == null) { say(pl, "Look at a DuneChest device within 5 blocks, or left-click it with a Wrench."); return; }
panel(pl, b, p);
}
// ---------- /dunechest give ----------
@Override public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
if (a.length >= 1 && a[0].equalsIgnoreCase("panel") && s instanceof Player pl) { settingsAtCrosshair(pl); return true; }
if (!s.hasPermission("dune.admin")) { s.sendMessage("Look at an Ender Chest or Speed Hopper and use a Wrench or /dunechest panel."); return true; }
if (!s.hasPermission("dune.admin")) { s.sendMessage("Look at a DuneChest device and use a Wrench or /dunechest panel."); return true; }
if (a.length < 2 || !a[0].equalsIgnoreCase("give")) { s.sendMessage("/dunechest give <player> <ender|hopper1|hopper2|hopper3|crafter|wrench|beacon> [amount]"); return true; }
Player t = Bukkit.getPlayerExact(a[1]); if (t == null || a.length < 3) { s.sendMessage("Player offline or missing item."); return true; }
ItemStack item = switch (a[2].toLowerCase(Locale.ROOT)) { case "ender" -> items.create(StorageItems.ENDER, 1); case "hopper1" -> items.create(StorageItems.HOPPER, 1);

View file

@ -1,6 +1,7 @@
package com.example.dunechest;
import java.util.*;
import java.util.function.BiPredicate;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
@ -75,7 +76,8 @@ public final class StorageRules {
}
/** Build a grid of real inputs and reserve their source slots without changing the inventory. */
static int[] matchIngredients(ItemStack[] template, ItemStack[] source, ItemStack[] actualGrid) {
static int[] matchIngredients(ItemStack[] template, ItemStack[] source, ItemStack[] actualGrid,
BiPredicate<ItemStack, ItemStack> matches) {
int[] consumption = new int[source.length];
for (int gridSlot = 0; gridSlot < template.length; gridSlot++) {
ItemStack ingredient = template[gridSlot];
@ -83,7 +85,7 @@ public final class StorageRules {
int slot = 0;
while (slot < source.length) {
ItemStack stack = source[slot];
if (stack != null && stack.getAmount() > consumption[slot] && ingredient.isSimilar(stack)) break;
if (stack != null && stack.getAmount() > consumption[slot] && matches.test(ingredient, stack)) break;
slot++;
}
if (slot == source.length) return null;

View file

@ -1,5 +1,5 @@
name: DuneChest
version: 1.0.6
version: 1.0.7
main: com.example.dunechest.DuneChest
api-version: '1.21.8'
softdepend: [floodgate, DuneMenus, DuneEss]

View file

@ -5,6 +5,9 @@ import com.example.dunechest.StorageModule;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@ -35,7 +38,7 @@ public final class DuneChestPaperValidation extends JavaPlugin implements Listen
Bukkit.getScheduler().runTask(this, () -> {
try {
validateCrafter();
getLogger().info("DUNECHEST_VALIDATION {\"ok\":true,\"cases\":6}");
getLogger().info("DUNECHEST_VALIDATION {\"ok\":true,\"cases\":7}");
} catch (Exception | AssertionError failure) {
getLogger().log(java.util.logging.Level.SEVERE, "DUNECHEST_VALIDATION {\"ok\":false}", failure);
} finally {
@ -85,6 +88,18 @@ public final class DuneChestPaperValidation extends JavaPlugin implements Listen
throw new AssertionError("Valid upgrade did not credit and debit the exact stacks");
}
validateRecipePreview(module, table.getWorld(), placedType, placed, mk1, mk2);
ItemStack legacy = mk1.clone();
var legacyMeta = legacy.getItemMeta();
legacyMeta.displayName(Component.text("Speed Hopper Mk I", NamedTextColor.GOLD)
.decoration(TextDecoration.ITALIC, false));
legacy.setItemMeta(legacyMeta);
load(input, legacy, 4, redstone);
output.clear();
craft.invoke(module, table, placed);
if (!output.containsAtLeast(mk2, 1) || !input.isEmpty()) {
throw new AssertionError("Renaming the hopper broke upgrades using the previous name");
}
}
private void validateRecipePreview(StorageModule module, World world, Class<?> placedType,

View file

@ -60,11 +60,11 @@ class StorageRulesTest {
ItemStack mk2 = new HopperStack(2, 2);
ItemStack vanilla = new HopperStack(0, 64);
assertNull(StorageRules.matchIngredients(new ItemStack[]{mk1}, new ItemStack[]{vanilla, mk2}, new ItemStack[1]));
assertNull(StorageRules.matchIngredients(new ItemStack[]{mk1, mk1}, new ItemStack[]{vanilla, mk1}, new ItemStack[2]));
assertNull(StorageRules.matchIngredients(new ItemStack[]{mk1}, new ItemStack[]{vanilla, mk2}, new ItemStack[1], ItemStack::isSimilar));
assertNull(StorageRules.matchIngredients(new ItemStack[]{mk1, mk1}, new ItemStack[]{vanilla, mk1}, new ItemStack[2], ItemStack::isSimilar));
ItemStack[] actualGrid = new ItemStack[3];
assertArrayEquals(new int[]{0, 0, 2}, StorageRules.matchIngredients(
new ItemStack[]{mk2, null, mk2}, new ItemStack[]{vanilla, mk1, mk2}, actualGrid));
new ItemStack[]{mk2, null, mk2}, new ItemStack[]{vanilla, mk1, mk2}, actualGrid, ItemStack::isSimilar));
assertTrue(mk2.isSimilar(actualGrid[0]));
assertNull(actualGrid[1]);
assertEquals(1, actualGrid[2].getAmount());

View file

@ -277,7 +277,7 @@ def plan(artifacts, inventory, expected_source):
installed=existing_paths.get('dunechest')
approved_dunechest = {
chosen[0]['sha256'],
'0c56c56e03310572e0fc1f603d4fd23230456c64ab9d2892f3a0849fb349a1ae',
'94e591f11f10c3174c821bbfc8734f50a9638981e17269db2682be6e36d8fb97',
}
if installed is not None and digest(installed) not in approved_dunechest:
raise ValueError('Existing DuneChest differs from the approved release or predecessor')