Integrate the beamless Dune Beacon #39
16 changed files with 273 additions and 18 deletions
|
|
@ -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/")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.example.dunechest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/** Pure vanilla-beacon rules (no Bukkit types): effect availability per pyramid level, range and duration. */
|
||||
public final class BeaconRules {
|
||||
private static final Set<String> COMMODITY_METADATA = Set.of(
|
||||
"dunerealms:quality", "dunerealms:equipment_mark", "dunerealms:item_class",
|
||||
"dunerealms:metadata_policy", "dunerealms:metadata_lore_header", "dunerealms:origin_world");
|
||||
|
||||
static boolean ordinaryPaymentMetadata(Set<String> keys) {
|
||||
return COMMODITY_METADATA.containsAll(keys);
|
||||
}
|
||||
|
||||
private BeaconRules() {}
|
||||
|
||||
public static final List<String> 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<String> primaries(int level) {
|
||||
var out = new java.util.ArrayList<String>();
|
||||
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<String> 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); }
|
||||
}
|
||||
|
|
@ -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<Material> filter = new ArrayList<>(); ItemStack[] recipe = new ItemStack[9]; int cooldown; Location loc;
|
||||
List<Material> 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();
|
||||
|
|
|
|||
|
|
@ -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<Component> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ 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;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.joml.AxisAngle4f;
|
||||
import org.joml.Vector3f;
|
||||
|
|
@ -144,6 +147,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 +176,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 +361,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); }
|
||||
}
|
||||
}
|
||||
|
|
@ -379,14 +386,17 @@ public final class StorageModule implements Listener, CommandExecutor {
|
|||
Block above = b.getRelative(BlockFace.UP); Inventory source = containerAt(above);
|
||||
Predicate<ItemStack> ok = s -> StorageRules.accepts(p.whitelist, p.filter, s.getType());
|
||||
if (source != null && StorageRules.transferable(source.getType().name())) { if (move(source, own, tier.amount, ok, true, true) > 0) moved = true; }
|
||||
else if (source == null && !above.getType().isSolid()) { if (suck(above, own, tier.amount, ok) > 0) moved = true; }
|
||||
else if (source == null && suck(b, own, tier.amount, ok) > 0) moved = true;
|
||||
if (moved && (data.at(out) != null || data.at(above) != null)) data.dirty = true;
|
||||
p.cooldown = tier.interval;
|
||||
}
|
||||
|
||||
private int suck(Block above, Inventory own, int max, Predicate<ItemStack> ok) {
|
||||
/** The vanilla pickup area covers the hopper bowl and the block above. */
|
||||
private int suck(Block hopper, Inventory own, int max, Predicate<ItemStack> ok) {
|
||||
int moved = 0;
|
||||
for (Entity en : above.getWorld().getNearbyEntities(above.getBoundingBox(), x -> x instanceof Item)) {
|
||||
BoundingBox area = new BoundingBox(hopper.getX(), hopper.getY() + 11.0 / 16, hopper.getZ(),
|
||||
hopper.getX() + 1, hopper.getY() + 2, hopper.getZ() + 1);
|
||||
for (Entity en : hopper.getWorld().getNearbyEntities(area, entity -> entity instanceof Item item && item.isValid())) {
|
||||
Item item = (Item) en; ItemStack s = item.getItemStack(); if (!ok.test(s)) continue;
|
||||
int take = Math.min(max - moved, s.getAmount()); ItemStack part = s.clone(); part.setAmount(take);
|
||||
var left = own.addItem(part); int done = take - (left.isEmpty() ? 0 : left.values().iterator().next().getAmount());
|
||||
|
|
@ -445,6 +455,129 @@ 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<Material> 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);
|
||||
BoundingBox area = new BoundingBox(b.getX() - range, b.getY() - range, b.getZ() - range,
|
||||
b.getX() + 1 + range, b.getY() + 1 + range + b.getWorld().getMaxHeight() - b.getWorld().getMinHeight(),
|
||||
b.getZ() + 1 + range);
|
||||
for (Player pl : b.getWorld().getPlayers()) {
|
||||
if (pl.getGameMode() == GameMode.SPECTATOR || !area.overlaps(pl.getBoundingBox())) 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 = currentBeacon(pl, key, p);
|
||||
if (b == null) return;
|
||||
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));
|
||||
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);
|
||||
}
|
||||
private void beaconSecondary(Player pl, String key, StorageData.Placed expected, String primary) {
|
||||
Block block = currentBeacon(pl, key, expected);
|
||||
if (block == null) return;
|
||||
int level = beaconLevel(block);
|
||||
if (level < 4) { beaconMenu(pl, key); return; }
|
||||
Inventory model = Bukkit.createInventory(null, 27); Map<Integer, Runnable> 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, 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);
|
||||
}
|
||||
private static boolean beaconPayment(ItemStack item) {
|
||||
if (item == null || item.isEmpty() || !PAYMENT.contains(item.getType())) return false;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
return !meta.hasDisplayName() && !meta.hasItemName() && !meta.hasItemModel()
|
||||
&& !meta.hasCustomModelData() && !meta.hasEnchants()
|
||||
&& BeaconRules.ordinaryPaymentMetadata(meta.getPersistentDataContainer().getKeys().stream()
|
||||
.map(NamespacedKey::toString).collect(java.util.stream.Collectors.toSet()));
|
||||
}
|
||||
|
||||
private Block currentBeacon(Player player, String key, StorageData.Placed expected) {
|
||||
if (data.blocks.get(key) != expected) return null;
|
||||
Location at = locate(key, expected);
|
||||
if (at == null || !at.getWorld().equals(player.getWorld()) || player.getLocation().distanceSquared(at) > 64
|
||||
|| !at.getWorld().isChunkLoaded(at.getBlockX() >> 4, at.getBlockZ() >> 4)) return null;
|
||||
Block block = at.getBlock();
|
||||
return block.getType() == Material.SEA_LANTERN ? block : null;
|
||||
}
|
||||
|
||||
private void beaconConfirm(Player pl, String key, StorageData.Placed p, String primary, String secondary) {
|
||||
Block block = currentBeacon(pl, key, p);
|
||||
if (block == null) { say(pl, "This beacon is no longer in reach."); return; }
|
||||
int level = beaconLevel(block);
|
||||
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 (beaconPayment(item)) 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(block, 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 +651,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 <player> <ender|hopper1|hopper2|hopper3|crafter|wrench> [amount]"); 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);
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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 <player> <ender|hopper1|hopper2|hopper3|crafter|wrench> [amount]
|
||||
usage: /dunechest panel | /dunechest give <player> <ender|hopper1|hopper2|hopper3|crafter|wrench|beacon> [amount]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package com.example.dunechest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BeaconRulesTest {
|
||||
@Test void acceptsOrdinaryJarvisMetadataAndRejectsCustomIdentities() {
|
||||
assertTrue(BeaconRules.ordinaryPaymentMetadata(Set.of()));
|
||||
assertTrue(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:quality",
|
||||
"dunerealms:equipment_mark", "dunerealms:item_class", "dunerealms:metadata_policy",
|
||||
"dunerealms:metadata_lore_header", "dunerealms:origin_world")));
|
||||
assertFalse(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:quality", "executableitems:ei-id")));
|
||||
assertFalse(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:item")));
|
||||
}
|
||||
|
||||
@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"));
|
||||
}
|
||||
}
|
||||
|
|
@ -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"}})
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
{"model":{"type":"minecraft:model","model":"dunerealms:item/dune_beacon"}}
|
||||
|
|
@ -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"}}}]}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"parent":"dunerealms:block/dune_beacon"}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 332 B |
Binary file not shown.
|
After Width: | Height: | Size: 1 KiB |
|
|
@ -277,7 +277,7 @@ def plan(artifacts, inventory, expected_source):
|
|||
installed=existing_paths.get('dunechest')
|
||||
approved_dunechest = {
|
||||
chosen[0]['sha256'],
|
||||
'bd80ff028e58b24e4ee023827d9fa6dca3ae857dc867a27caca5ef399544ec85',
|
||||
'0c56c56e03310572e0fc1f603d4fd23230456c64ab9d2892f3a0849fb349a1ae',
|
||||
}
|
||||
if installed is not None and digest(installed) not in approved_dunechest:
|
||||
raise ValueError('Existing DuneChest differs from the approved release or predecessor')
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ import sys
|
|||
from plugin_resource_pack import read_zip
|
||||
|
||||
PACK_BASELINE_SHA256 = '446c0b60fa6e6752ff5260bb22c9a76280b7b10ffa03c3cca4b08f4d9320105b'
|
||||
MODELS = ['ender_chest', *(f'speed_hopper_{tier}{facing}' for tier in range(1,4) for facing in ('','_side'))]
|
||||
MODELS = ['ender_chest', 'dune_beacon', *(f'speed_hopper_{tier}{facing}' for tier in range(1,4) for facing in ('','_side'))]
|
||||
ASSETS = {
|
||||
'assets/dunerealms/textures/block/dune_beacon_frame.png',
|
||||
'assets/dunerealms/textures/block/dune_beacon_crystal.png',
|
||||
'assets/dunerealms/items/ender_chest_barrel_display.json',
|
||||
'assets/dunerealms/models/block/ender_chest_barrel_display.json',
|
||||
*(f'assets/dunerealms/{category}/{model}.json' for category in ('items','models/item','models/block') for model in MODELS),
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff