动态形态系统 - Junye-666/RideBattleLib_NeoForge_1.21.1 GitHub Wiki

动态形态是 RideBattleLib 最强大的特性之一,允许根据驱动器内的物品组合自动生成形态。

用于组合数量巨大的骑士系统,例如 Build、OOO。
无需为每种组合预先注册形态。

启用动态形态

在 RiderBuilder 中:

RiderBuilder.create(RIDER_ID)
        .driver(Items.NETHERITE_LEGGINGS)
        .slot(SLOT_1, List.of(Items.EMERALD, Items.DIAMOND), true, true)
        .slot(SLOT_2, List.of(Items.REDSTONE, Items.GLOWSTONE_DUST), true, true)
        .form(BASE_FORM)
            .armor(Items.LEATHER_HELMET, Items.LEATHER_CHESTPLATE, null, Items.LEATHER_BOOTS)
            .triggerType(TriggerType.KEY)
            .requiredItem(SLOT_1, Items.AIR)
            .requiredItem(SLOT_2, Items.AIR)
            .attribute(Attributes.MAX_HEALTH, 8.0, AttributeModifier.Operation.ADD_VALUE)
            .allowsEmptyDriver(true)
        .end()
        .baseForm(BASE_FORM)

        .allowDynamicForms(true) // 允许动态形态匹配

        .buildAndRegister();

ExampleDynamicPack

映射可通过Builder构建

public class ExampleDynamicPack implements IRiderPack {

    public static final ResourceLocation RIDER_ID = rl("test_beta");
    public static final ResourceLocation BASE_FORM = rl("beta_base_form");
    public static final ResourceLocation SLOT_1 = rl("beta_slot_1");
    public static final ResourceLocation SLOT_2 = rl("beta_slot_2");

    private static ResourceLocation rl(String path) {
        return ResourceLocation.fromNamespaceAndPath(RideBattleLib.MODID, path);
    }

    @Override
    public ResourceLocation riderId() {
        return RIDER_ID;
    }

    @Override
    public void registerCommon() {
        RiderBuilder.create(RIDER_ID)
                .driver(Items.NETHERITE_LEGGINGS)
                .slot(SLOT_1, List.of(Items.EMERALD, Items.DIAMOND), true, true)
                .slot(SLOT_2, List.of(Items.REDSTONE, Items.GLOWSTONE_DUST), true, true)

                .form(BASE_FORM)
                    .armor(Items.LEATHER_HELMET, Items.LEATHER_CHESTPLATE, null, Items.LEATHER_BOOTS)
                    .triggerType(TriggerType.KEY)
                    .requiredItem(SLOT_1, Items.AIR)
                    .requiredItem(SLOT_2, Items.AIR)
                    .attribute(Attributes.MAX_HEALTH, 8.0, AttributeModifier.Operation.ADD_VALUE)
                    .allowsEmptyDriver(true)
                .end()

                .baseForm(BASE_FORM)
                .allowDynamicForms(true)
                .buildAndRegister();

        buildDynamicMappings();
    }

    private static void buildDynamicMappings() {
        DynamicMappingBuilder.forRider(RIDER_ID)
                .armor(Items.DIAMOND, EquipmentSlot.HEAD, Items.DIAMOND_HELMET)
                .effects(Items.DIAMOND, MobEffects.JUMP, MobEffects.ABSORPTION)
                .grantedItem(Items.DIAMOND, Items.DIAMOND_AXE)

                .armor(Items.EMERALD, Items.TURTLE_HELMET)
                .effect(Items.EMERALD, MobEffects.DAMAGE_RESISTANCE)
                .grantedItem(Items.EMERALD, Items.GOLDEN_CARROT)

                .armor(Items.REDSTONE, Items.IRON_CHESTPLATE)
                .effect(Items.REDSTONE, MobEffects.DAMAGE_BOOST)

                .armor(Items.GLOWSTONE_DUST, Items.GOLDEN_CHESTPLATE)
                .effect(Items.GLOWSTONE_DUST, MobEffects.MOVEMENT_SPEED)

                .undersuit(Items.SKELETON_SKULL, Items.CHAINMAIL_CHESTPLATE, null, Items.CHAINMAIL_BOOTS)
                .register();
    }
}

DynamicMappingBuilder 方法链

DynamicMappingBuilder.forRider(riderId)
        .armor(Items.DIAMOND, EquipmentSlot.HEAD, Items.DIAMOND_HELMET)
        .armor(Items.EMERALD, Items.TURTLE_HELMET)
        .effect(Items.DIAMOND, MobEffects.JUMP)
        .effect(Items.DIAMOND, MobEffects.DAMAGE_BOOST, 1200, 1)
        .effects(Items.DIAMOND, MobEffects.JUMP, MobEffects.ABSORPTION)
        .grantedItem(Items.DIAMOND, Items.DIAMOND_SWORD)
        .grantedItems(Items.DIAMOND, new ItemStack(Items.DIAMOND_SWORD), new ItemStack(Items.DIAMOND_AXE))
        .undersuit(Items.LEATHER_HELMET, Items.LEATHER_CHESTPLATE, null, Items.LEATHER_BOOTS)
        .register();

必须调用 .register(),否则映射不生效。

动态形态 ID 生成规则

命名空间: 骑士 ID 的命名空间
路径: 骑士路径 + "_" + 物品路径1 + "_" + 物品路径2 + ...

系统会自动裁剪多个物品的共同后缀。
示例:

骑士 ID 驱动器中物品 生成的形态 ID
mymod:build rabbit_full_bottle, tank_full_bottle mymod:build_rabbit_tank
mymod:ooo taka_medal, tora_medal, batta_medal mymod:ooo_taka_tora_batta

动态形态配置优先级

1. 物品映射 DynamicMappingBuilder
   ├── 盔甲映射
   ├── 效果映射
   └── 授予物品映射

2. 骑士基础配置 RiderConfig.baseAttributes / baseEffects

3. 预设基础形态配置
   ├── triggerType
   └── shouldPause

4. 默认值
   ├── triggerType = KEY
   └── shouldPause = false

匹配优先级:预设形态 > 动态形态。