Minecraft1.12.2坠落配方思路 2025-03-23 17 笔记  为了给HDS实现此需求我直接在HDSU上直接动土,发现在Forge的`EntityFallingBlock`中有一个`onGround`,第一次 我就在`WorldTick`中直接使用它进行判断方块是否落到了地面上,但很快啊,我就知道了在Forge中的`EntityFallingBlock`的`onGround`并不能正常生效,就算落地了它也会直接`false`。:sweat_smile: 好了,下面直接给出解决办法吧。:innocent: 思路是这样的,在`EntityJoinWorldEvent`判断`Entity`是否为`EntityFallingBlock`,如果是且还是我想要的那种方块则记录下来。 记录之后在`WorldTick`中对其进行迭代获取`EntityFallingBlock`的`isDead`状态。返回`true`之后从`EntityFallingBlock`直接拿`BlockPos`,接下来就编写沙子消失生成物品的逻辑就好。 代码如下[→Commit见此←](https://github.com/ProjectHDS/HerodotusUtils/commit/45786988107b23869b2f1c1f6536768034cfc67f) ```csharp private static final List TRACKED_BLOCKS = new ArrayList<>(); @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if (event.getEntity() instanceof EntityFallingBlock) { EntityFallingBlock fallingBlock = (EntityFallingBlock) event.getEntity(); if (fallingBlock.getBlock().getBlock() == Blocks.SAND || fallingBlock.getBlock().getBlock() == Blocks.GRAVEL) { TRACKED_BLOCKS.add(fallingBlock); } } } @SubscribeEvent public static void onWorldTick(TickEvent.WorldTickEvent event) { World world = event.world; if (event.phase == TickEvent.Phase.END && world instanceof WorldServer) { Iterator iterator = TRACKED_BLOCKS.iterator(); while (iterator.hasNext()) { EntityFallingBlock block = iterator.next(); if (block.isDead) { BlockPos pos = new BlockPos(block.posX, block.posY, block.posZ); if (event.world.getBlockState(pos) == block.getBlock()) { AxisAlignedBB area = new AxisAlignedBB(pos).grow(0); world.getEntitiesWithinAABB(EntityItem.class, area).forEach(item -> { if (item.getItem().getItem() == Items.COAL) { EntityItem diamond = new EntityItem(world, item.posX, item.posY, item.posZ, new ItemStack(Items.DIAMOND, item.getItem().getCount())); world.spawnEntity(diamond); world.setBlockState(pos, Blocks.AIR.getBlockState().getBaseState()); item.setDead(); } }); } iterator.remove(); } } } } ``` 后来又折腾了一会把此功能拆分出来[做了个模组](https://github.com/ProjectHDS/FallingAlchemy) 实现了 - 自定义下落方块(沙子/沙砾/铁砧等) - 检测范围内指定物品并替换 - 支持多产物生成和数量比例控制 - 配方成功率 (`0.0~1.0`) - 方块保留几率 (`0.0~1.0`) - 检测半径动态调整 - 失败/成功音效定制化 - NBT模糊匹配 (`fuzzyNBT`) - 配方执行优先级 (`priority`) - 生物群系限制 - 时间范围 (MC时间 `0~24000`) - 天气状态 (晴天/下雨/雷暴) - 高度限制 - 月相限制 本文链接: https://shrinken.pw/crash-2025-03-23_96-fml.html