• 欢迎来到Minecraft插件百科!
  • 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
  • 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289

Magic/Custom Spells

来自Minecraft插件百科
炫宙菌讨论 | 贡献2021年7月29日 (四) 20:27的版本 解剖法术
跳转至: 导航搜索

插件自定义法术

Magic的法术可以非常复杂,从零开始可能很困难,所以如果默认的内部法术里面有类似于你心中理想的法术,可以试试在此基础上修改修改

Magic的法术类似于脚本事件,可以包含十分复杂的规则、行为和逻辑,借此制作高度自由化的视觉以及游戏体验

工具和参考

在阅读了以下教程后,有些网页工具就显得非常有用了:

  • 参考指南 深入所有细节,列出了所有参数、行为、效果以及其他本指南中提到的 Legacy version 1.13-版本专用
  • Default survival spell list 查看更高级的内置生存服技能的相关信息,并且把游戏中的关键词转化为相应内容以查到正确的配置

教学

本教程将由魔法导弹技能开始学习,逐步拨云见日地了解它的组成

分析法术

多数法术有五个主要部分,我们每次讨论一个:

  • Base Properties: 基础的法术设置,比如图标、SP消耗和SP获取量,以及一些法杖升级或使用/cast parameters无法更改的内容
  • Actions: 完善的法术使用Modern spells use the 行为系统, 可以让你灵活地自定义法术的行为,实现你所想的效果
  • Effects: 有多种施法时产生的视觉效果,一般由施法多个过程触发
  • Parameters: 行为需要参数来改变它们的视觉效果。参数可以作为进阶法术、法杖或使用/cast parameters时的必备部分,更加直接和方便地测试法术的效果。译者注:参数包含如技能伤害、范围、时效等内容
  • Costs: 法术需要一些消耗才能释放,大多数情况消耗法力,当然物品、金钱和生命值也是可以作为消耗的

Base Properties

Let's take a look at Magic Missile, the configuration of which can be found here.

missile:

This is the spell's "key" name. This is what is used when referencing this spell in configs, with the /cast command or /wand commands.

    icon: diamond_axe:160
    icon_disabled: diamond_hoe:160
    icon_url: http://textures.minecraft.net/texture/2ba95570c7b712713632d4c0d2fc66906613d3850a596a0267c6d763fe741ac

The icon for a spell is the item that will be used to represent it in-game. This can be on a wand, in a shop, as an item, etc.

Magic can be configured to use icons from a resource pack (the default), vanilla items, or textured player skulls. If "urliconsenabled" is set to true in config.yml, spells will use the icon_url property to create a player skull with a custom texture.

Otherwise, spells use the icon property as their icon. When a spell is not available to cast (out of mana, on cooldown, no permission) the icon_disabled property is used. (Skull-based icons do not support a disabled icon). In the official Magic resource packs, the disabled icon for each spell is identical to the normal icon, but with a red "no" sign overlayed.

    upgrade_required_path: beginner
    upgrade_required_casts: 40

Spells can have upgrades. Upgrade spells are defined using the pipe character |, so "missile|2" is Magic Missile Level 2. Spell upgrades inherit from the previous level, meaning they have all of the same properties unless overridden. For example, as Magic Missile levels up its range and damage increase.

These properties define how upgrading works- in this case for Magic Missile to upgrade, you must be on the "Beginner" path and have cast the spell successfully 40 times.

    category: combat

Spells can have categories, this is mainly used for organization in spell books and the /spells command.

    worth: 150
    earns_sp: 8
    earns_cooldown: 10000

These define how Spell Points work for this spells. The worth properties is the cost of the spell in spell points. (Or currency, depending on spellshop configuration).

The earns_sp property defines the maximum amount of SP this spell will earn. When a spell earns SP, it goes on cooldown for some amount of time. During this time, the amount of SP you earn for additional successful casts is reduced. This is to prevent players grinding their way through levels quicky.

The earns_cooldown property defines how long the SP earn cooldown lasts for this spell. Note that this is not a hard cooldown, the spell can still earn SP, it is just reduced proportionally to how long it has been since the spell last earned SP.

For example, the first time you cast Magic Missile, it will earn 8 SP. If you cast it again 5 seconds later (half of the 10-second cooldown) it will only earl 4 SP.

Magic Missile is the first spell a player will get on the default wand, so as a manner of tutorial its SP cooldown is greatly reduced. The default value for all other spells is 15 minutes.

As Magic Missile levels up, its SP cooldown increases until it is on par with other spells.

In-Game Text

To make localization easier, Magic tries to put all in-game text in messages.yml. Each spell's name and description can be found under the "spells" section.

However, for convenience you may also put a name and description property in a spell's base properties.

Spell Classses

Some older spells, such as SuperBlob, use a class property like this:

superblob:
    class: ConstructSpell

These spells predate the action system, and cannot use actions or have an actions section.

The behavior of these spells is completely hard-coded. Each spell has its own class, which can be seen here in the source code.

It is not recommended to use these if you can avoid it since they are not as customizable as action-based spells. However, some spells like engineering magic have not been converted (yet) and use ConstructSpell, for instance.

Actions

Most spells now use the Actions. The actions section is used to define what actions a spell will perform when cast.

Let's look at Magic Missile again:

    actions:
        cast:
        - class: CustomProjectile
          actions:
          - class: Damage
          - class: BreakBlock
            ignore_result: true

There can be multiple sections of actions, but most spells will have only cast, the actions performed when this spell is cast.

