Fix hopper pickup area and guard beacon callbacks
All checks were successful
Planet DuneChest Build / dunechest (push) Successful in 52s
DuneRealms Plugin CI / plugins (push) Successful in 2m24s

This commit is contained in:
unimatrixgit 2026-11-30 19:35:16 +01:00
commit 7d53eaf8f5

View file

@ -386,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());
@ -506,26 +509,32 @@ public final class StorageModule implements Listener, CommandExecutor {
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);
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, choice, level); else beaconConfirm(pl, key, choice, null); });
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, String primary, int level) {
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, primary, choice)); }
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, primary, null));
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) {
@ -537,9 +546,19 @@ public final class StorageModule implements Listener, CommandExecutor {
.map(NamespacedKey::toString).collect(java.util.stream.Collectors.toSet()));
}
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());
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();
@ -556,7 +575,7 @@ public final class StorageModule implements Listener, CommandExecutor {
}
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);
beaconPulse(block, p);
}
// ---------- display entities (pads on top, most common item on the front) ----------