9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 12:56:28 +00:00

添加蔓延方块行为

This commit is contained in:
jhqwqmc
2025-12-27 04:41:13 +08:00
parent 1f8f23f1d3
commit ea2c2635bd
4 changed files with 49 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ public class BukkitBlockBehaviors extends BlockBehaviors {
public static final BlockBehaviorType DROP_EXPERIENCE_BLOCK = register(DropExperienceBlockBehavior.ID, DropExperienceBlockBehavior.FACTORY);
public static final BlockBehaviorType DROP_EXP_BLOCK = register(Key.from("craftengine:drop_exp_block"), DropExperienceBlockBehavior.FACTORY);
public static final BlockBehaviorType MULTI_HIGH_BLOCK = register(MultiHighBlockBehavior.ID, MultiHighBlockBehavior.FACTORY);
public static final BlockBehaviorType SPREADING_BLOCK = register(SpreadingBlockBehavior.ID, SpreadingBlockBehavior.FACTORY);
public static void init() {
}

View File

@@ -0,0 +1,46 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.behavior.BlockBehavior;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.LazyReference;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
public class SpreadingBlockBehavior extends BukkitBlockBehavior {
public static final Key ID = Key.from("minecraft:spreading_block");
public static final BlockBehaviorFactory FACTORY = new Factory();
private final LazyReference<Object> targetBlock;
public SpreadingBlockBehavior(CustomBlock customBlock, String targetBlock) {
super(customBlock);
this.targetBlock = LazyReference.lazyReference(() -> Objects.requireNonNull(BukkitBlockManager.instance().createBlockState(targetBlock)).literalObject());
}
@Override
public void randomTick(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
Object level = args[1];
Object pos = args[2];
Object blockPos = FastNMS.INSTANCE.method$BlockPos$offset(pos, RandomUtils.generateRandomInt(-1, 2), RandomUtils.generateRandomInt(-3, 2), RandomUtils.generateRandomInt(-1, 2));
if (FastNMS.INSTANCE.method$BlockStateBase$isBlock(FastNMS.INSTANCE.method$BlockGetter$getBlockState(level, blockPos), FastNMS.INSTANCE.method$BlockState$getBlock(this.targetBlock.get()))) {
FastNMS.INSTANCE.method$LevelWriter$setBlock(level, blockPos, this.block().defaultState().customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags());
}
}
public static class Factory implements BlockBehaviorFactory {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String targetBlock = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("target-block"), "warning.config.block.behavior.spreading.missing_target_block");
return new SpreadingBlockBehavior(block, targetBlock);
}
}
}

View File

@@ -435,6 +435,7 @@ warning.config.block.behavior.surface_spreading.missing_base_block: "<yellow>Iss
warning.config.block.behavior.snowy.missing_snowy: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'snowy' property for 'snowy_block' behavior.</yellow>"
warning.config.block.behavior.hangable.missing_hanging: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'hanging' property for 'hangable_block' behavior.</yellow>"
warning.config.block.behavior.multi_high.missing_high: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'high' property for 'multi_high_block' behavior.</yellow>"
warning.config.block.behavior.spreading.missing_target_block: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'target-block' argument for 'spreading_block' behavior.</yellow>"
warning.config.model.generation.missing_parent: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'parent' argument in 'generation' section.</yellow>"
warning.config.model.generation.conflict: "<yellow>Issue found in file <arg:0> - Failed to generate model for '<arg:1>' as two or more configurations attempt to generate different json models with the same path: '<arg:2>'.</yellow>"
warning.config.model.generation.invalid_display_position: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid display position '<arg:2>' in 'generation.display' section. Allowed display positions: [<arg:3>]</yellow>"

View File

@@ -435,6 +435,7 @@ warning.config.block.behavior.surface_spreading.missing_base_block: "<yellow>在
warning.config.block.behavior.snowy.missing_snowy: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'snowy_block' 行为缺少必需的 'snowy' 属性</yellow>"
warning.config.block.behavior.hangable.missing_hanging: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'hangable_block' 行为缺少必需的 'hanging' 属性</yellow>"
warning.config.block.behavior.multi_high.missing_high: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'multi_high_block' 行为缺少必需的 'high' 属性</yellow>"
warning.config.block.behavior.spreading.missing_target_block: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'spreading_block' 行为缺少必需的 'target-block' 选项</yellow>"
warning.config.model.generation.missing_parent: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 的 'generation' 段落缺少必需的 'parent' 参数</yellow>"
warning.config.model.generation.conflict: "<yellow>在文件 <arg:0> 发现问题 - 无法为 '<arg:1>' 生成模型 存在多个配置尝试使用相同路径 '<arg:2>' 生成不同的 JSON 模型</yellow>"
warning.config.model.generation.invalid_display_position: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 在 'generation.display' 区域使用了无效的 display 位置类型 '<arg:2>'. 可用展示类型: [<arg:3>]</yellow>"