From 1bdb52f34ce3b7dfcb96ad3eaf57a0b0ca78137e Mon Sep 17 00:00:00 2001 From: youpaishidifu <1@ypshidifu.cn> Date: Sun, 1 Nov 2026 11:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC65=E6=89=B9=E4=BF=AE=E5=A4=8D7?= =?UTF-8?q?=EF=BC=9A=E8=BF=9E=E9=94=81=E9=87=87=E9=9B=86=E6=A0=91=E6=9C=A8?= =?UTF-8?q?=E5=9E=82=E7=9B=B4=E4=BC=98=E5=85=88=20+=20=E7=9F=BF=E7=89=A9?= =?UTF-8?q?=E6=8E=89=E8=90=BD=E7=9F=BF=E7=9F=B3=E7=89=A9=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 树木采集策略改为垂直优先: - 先向上扫描整棵树干(同XZ坐标,直到方块类型变化) - 再从每个树干位置水平9×9辐射 - 解决之前水平9×9误采旁边树木的问题 2. 矿物掉落物映射(getDropMaterial): - 之前直接掉落原矿方块(如COPPER_ORE) - 现在映射到矿石物品(如COPPER_RAW_ORE) - 支持普通矿石和深板岩矿石 - 用字符串查找避免Paper 26.x enum缺失问题 --- src/main/java/Sdf1_login/Main.java | 82 +++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/src/main/java/Sdf1_login/Main.java b/src/main/java/Sdf1_login/Main.java index 903ecc2..d790c07 100644 --- a/src/main/java/Sdf1_login/Main.java +++ b/src/main/java/Sdf1_login/Main.java @@ -4039,7 +4039,7 @@ public class Main extends JavaPlugin if (isOre && !isPickaxe) return; if (isLog && !isAxe) return; - // 连锁采集:以被破坏方块为中心,9×9范围(前后各4格) + // 连锁采集:树木优先垂直,矿物水平辐射 org.bukkit.Location center = centerBlock.getLocation(); int range = 4; // 9×9 = 中心±4 @@ -4049,17 +4049,42 @@ public class Main extends JavaPlugin int cy = center.getBlockY(); int cz = center.getBlockZ(); - for (int x = -range; x <= range; x++) { - for (int z = -range; z <= range; z++) { - // 跳过中心方块(已由原版逻辑处理) - if (x == 0 && z == 0) continue; - - org.bukkit.block.Block block = - world.getBlockAt(cx + x, cy, cz + z); - - // 只采集同一层、同类型、固体方块 + if (isLog) { + // 树木:先垂直扫描树干,再从树顶水平辐射 + // 1. 向上找同类型树干,直到找不到 + List trunkBlocks = new ArrayList<>(); + for (int y = cy; y <= 255; y++) { + org.bukkit.block.Block block = world.getBlockAt(cx, y, cz); if (block.getType() == targetType && block.getType().isSolid()) { - sameTypeBlocks.add(block); + trunkBlocks.add(block); + } else { + break; // 树干结束 + } + } + // 2. 从每个树干位置水平 9×9 辐射 + for (org.bukkit.block.Block trunk : trunkBlocks) { + int tx = trunk.getX(); + int ty = trunk.getY(); + int tz = trunk.getZ(); + for (int x = -range; x <= range; x++) { + for (int z = -range; z <= range; z++) { + if (x == 0 && z == 0) continue; // 跳过树干本身(已收集) + org.bukkit.block.Block block = world.getBlockAt(tx + x, ty, tz + z); + if (block.getType() == targetType && block.getType().isSolid()) { + sameTypeBlocks.add(block); + } + } + } + } + } else { + // 矿物:直接水平 9×9 辐射 + for (int x = -range; x <= range; x++) { + for (int z = -range; z <= range; z++) { + if (x == 0 && z == 0) continue; // 跳过中心方块 + org.bukkit.block.Block block = world.getBlockAt(cx + x, cy, cz + z); + if (block.getType() == targetType && block.getType().isSolid()) { + sameTypeBlocks.add(block); + } } } } @@ -4073,10 +4098,11 @@ public class Main extends JavaPlugin // 二次检查:方块仍然存在且类型未变 if (block.getType() != targetType) continue; - // 生成掉落物 + // 生成掉落物(矿物掉落对应矿石物品,树木掉落原木) + Material dropType = getDropMaterial(targetType, isOre); org.bukkit.Location dropLoc = block.getLocation().add(0.5, 0.5, 0.5); org.bukkit.entity.Item item = (org.bukkit.entity.Item) - block.getWorld().dropItemNaturally(dropLoc, new org.bukkit.inventory.ItemStack(targetType)); + block.getWorld().dropItemNaturally(dropLoc, new org.bukkit.inventory.ItemStack(dropType)); item.setPickupDelay(0); // 设置方块为空气 @@ -4091,6 +4117,36 @@ public class Main extends JavaPlugin }, 1L); } + /** 获取方块的掉落物类型(矿物掉落矿石物品,原木掉落原木) */ + private Material getDropMaterial(Material blockType, boolean isOre) { + if (isOre) { + // 矿物→矿石物品映射(用字符串查找,避免Paper 26.x enum缺失) + String name = blockType.name(); + if (name.endsWith("_RAW_ORE")) return blockType; // 已经是矿石物品 + // 深板岩矿石先去掉 DEEPSLATE_ 前缀匹配 + String stripped = name.startsWith("DEEPSLATE_") ? name.substring(10) : name; + // 映射到矿石物品名 + String dropName = null; + if (stripped.equals("COPPER_ORE")) dropName = "COPPER_RAW_ORE"; + else if (stripped.equals("IRON_ORE")) dropName = "IRON_RAW_ORE"; + else if (stripped.equals("GOLD_ORE")) dropName = "GOLD_RAW_ORE"; + else if (stripped.equals("DIAMOND_ORE")) dropName = "DIAMOND"; + else if (stripped.equals("COAL_ORE")) dropName = "COAL"; + else if (stripped.equals("EMERALD_ORE")) dropName = "EMERALD"; + else if (stripped.equals("LAPIS_LAZULI_ORE")) dropName = "LAPIS_LAZULI"; + else if (stripped.equals("LAPIS_ORE")) dropName = "LAPIS_LAZULI"; + else if (stripped.equals("NETHER_QUARTZ_ORE")) dropName = "QUARTZ"; + else if (stripped.equals("ANCIENT_DEBRIS")) dropName = "ANCIENT_DEBRIS"; + if (dropName != null) { + Material m = Material.getMaterial(dropName); + if (m != null) return m; + } + return blockType; // 找不到就返回原方块 + } else { + return blockType; // 树木直接返回原木 + } + } + /** 检查是否为矿物方块 */ private boolean isOreBlock(org.bukkit.Material type) { String name = type.name();