Actions are often a hierarchy, meaning one action may have "child" actions that it is responsible for running under certain conditions.

Each action must have at least a class property, this defines what action it is. Classes can be found on the Actions page, or you can look at the source code here.

Note that when referring to the source code, the "Action" part of the class name may be omitted when you use it in a spell configuration.

Many spells in the builtin configs start off with the "CustomProjectile" action. This action creates a virtual projectile (not a vanilla snowball, arrow, etc) with some extremely customizable behavior.

When the projectile hits a target (either block or entity) it will run it's actions list.

In this case, when Magic Missile hits it will perform the Damage action and the BreakBlock action. Both are performed no matter the target, but if hitting a block Damage will do nothing, if hitting an entity BreakBlock will do nothing.

Action Parameters

Every action has some parameters that can change its behavior. These parameters can be put in two places: As properties directly on an action in the actions list, or as common shared parameters in the parameters section (see below).

In this case, the BreakBlock action has ignore_result set to true.

Every action returns a result, generally success, fail or no_target. For a spell to count as a successful cast, at least one action must return success. This is the only way for it to earn SP, or have the cast count towards the spell upgrade counter.

In the case of Magic Missile, breaking blocks is more of a secondary cosmetic effect, and does not count towards earning SP. You must hit and damage an entity for Magic Missile to count as a success.

And so, "ignore_result: true" on the BreakBlock action says to ignore the result of that action, meaning that Damage is the only action that matters for the overall result of the spell.

Effects

The effects section defines the visual effects that a spell will use. Spells should generally at least have a cast effects section so that something visual happens when the spell is cast. Generally some particle FX and a sound are good to make a spell feel meaningful.

Let's look at Magic Missile:

        cast:
        -  class: EffectSingle
           sound: magic.zap_crack
           location: origin
           color_override: color
           effectlib:
             class: ConeEffect
             iterations: 10
             particle: redstone
             lengthGrow: 0.1
             radiusGrow: 0.003
             updateLocations: false
             updateDirections: false

The cast section will run when the spell is cast. Each section is really a list, so you can run multiple different effects on cast. Each section in the list can have a few properties:

  • class: The class of effect. This is sort of outdated and can mostly be ignored and omitted. EffectSingle means to run a single effect, but most effects in Magic now defer to EffectLib. Other options are EffectRing, EffectTrail and EffectTransform but they are rarely used.
  • sound: A sound effect to play, which can be a custom sound from a resource pack (such as with "magic.zapcrack" here or a builtin vanilla sound, using its Sound enum. **soundpitch** and sound_volume can also be used to modify the sound.
  • location: Where the effect should play. This can be origin (the caster), target or both.
  • color_override: Wands have personalized colors which can be used by spells. The color_override property tells the effectlib effects to use the wand color as one if its parameters (usually color, which is how the color of most effectlib effects is controlled). This only works with the redstone and mob_spell particles.
  • effectlib: Magic is deeply integrated with EffectLib and most spells use an effectlib effect. See here for details on configuring effectlib effects.

Magic Missile also has a "tick" effect list:

        tick:
        - particle: redstone
          location: target 

In this case you can see that class has been omitted, EffectSingle will be used as the default class.

The tick effect list is a special set of effects used by the CustomProjectile action. These effects will be shown on every server tick while the projectile is running. They may be shown multiple times per tick, depending on the projectile velocity and configuration, so it's best not to put anything too complex in here.

In this case, we are showing a single particle, whose names come from the EffectLib particle enum.

Magic Missile has several other effect blocks, too many to list here. It has special effects for headshots, hitting blocks, etc. If you're curious, take a look at [the configs].(https://github.com/elBukkit/MagicPlugin/blob/master/Magic/src/main/resources/examples/survival/spells/missile.yml#L18).

Parameters

Spells have several base parameters that can be seen here: SpellParameters

Each action also has its own parameters, which can be seen on the Actions page, though it is not completely up to date. Action parameters can also be found in the source code of each action, by searching for the "prepare" method and looking at what it reads out of its configuration.

Parameters in the parameters section affect all actions in the spell.

Let's look at Magic Missile (TODO: Flesh this out)

    parameters:
        allow_max_range: true
        velocity: 200
        range: 24
        hitbox: true
        target_type: Damageable
        player_damage: 2
        entity_damage: 4
        target_breakables: 1
        cooldown: 1000
        reorient: false
        destructible: solid
        destructible_durability: 50
        break_durability: 2
        undo: 10000

Headshots

The CustomProjectile action can detect when you hit an entity in the head. In this case, it may run a separate set of headshot actions, or in some cases (like Magic Missile) just use some extra parameters:

    headshot_parameters:
      damage_multiplier: 1.5

So a headshot with Magic Missile multiplies the damage done by 150%.

Costs

Costs are lists of costs required to cast the spell. It is most often just mana, like this:

    costs:
        mana: 15

Requirements

Spells can have requirements assigned to them, which much be met in order for the player to purchase and use them. This can be used to create reasearch or teching paths, requiring players to have a certain class, skill, spell, etc, before they can purchase the spell.

Right now the current requirements are supported:

  • Type: skillapi
    • skill - Requires the player to have the specified SkillAPI skill
    • class - Requires the player to have the specified SkillAPI class

Here is an example requirement block, which might appear in a spell, Selector or other config. It requires the player to have the skillapi skill enchanting

    requirements:
        -  type: skillapi
        -  skill: enchanting

type specifies the type of requirement
skill further specifies that a skill from skillAPI is required, and what that skill is