--- front: hard: 入门 time: 分钟 --- # 自定义重力方块 ## 概述 自定义重力方块可以模拟[下落的方块](https://zh.minecraft.wiki/w/%E4%B8%8B%E8%90%BD%E7%9A%84%E6%96%B9%E5%9D%97),并且支持在组件中修改配置、python监听事件。 ## base_block设置 - 自定义重力方块的base_block需要设为`custom_heavy_block` ## netease:fall | 键 | 类型 | 默认值 | 解释 | | ------------ | ----- | -------------------- | ------------------------------------------------------------ | | send_python_event | bool | false | 可选,是否发送重力方块/下落方块实体相关事件至python | | fall_acceleration | float | 0.04 | 可选,下落的方块实体每次tick的垂直加速增量 | | adjust_percentage | float | 0.98 | 可选,下落的方块实体每次tick移动完后移速乘的调整数值 | | hurt_entity | bool | false | 可选,下落的方块实体结束下落后是否要计算对碰撞实体的伤害 | | fall_damage_amount | float | 2.0 | 可选,原版下落伤害计算完后乘的倍率 | | max_fall_damage | int | 40 | 可选,下落伤害乘完倍率后也会被限制在该值的范围内 | | min_height_remove_tick | int | 100 | 可选,当下落的方块实体低于区块最低高度后多少tick将其强制删除 | | force_break_tick | int | 600 | 可选,下落的方块实体多少tick后会强制被破坏 | | cancel_drop | bool | false | 可选,下落的方块实体被破坏时是否取消方块物品的掉落 | - `send_python_event`主要影响HeavyBlockStartFallingServerEvent、FallingBlockCauseDamageBeforeServerEvent、FallingBlockBreakServerEvent、FallingBlockReturnHeavyBlockServerEvent、FallingBlockCauseDamageBeforeClientEvent几个事件。 - 如果没有在mod程序中监听的需要,可以不将`send_python_event`设为true以优化性能(不发python事件也可以配置组件的其他值)。 - 原版对于下落的方块实体计算下落的过程使用python伪代码表示大致为 ```python while Tick: falling_block.move_vector.y -= fall_acceleration # 当前移动向量增加一个向下的力 move(falling_block) # 按照当前的移动向量调整实体位置 falling_block.move_vector *= adjust_percentage # 移动完后将当前移速(移动向量)乘个数值回调 ``` - 原版下落的方块实体并没有对实体实时的碰撞检测,这就意味着在调整下落的方块移动速度时可能会遇到两个问题: - 如果两个下落的方块速度不一致,会看到一个方块实体从另一个方块实体传过去,并没有碰撞效果。 - 下落的方块对实体造成伤害的计算并不是在刚接触到实体时,而是在落地时才检测范围有无实体,把移速调整的慢点更容易观察到此现象。 ## 示例配置 可参考[CustomBlocksMod](../../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)中的customblocks:customblocks_test_heavy.json。 ```json { "format_version": "1.10.0", "minecraft:block": { "description": { "identifier": "customblocks:customblocks_test_heavy", "base_block": "custom_heavy_block", "category": "custom" }, "components": { "netease:fall": { "send_python_event":true, "fall_acceleration":0.04, "adjust_percentage":0.98, "hurt_entity":true, "min_height_remove_tick":100, "force_break_tick":600, "fall_damage_amount":2.0, "max_fall_damage":40 } } } } ```