From c19d4e6610921aeedf02afc86fb716c0a54f4319 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:31:33 +0100 Subject: [PATCH] Integrate the beamless Dune Beacon --- DuneChest/build.gradle.kts | 2 +- .../com/example/dunechest/BeaconRules.java | 32 ++++++ .../com/example/dunechest/StorageData.java | 8 +- .../com/example/dunechest/StorageItems.java | 18 ++- .../com/example/dunechest/StorageModule.java | 106 +++++++++++++++++- DuneChest/src/main/resources/plugin.yml | 4 +- .../example/dunechest/BeaconRulesTest.java | 30 +++++ DuneChest/tools/dunechest_art.py | 24 ++++ DuneMenus/build.gradle.kts | 2 + .../assets/dunerealms/items/dune_beacon.json | 1 + .../dunerealms/models/block/dune_beacon.json | 1 + .../dunerealms/models/item/dune_beacon.json | 1 + .../textures/block/dune_beacon_crystal.png | Bin 0 -> 332 bytes .../textures/block/dune_beacon_frame.png | Bin 0 -> 1026 bytes tools/install-plugin-fleet.py | 2 +- tools/plugin_dunechest_pack.py | 4 +- 16 files changed, 220 insertions(+), 15 deletions(-) create mode 100644 DuneChest/src/main/java/com/example/dunechest/BeaconRules.java create mode 100644 DuneChest/src/test/java/com/example/dunechest/BeaconRulesTest.java create mode 100644 network/resource-pack/central/overlay/assets/dunerealms/items/dune_beacon.json create mode 100644 network/resource-pack/central/overlay/assets/dunerealms/models/block/dune_beacon.json create mode 100644 network/resource-pack/central/overlay/assets/dunerealms/models/item/dune_beacon.json create mode 100644 network/resource-pack/central/overlay/assets/dunerealms/textures/block/dune_beacon_crystal.png create mode 100644 network/resource-pack/central/overlay/assets/dunerealms/textures/block/dune_beacon_frame.png diff --git a/DuneChest/build.gradle.kts b/DuneChest/build.gradle.kts index 6a266522..0439bb13 100644 --- a/DuneChest/build.gradle.kts +++ b/DuneChest/build.gradle.kts @@ -1,6 +1,6 @@ plugins { java } group = "com.example" -version = "1.0.5" +version = "1.0.6" repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") diff --git a/DuneChest/src/main/java/com/example/dunechest/BeaconRules.java b/DuneChest/src/main/java/com/example/dunechest/BeaconRules.java new file mode 100644 index 00000000..093b71cf --- /dev/null +++ b/DuneChest/src/main/java/com/example/dunechest/BeaconRules.java @@ -0,0 +1,32 @@ +package com.example.dunechest; + +import java.util.List; + +/** Pure vanilla-beacon rules (no Bukkit types): effect availability per pyramid level, range and duration. */ +public final class BeaconRules { + private BeaconRules() {} + + public static final List LEVEL1 = List.of("SPEED", "HASTE"), LEVEL2 = List.of("RESISTANCE", "JUMP_BOOST"), LEVEL3 = List.of("STRENGTH"); + public static final String SECONDARY_REGEN = "REGENERATION"; + + /** Primary effects available at a pyramid level (0 = none). */ + public static List primaries(int level) { + var out = new java.util.ArrayList(); + if (level >= 1) out.addAll(LEVEL1); if (level >= 2) out.addAll(LEVEL2); if (level >= 3) out.addAll(LEVEL3); + return out; + } + /** Secondary effects: only at level 4 - Regeneration, or the chosen primary at power II (represented by the primary's own name). */ + public static List secondaries(int level, String primary) { + if (level < 4 || primary == null) return List.of(); + return List.of(SECONDARY_REGEN, primary); + } + public static boolean validChoice(int level, String primary, String secondary) { + if (primary == null || !primaries(level).contains(primary)) return false; + return secondary == null || secondaries(level, primary).contains(secondary); + } + public static int range(int level) { return level * 10 + 10; } + public static int durationTicks(int level) { return (level * 2 + 9) * 20; } + /** Amplifier of the primary effect: II when the secondary repeats it. */ + public static int primaryAmplifier(int level, String primary, String secondary) { return level >= 4 && primary != null && primary.equals(secondary) ? 1 : 0; } + public static boolean regeneration(int level, String primary, String secondary) { return level >= 4 && SECONDARY_REGEN.equals(secondary) && !SECONDARY_REGEN.equals(primary); } +} diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageData.java b/DuneChest/src/main/java/com/example/dunechest/StorageData.java index be0ed260..89ffd21f 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageData.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageData.java @@ -13,11 +13,11 @@ import org.bukkit.plugin.Plugin; /** Persistent state of the custom storage blocks on this planet: placed blocks and colour-frequency inventories. */ final class StorageData { - enum Kind { ENDER_CHEST, SPEED_HOPPER, AUTO_CRAFTER } + enum Kind { ENDER_CHEST, SPEED_HOPPER, AUTO_CRAFTER, BEACON } static final class Placed { Kind kind; int[] colors = new int[3]; UUID owner; boolean priv; int tier = 1; boolean whitelist = false; - List filter = new ArrayList<>(); ItemStack[] recipe = new ItemStack[9]; int cooldown; Location loc; + List filter = new ArrayList<>(); ItemStack[] recipe = new ItemStack[9]; int cooldown; Location loc; String primary, secondary; } /** Holder of a frequency inventory so listeners recognise it. */ @@ -56,7 +56,7 @@ final class StorageData { try { Placed p = new Placed(); p.kind = Kind.valueOf(s.getString("kind", "ENDER_CHEST")); p.colors = StorageRules.parseColors(s.getString("colors")); String o = s.getString("owner"); p.owner = o == null ? null : UUID.fromString(o); - p.priv = s.getBoolean("private"); p.tier = s.getInt("tier", 1); p.whitelist = s.getBoolean("whitelist"); + p.primary = s.getString("primary"); p.secondary = s.getString("secondary"); p.priv = s.getBoolean("private"); p.tier = s.getInt("tier", 1); p.whitelist = s.getBoolean("whitelist"); for (String m : s.getStringList("filter")) { Material mat = Material.matchMaterial(m); if (mat != null) p.filter.add(mat); } List rec = s.getList("recipe"); if (rec != null) for (int i = 0; i < 9 && i < rec.size(); i++) p.recipe[i] = rec.get(i) instanceof ItemStack st ? st : null; @@ -78,7 +78,7 @@ final class StorageData { for (var e : blocks.entrySet()) { String b = "blocks." + e.getKey().replace('.', '_'); Placed p = e.getValue(); yb.set(b + ".kind", p.kind.name()); yb.set(b + ".colors", StorageRules.colorsToString(p.colors)); yb.set(b + ".owner", p.owner == null ? null : p.owner.toString()); - yb.set(b + ".private", p.priv); yb.set(b + ".tier", p.tier); yb.set(b + ".whitelist", p.whitelist); + yb.set(b + ".primary", p.primary); yb.set(b + ".secondary", p.secondary); yb.set(b + ".private", p.priv); yb.set(b + ".tier", p.tier); yb.set(b + ".whitelist", p.whitelist); yb.set(b + ".filter", p.filter.stream().map(Enum::name).toList()); yb.set(b + ".recipe", Arrays.asList(p.recipe)); } var yi = new YamlConfiguration(); diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageItems.java b/DuneChest/src/main/java/com/example/dunechest/StorageItems.java index 25a5c854..0587a8c7 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageItems.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageItems.java @@ -12,18 +12,19 @@ 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"; - private final Plugin plugin; final NamespacedKey type, tier, colors, owner, priv, filter, whitelist; + public static final String ENDER = "ender_chest", HOPPER = "speed_hopper", CRAFTER = "auto_crafter", WRENCH = "wrench", BEACON = "dune_beacon"; + private final Plugin plugin; final NamespacedKey type, tier, colors, owner, priv, filter, whitelist, primary, secondary; StorageItems(Plugin plugin) { this.plugin = plugin; type = new NamespacedKey(plugin, "storage_type"); tier = new NamespacedKey(plugin, "storage_tier"); colors = new NamespacedKey(plugin, "storage_colors"); owner = new NamespacedKey(plugin, "storage_owner"); priv = new NamespacedKey(plugin, "storage_private"); + primary = new NamespacedKey(plugin, "beacon_primary"); secondary = new NamespacedKey(plugin, "beacon_secondary"); filter = new NamespacedKey(plugin, "storage_filter"); whitelist = new NamespacedKey(plugin, "storage_whitelist"); } public ItemStack create(String id, int tierNumber) { - Material base = switch (id) { case ENDER -> Material.ENDER_CHEST; case HOPPER -> Material.HOPPER; case WRENCH -> Material.KNOWLEDGE_BOOK; default -> Material.CRAFTING_TABLE; }; + Material base = switch (id) { case ENDER -> Material.ENDER_CHEST; case HOPPER -> Material.HOPPER; case WRENCH -> Material.KNOWLEDGE_BOOK; case BEACON -> Material.SEA_LANTERN; default -> Material.CRAFTING_TABLE; }; ItemStack item = new ItemStack(base); ItemMeta m = item.getItemMeta(); var pdc = m.getPersistentDataContainer(); pdc.set(type, PersistentDataType.STRING, id); List lore = new ArrayList<>(); @@ -34,6 +35,9 @@ public final class StorageItems { 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)); 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)); + 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.")); } } @@ -56,11 +60,14 @@ public final class StorageItems { /** Item for a picked-up placed block, carrying its settings. */ ItemStack fromPlaced(StorageData.Placed p) { - String id = switch (p.kind) { case ENDER_CHEST -> ENDER; case SPEED_HOPPER -> HOPPER; case AUTO_CRAFTER -> CRAFTER; }; + String id = switch (p.kind) { case ENDER_CHEST -> ENDER; case SPEED_HOPPER -> HOPPER; case AUTO_CRAFTER -> CRAFTER; case BEACON -> BEACON; }; ItemStack item = create(id, p.tier); ItemMeta m = item.getItemMeta(); var pdc = m.getPersistentDataContainer(); if (p.kind == StorageData.Kind.ENDER_CHEST) { pdc.set(colors, PersistentDataType.STRING, StorageRules.colorsToString(p.colors)); if (p.priv && p.owner != null) { pdc.set(priv, PersistentDataType.BYTE, (byte) 1); pdc.set(owner, PersistentDataType.STRING, p.owner.toString()); } + } else if (p.kind == StorageData.Kind.BEACON) { + if (p.primary != null) pdc.set(primary, PersistentDataType.STRING, p.primary); + if (p.secondary != null) pdc.set(secondary, PersistentDataType.STRING, p.secondary); } else if (p.kind == StorageData.Kind.SPEED_HOPPER && !p.filter.isEmpty()) { pdc.set(filter, PersistentDataType.STRING, String.join(",", p.filter.stream().map(Enum::name).toList())); pdc.set(whitelist, PersistentDataType.BYTE, (byte) (p.whitelist ? 1 : 0)); } @@ -76,6 +83,7 @@ public final class StorageItems { case HOPPER -> { p.kind = StorageData.Kind.SPEED_HOPPER; p.tier = tierOf(item); String f = pdc.get(filter, PersistentDataType.STRING); if (f != null && !f.isEmpty()) for (String s : f.split(",")) { Material m = Material.matchMaterial(s); if (m != null) p.filter.add(m); } Byte w = pdc.get(whitelist, PersistentDataType.BYTE); p.whitelist = w != null && w == 1; } + case BEACON -> { p.kind = StorageData.Kind.BEACON; p.primary = pdc.get(primary, PersistentDataType.STRING); p.secondary = pdc.get(secondary, PersistentDataType.STRING); } default -> p.kind = StorageData.Kind.AUTO_CRAFTER; } return p; @@ -87,6 +95,8 @@ public final class StorageItems { 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)); + 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); shaped("auto_crafter", crafter, new String[]{"IRI", "RTR", "IDI"}, 'I', Material.IRON_INGOT, 'R', Material.REDSTONE, 'T', Material.CRAFTING_TABLE, 'D', Material.DROPPER); } diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java index 1df7a63b..359dedf5 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java @@ -18,6 +18,8 @@ import org.bukkit.event.inventory.*; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.*; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; @@ -144,6 +146,7 @@ public final class StorageModule implements Listener, CommandExecutor { case ENDER_CHEST -> { if (!canUse(pl, p)) say(pl, "This Ender Chest is private."); else tuneMenu(pl, key); } case SPEED_HOPPER -> openFilter(pl, key, p); case AUTO_CRAFTER -> openRecipe(pl, key, p); + case BEACON -> beaconMenu(pl, key); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void interact(PlayerInteractEvent e) { @@ -172,6 +175,7 @@ public final class StorageModule implements Listener, CommandExecutor { } case SPEED_HOPPER -> { if (sneak && empty) { e.setCancelled(true); openFilter(pl, key, p); } } case AUTO_CRAFTER -> { if (sneak && !empty) return; e.setCancelled(true); openRecipe(pl, key, p); } + case BEACON -> { if (sneak && !empty) return; e.setCancelled(true); beaconMenu(pl, key); } } } private String describe(int[] c) { return DyeColor.values()[c[0]].name() + " / " + DyeColor.values()[c[1]].name() + " / " + DyeColor.values()[c[2]].name(); } @@ -356,6 +360,8 @@ public final class StorageModule implements Listener, CommandExecutor { switch (p.kind) { case SPEED_HOPPER -> { if (b.getType() != Material.HOPPER) { remove(en.getKey()); continue; } hopper(b, p); if (counter % 25 == 0) hopperDisplay(en.getKey(), b, p); } case AUTO_CRAFTER -> { if (b.getType() != Material.CRAFTING_TABLE) { remove(en.getKey()); continue; } if (counter % 10 == 0) crafter(b, p); } + case BEACON -> { if (b.getType() != Material.SEA_LANTERN) { remove(en.getKey()); continue; } + if (counter % 40 == 0) beaconPulse(b, p); if (counter % 25 == 0) beaconDisplay(en.getKey(), b); } case ENDER_CHEST -> { if (b.getType() != Material.BARREL && b.getType() != Material.ENDER_CHEST) { remove(en.getKey()); continue; } if (counter % 25 == 0) displays(en.getKey(), b, p); } } } @@ -445,6 +451,102 @@ public final class StorageModule implements Listener, CommandExecutor { dst.addItem(result); data.dirty = true; } + + // ---------- Dune Beacon: vanilla beacon rules without the beam or the sky requirement ---------- + private static final Set PAYMENT = Set.of(Material.IRON_INGOT, Material.GOLD_INGOT, Material.EMERALD, Material.DIAMOND, Material.NETHERITE_INGOT); + private static PotionEffectType effect(String name) { + return switch (name) { case "SPEED" -> PotionEffectType.SPEED; case "HASTE" -> PotionEffectType.HASTE; case "RESISTANCE" -> PotionEffectType.RESISTANCE; + case "JUMP_BOOST" -> PotionEffectType.JUMP_BOOST; case "STRENGTH" -> PotionEffectType.STRENGTH; case "REGENERATION" -> PotionEffectType.REGENERATION; default -> null; }; + } + private static String pretty(String name) { String n = name.toLowerCase(Locale.ROOT).replace('_', ' '); return Character.toUpperCase(n.charAt(0)) + n.substring(1); } + private static Material effectIcon(String name) { + return switch (name) { case "SPEED" -> Material.SUGAR; case "HASTE" -> Material.GOLDEN_PICKAXE; case "RESISTANCE" -> Material.IRON_CHESTPLATE; + case "JUMP_BOOST" -> Material.RABBIT_FOOT; case "STRENGTH" -> Material.BLAZE_POWDER; default -> Material.GOLDEN_APPLE; }; + } + /** Pyramid level 0-4 from the layers of beacon base blocks below, exactly like vanilla. */ + private int beaconLevel(Block b) { + int level = 0; + for (int layer = 1; layer <= 4; layer++) { + int y = b.getY() - layer; if (y < b.getWorld().getMinHeight()) break; + boolean full = true; + for (int x = -layer; x <= layer && full; x++) for (int z = -layer; z <= layer; z++) + if (!b.getWorld().isChunkLoaded((b.getX() + x) >> 4, (b.getZ() + z) >> 4) + || !Tag.BEACON_BASE_BLOCKS.isTagged(b.getWorld().getBlockAt(b.getX() + x, y, b.getZ() + z).getType())) { full = false; break; } + if (!full) break; level = layer; + } + return level; + } + private void beaconPulse(Block b, StorageData.Placed p) { + if (p.primary == null) return; + int level = beaconLevel(b); if (!BeaconRules.validChoice(level, p.primary, p.secondary)) return; + int range = BeaconRules.range(level), dur = BeaconRules.durationTicks(level); + var primary = effect(p.primary); if (primary == null) return; + int amp = BeaconRules.primaryAmplifier(level, p.primary, p.secondary); boolean regen = BeaconRules.regeneration(level, p.primary, p.secondary); + double cx = b.getX() + 0.5, cz = b.getZ() + 0.5; + for (Player pl : b.getWorld().getPlayers()) { + Location l = pl.getLocation(); if (Math.abs(l.getX() - cx) > range + 0.5 || Math.abs(l.getZ() - cz) > range + 0.5) continue; + pl.addPotionEffect(new PotionEffect(primary, dur, amp, true, true, true)); + if (regen) pl.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, dur, 0, true, true, true)); + } + } + private void beaconDisplay(String key, Block b) { + String sig = "beacon"; var ids = displays.get(key); + if (sig.equals(signatures.get(key)) && ids != null && ids.stream().allMatch(id -> { Entity en = Bukkit.getEntity(id); return en != null && en.isValid(); })) return; + if (ids != null) ids.forEach(this::kill); + var body = b.getWorld().spawn(b.getLocation().add(0.5, 0.5, 0.5), ItemDisplay.class, id -> { + id.setItemStack(items.create(StorageItems.BEACON, 1)); id.setPersistent(false); id.setBrightness(new Display.Brightness(15, 15)); id.setItemDisplayTransform(ItemDisplay.ItemDisplayTransform.NONE); + id.setTransformation(new Transformation(new Vector3f(), new AxisAngle4f(), new Vector3f(1.002f, 1.002f, 1.002f), new AxisAngle4f())); + }); + displays.put(key, new ArrayList<>(List.of(body.getUniqueId()))); signatures.put(key, sig); + } + private String payText() { return "Costs 1 iron ingot, gold ingot, emerald, diamond or netherite ingot"; } + + private void beaconMenu(Player pl, String key) { + var p = data.blocks.get(key); if (p == null || p.kind != StorageData.Kind.BEACON) return; + Block b = locate(key, p).getBlock(); int level = beaconLevel(b); + Inventory model = Bukkit.createInventory(null, 27); Map 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)); + 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, choice, level); else beaconConfirm(pl, key, choice, null); }); + } + com.example.dunegui.NativeMenus.inventory(plugin, pl, "Dune Beacon", model, actions); + } + private void beaconSecondary(Player pl, String key, String primary, int level) { + Inventory model = Bukkit.createInventory(null, 27); Map actions = new HashMap<>(); + model.setItem(4, legacyIcon(effectIcon(primary), pretty(primary), "Pick the secondary effect", payText())); + int slot = 10; + for (String sec : BeaconRules.secondaries(level, primary)) { final String choice = sec; int sl = slot++; + model.setItem(sl, legacyIcon(effectIcon(sec), sec.equals(primary) ? pretty(primary) + " II" : pretty(sec), "Click to set")); + actions.put(sl, () -> beaconConfirm(pl, key, primary, choice)); } + model.setItem(slot, legacyIcon(Material.BARRIER, "No secondary", "Primary only")); + actions.put(slot, () -> beaconConfirm(pl, key, primary, null)); + com.example.dunegui.NativeMenus.inventory(plugin, pl, "Dune Beacon", model, actions); + } + private void beaconConfirm(Player pl, String key, String primary, String secondary) { + var p = data.blocks.get(key); if (p == null || p.kind != StorageData.Kind.BEACON) return; + int level = beaconLevel(locate(key, p).getBlock()); + if (!BeaconRules.validChoice(level, primary, secondary)) { say(pl, "That effect is not available at this beacon's level."); return; } + if (pl.getGameMode() != GameMode.CREATIVE) { + Inventory inventory = pl.getInventory(); + ItemStack[] slots = inventory.getStorageContents(); + int paymentSlot = 0; + while (paymentSlot < slots.length) { + ItemStack item = slots[paymentSlot]; + if (item != null && PAYMENT.contains(item.getType()) && !item.hasItemMeta()) break; + paymentSlot++; + } + if (paymentSlot == slots.length) { say(pl, payText() + "."); return; } + ItemStack payment = slots[paymentSlot]; + 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))) + "."); + beaconPulse(locate(key, p).getBlock(), p); + } + // ---------- display entities (pads on top, most common item on the front) ---------- /** Custom-model overlay (scaled 1.01) over the vanilla hopper so Speed Hoppers look distinct; spout follows the hopper's facing. */ private void hopperDisplay(String key, Block b, StorageData.Placed p) { @@ -518,10 +620,10 @@ public final class StorageModule implements Listener, CommandExecutor { @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 (a.length < 2 || !a[0].equalsIgnoreCase("give")) { s.sendMessage("/dunechest give [amount]"); return true; } + if (a.length < 2 || !a[0].equalsIgnoreCase("give")) { s.sendMessage("/dunechest give [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); - case "hopper2" -> items.create(StorageItems.HOPPER, 2); case "hopper3" -> items.create(StorageItems.HOPPER, 3); case "crafter" -> items.create(StorageItems.CRAFTER, 1); case "wrench" -> items.create(StorageItems.WRENCH, 1); default -> null; }; + case "hopper2" -> items.create(StorageItems.HOPPER, 2); case "hopper3" -> items.create(StorageItems.HOPPER, 3); case "crafter" -> items.create(StorageItems.CRAFTER, 1); case "wrench" -> items.create(StorageItems.WRENCH, 1); case "beacon" -> items.create(StorageItems.BEACON, 1); default -> null; }; if (item == null) { s.sendMessage("Unknown item."); return true; } int n = 1; try { if (a.length > 3) n = Math.max(1, Math.min(64, Integer.parseInt(a[3]))); } catch (NumberFormatException ignored) { } item.setAmount(n); t.getInventory().addItem(item).values().forEach(r -> t.getWorld().dropItemNaturally(t.getLocation(), r)); s.sendMessage("Gave " + n + " " + a[2] + " to " + t.getName()); return true; diff --git a/DuneChest/src/main/resources/plugin.yml b/DuneChest/src/main/resources/plugin.yml index 888eb9fe..5a1b6687 100644 --- a/DuneChest/src/main/resources/plugin.yml +++ b/DuneChest/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: DuneChest -version: 1.0.5 +version: 1.0.6 main: com.example.dunechest.DuneChest api-version: '1.21.8' softdepend: [floodgate, DuneMenus, DuneEss] @@ -8,4 +8,4 @@ description: DuneChest - colour-linked Ender Chests, Speed Hoppers and Auto Craf commands: dunechest: description: DuneChest storage panel and admin give - usage: /dunechest panel | /dunechest give [amount] + usage: /dunechest panel | /dunechest give [amount] diff --git a/DuneChest/src/test/java/com/example/dunechest/BeaconRulesTest.java b/DuneChest/src/test/java/com/example/dunechest/BeaconRulesTest.java new file mode 100644 index 00000000..20b8d641 --- /dev/null +++ b/DuneChest/src/test/java/com/example/dunechest/BeaconRulesTest.java @@ -0,0 +1,30 @@ +package com.example.dunechest; + +import static org.junit.jupiter.api.Assertions.*; +import java.util.List; +import org.junit.jupiter.api.Test; + +class BeaconRulesTest { + @Test void primariesGrowWithLevel() { + assertEquals(List.of(), BeaconRules.primaries(0)); + assertEquals(List.of("SPEED", "HASTE"), BeaconRules.primaries(1)); + assertEquals(4, BeaconRules.primaries(2).size()); + assertEquals(5, BeaconRules.primaries(3).size()); + assertEquals(5, BeaconRules.primaries(4).size()); + } + @Test void secondaryOnlyAtLevelFour() { + assertTrue(BeaconRules.secondaries(3, "SPEED").isEmpty()); + assertEquals(List.of("REGENERATION", "SPEED"), BeaconRules.secondaries(4, "SPEED")); + assertTrue(BeaconRules.validChoice(4, "SPEED", "REGENERATION")); + assertFalse(BeaconRules.validChoice(3, "SPEED", "REGENERATION")); + assertFalse(BeaconRules.validChoice(1, "STRENGTH", null)); + assertTrue(BeaconRules.validChoice(1, "HASTE", null)); + } + @Test void rangeDurationAndAmplifier() { + assertEquals(20, BeaconRules.range(1)); assertEquals(50, BeaconRules.range(4)); + assertEquals(11 * 20, BeaconRules.durationTicks(1)); assertEquals(17 * 20, BeaconRules.durationTicks(4)); + assertEquals(1, BeaconRules.primaryAmplifier(4, "SPEED", "SPEED")); assertEquals(0, BeaconRules.primaryAmplifier(4, "SPEED", "REGENERATION")); + assertEquals(0, BeaconRules.primaryAmplifier(3, "SPEED", "SPEED")); + assertTrue(BeaconRules.regeneration(4, "SPEED", "REGENERATION")); assertFalse(BeaconRules.regeneration(4, "SPEED", "SPEED")); + } +} diff --git a/DuneChest/tools/dunechest_art.py b/DuneChest/tools/dunechest_art.py index 896055e2..a25b242b 100644 --- a/DuneChest/tools/dunechest_art.py +++ b/DuneChest/tools/dunechest_art.py @@ -73,3 +73,27 @@ save("textures/item/wrench.png", im) w("models/item/wrench.json", {"parent": "minecraft:item/handheld", "textures": {"layer0": "dunerealms:item/wrench"}}) w("items/wrench.json", {"model": {"type": "minecraft:model", "model": "dunerealms:item/wrench"}}) print("wrote DuneChest art to", root) + +# ---- Dune Beacon: opaque frame-and-crystal cube drawn over a sea lantern (no beam; the base block supplies the light) ---- +FR = [(20, 16, 32), (26, 20, 42), (14, 11, 26), (32, 24, 52)] +fr = Image.new("RGBA", (S, S)); fp = fr.load() +for y in range(S): + for x in range(S): fp[x, y] = rng.choice(FR) + (255,) +fd = ImageDraw.Draw(fr); fd.rectangle([0, 0, S - 1, S - 1], outline=(8, 6, 16, 255)); fd.rectangle([2, 2, S - 3, S - 3], outline=(60, 44, 100, 255)) +save("textures/block/dune_beacon_frame.png", fr) +cr = Image.new("RGBA", (S, S)); cp = cr.load() +for y in range(S): + for x in range(S): + t = y / (S - 1); cp[x, y] = (int(40 + 40 * (1 - t)), int(170 + 50 * (1 - t)), int(190 + 50 * (1 - t)), 255) +cd = ImageDraw.Draw(cr); cd.rectangle([0, 0, S - 1, S - 1], outline=(20, 110, 130, 255)); cd.rectangle([1, 1, S - 2, S - 2], outline=(150, 235, 245, 255)) +cx = cy = S // 2 # nether-star style sparkle +for r in range(1, 9): cd.point((cx - r, cy), fill=(235, 255, 255, 255)); cd.point((cx + r, cy), fill=(235, 255, 255, 255)); cd.point((cx, cy - r), fill=(235, 255, 255, 255)); cd.point((cx, cy + r), fill=(235, 255, 255, 255)) +cd.rectangle([cx - 2, cy - 2, cx + 2, cy + 2], fill=(255, 255, 255, 255)) +save("textures/block/dune_beacon_crystal.png", cr) +allf = lambda t: {k: {"texture": "#" + t} for k in ("down", "up", "north", "south", "west", "east")} +w("models/block/dune_beacon.json", {"parent": "minecraft:block/block", + "textures": {"particle": "dunerealms:block/dune_beacon_frame", "frame": "dunerealms:block/dune_beacon_frame", "crystal": "dunerealms:block/dune_beacon_crystal"}, + "elements": [{"from": [0, 0, 0], "to": [16, 3, 16], "faces": allf("frame")}, {"from": [0, 13, 0], "to": [16, 16, 16], "faces": allf("frame")}, + {"from": [1, 3, 1], "to": [15, 13, 15], "faces": allf("crystal")}]}) +w("models/item/dune_beacon.json", {"parent": "dunerealms:block/dune_beacon"}) +w("items/dune_beacon.json", {"model": {"type": "minecraft:model", "model": "dunerealms:item/dune_beacon"}}) diff --git a/DuneMenus/build.gradle.kts b/DuneMenus/build.gradle.kts index 19c3f44d..518b52d8 100644 --- a/DuneMenus/build.gradle.kts +++ b/DuneMenus/build.gradle.kts @@ -62,6 +62,8 @@ tasks.processResources { exclude("assets/dunerealms/items/$item.json", "assets/dunerealms/models/item/$item.json", "assets/dunerealms/textures/item/$item.png") } + exclude("assets/dunerealms/items/dune_beacon.json", "assets/dunerealms/models/item/dune_beacon.json", + "assets/dunerealms/models/block/dune_beacon.json", "assets/dunerealms/textures/block/dune_beacon_*.png") exclude("assets/dunerealms/items/ender_chest.json", "assets/dunerealms/models/item/ender_chest.json", "assets/dunerealms/models/block/ender_chest.json", "assets/dunerealms/models/block/ender_chest_barrel_display.json", "assets/dunerealms/items/ender_chest_barrel_display.json", "assets/dunerealms/textures/block/ender_chest_*.png") diff --git a/network/resource-pack/central/overlay/assets/dunerealms/items/dune_beacon.json b/network/resource-pack/central/overlay/assets/dunerealms/items/dune_beacon.json new file mode 100644 index 00000000..9e46b915 --- /dev/null +++ b/network/resource-pack/central/overlay/assets/dunerealms/items/dune_beacon.json @@ -0,0 +1 @@ +{"model":{"type":"minecraft:model","model":"dunerealms:item/dune_beacon"}} \ No newline at end of file diff --git a/network/resource-pack/central/overlay/assets/dunerealms/models/block/dune_beacon.json b/network/resource-pack/central/overlay/assets/dunerealms/models/block/dune_beacon.json new file mode 100644 index 00000000..59b28d38 --- /dev/null +++ b/network/resource-pack/central/overlay/assets/dunerealms/models/block/dune_beacon.json @@ -0,0 +1 @@ +{"parent":"minecraft:block/block","textures":{"particle":"dunerealms:block/dune_beacon_frame","frame":"dunerealms:block/dune_beacon_frame","crystal":"dunerealms:block/dune_beacon_crystal"},"elements":[{"from":[0,0,0],"to":[16,3,16],"faces":{"down":{"texture":"#frame"},"up":{"texture":"#frame"},"north":{"texture":"#frame"},"south":{"texture":"#frame"},"west":{"texture":"#frame"},"east":{"texture":"#frame"}}},{"from":[0,13,0],"to":[16,16,16],"faces":{"down":{"texture":"#frame"},"up":{"texture":"#frame"},"north":{"texture":"#frame"},"south":{"texture":"#frame"},"west":{"texture":"#frame"},"east":{"texture":"#frame"}}},{"from":[1,3,1],"to":[15,13,15],"faces":{"down":{"texture":"#crystal"},"up":{"texture":"#crystal"},"north":{"texture":"#crystal"},"south":{"texture":"#crystal"},"west":{"texture":"#crystal"},"east":{"texture":"#crystal"}}}]} \ No newline at end of file diff --git a/network/resource-pack/central/overlay/assets/dunerealms/models/item/dune_beacon.json b/network/resource-pack/central/overlay/assets/dunerealms/models/item/dune_beacon.json new file mode 100644 index 00000000..d85a43e6 --- /dev/null +++ b/network/resource-pack/central/overlay/assets/dunerealms/models/item/dune_beacon.json @@ -0,0 +1 @@ +{"parent":"dunerealms:block/dune_beacon"} \ No newline at end of file diff --git a/network/resource-pack/central/overlay/assets/dunerealms/textures/block/dune_beacon_crystal.png b/network/resource-pack/central/overlay/assets/dunerealms/textures/block/dune_beacon_crystal.png new file mode 100644 index 0000000000000000000000000000000000000000..328f3f328b6113a68b1f536d1434c94fe1eaf25d GIT binary patch literal 332 zcmV-S0ki&zP)PwTQkE&^alJrBBL`W3}{G%WdQlfY8ga9SkkP^LQmxPC` z)Zi)kfQ1T}ZFlSz$)zb(q5z(i$tX<;Rz@3aHHr4sdK(R_Y6A{m$7u$^5b!^E6|3f> z_SzWYxYXhUWTydafSekYU=-j27W*!NrM5WfG5A2) e8!!%Z_Z$EuVd4J&;`<)}00004z^5QWb{5wfsB7!|>&N|iEo>iq1~sZ*v1sf=(Tgo%Y>BtycRop1E^;t&@B512do z_I768%zHa`Hk&Sf4KHXD`M#JhhQsktVN737405l9uCwR8Ub-m1UU?V7;$Z*htop;TKGp=s0{D&Oj#5YE)8w4kJC zu*6vts7>Zw8D$ZGQ$`zvBP~w)>Av6=jf|3oUQ#PckoQ{a&uMn|86|LN;-$%m!^Y`o z#_a52*4|}fGOlX|Km+UQdQ%8^cMAdFk_k?P#REmGv^EfNAxnA|l1WRh^iT!BW}p#4 zB+oIND;RIqpws=SVX1R8at2RH9Buv=J-~*_f{dcGllRmdizZW+l2*xcN_V`Uq6W2{ z|Dfx8cQkZ8aP`6>xa@v{!(8jbK?Xwqa7JJV(H|^u8p;V-;Q+_5MH?yb$~e(*?sG3B zOPCVfjs-zGb!v7!*@n$pLl*3LDmp!*#!2ILe^SjlS<`Wo>wQC@8q7M`sTcB_kOq`G zT9fZ+1(~^oM}JYWhfS{o=_>+oiIvgmW5+coq!yt2$wt(IG%NT-UL& zbl$C^)z(B@blZ%OcvZnrkR9|!g}t!FLBCQLPpsF0SxG2 zh89tZYNTXLY?7y(j6mAK)Tr#}xxz+2WWe27z$q9T=FkyZVA*=~Y~K*?C-kJ4xG~`AF>=hmO|9g@ZIX8_vAnAe|(}<0AFuDb)Q{~ w*&yV