方块放置限制
基本信息
| 属性 | 值 |
|---|---|
| 实现类 | com.github.namikon.blocklimiter.events.BlockPlaceEvent |
| 监听事件 | net.minecraftforge.event.world.BlockEvent.PlaceEvent |
| 事件总线 | MinecraftForge.EVENT_BUS |
| 订阅优先级 | EventPriority.LOWEST |
| 注册时机 | BlockLimiter.postInit 当 Config.LoadConfig() 成功时 |
触发条件
事件源来自 Forge 的 BlockEvent.PlaceEvent,在任意玩家放置方块(含右击放置、左击放置、命令方块 setblock 之外的常规路径)时触发。
事件回调中按顺序执行:
- 创造模式豁免:当玩家处于创造模式且
BlockLimiter.Config.DenyCreativeMode == false时直接return。DenyCreativeMode = true时此规则被覆盖,包括创造模式玩家也会被拦截(默认false,默认行为下创造模式不受限制)。
- 通过
GameRegistry.findUniqueIdentifierFor(event.block)取得UniqueIdentifier(modId, name)。 - 遍历
BlockLimiter.Config.LimitedBlocks,对每条BlockInfo调用isDenied(uid, player.dimension)。
判定逻辑(BlockInfo.isDenied)
if (pUID.modId.equalsIgnoreCase(_mModID) && pUID.name.equalsIgnoreCase(_mBlockName)) {
if (_mBannedDimensions.contains(pDimensionID) || _mGlobalDenied) tResult = true;
}
- 大小写不敏感地比较
modId与blockName。 - 一旦匹配且该玩家所在维度在黑名单中(或条目为全局禁用),返回
true。
拦截后的反馈
若命中禁用条目,事件被 setCanceled(true) 取消放置,并在 try/catch 内执行:
| 步骤 | 行为 |
|---|---|
| 音效 | event.world.playSoundAtEntity(event.player, SFXOnBlockDeny, 1F, 1F);空字符串则静音 |
| 消息 | 从 RandomDenyMessages 中随机选一条,使用 PlayerChatHelper.SendNotifyWarning 发送给玩家 |
| 异常保护 | try/catch 捕获任意运行时异常,避免错误配置导致服务端崩溃 |
数值
| 数值 | 默认值 |
|---|---|
| 默认拒绝消息数量 | 5 条(RandomDenyMessages) |
| 默认拒绝音效 | minecraft:ambient.weather.thunder |
默认 DenyCreativeMode |
false |
限制
- 仅依赖
UniqueIdentifier比对,不支持 metadata / 子方块 / TileEntity 状态区分。 LOWEST优先级在其他模组之前生效;如果其他 mod 也想取消放置并将优先级设为HIGHEST,可能抢先生效。- 取消事件后还会播放声音与发送消息——监听同事件且优先级更高的模组若想自定义消息,需要先于本 mod 拦截或绕过。
相关条目
- BlockLimiter 配置 -
BlockList/RandomDenyMessages/SFXOnBlockDeny/DenyCreativeMode配置项 - /blimit 指令 - 通过
/blimit blockinfo查询当前生效的禁止方块列表