Modding:Basic Entity: Difference between revisions

From Vintage Story Wiki
No edit summary
No edit summary
Line 47: Line 47:
=== Client ===
=== Client ===


The client type has different properties for client and server. This will cover the client side:
The client type has different properties for client and server. This will cover the client side (rendering, shape, texture):


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
   "client": {
   "client": {
     "renderer": "Shape", //  
     "renderer": "Shape", // How the entity will be rendered, "Shape" is the right one in almost all cases.
     "shape": { "base": "entity/land/littlefigure" }, // a path to our shape
     "shape": { "base": "entity/land/littlefigure" }, // a path to our shape
     "texture": { "base": "game:block/wood/planks/birch1" }, // the figure should have the texture of birch wood. Therefore the prefix "game" is needed
     "texture": { "base": "game:block/wood/planks/birch1" }, // the figure should have the texture of birch wood. Therefore the prefix "game" is needed
Line 57: Line 57:
       { "code": "repulseagents" },
       { "code": "repulseagents" },
       {
       {
         "code": "controlledphysics",
         "code": "controlledphysics", // Adds physics to the entity
         "stepHeight": 0.2
         "stepHeight": 0.2
       },
       },
       {
       {
         "code": "floatupwhenstuck",
         "code": "floatupwhenstuck", // Fixes corpse get stuck in ground
         "onlyWhenDead": true
         "onlyWhenDead": true
       },
       },
       { "code": "interpolateposition" }
       { "code": "interpolateposition" } // Smooths out movement of entity
     ],
     ],
     "animations": [
     "animations": [ // Animations which have to be implemented by the shape as well
       {
       {
         "code": "hurt",
         "code": "hurt",
Line 87: Line 87:
=== Server ===
=== Server ===


The server side handles the "brain" of the entity.
<syntaxhighlight lang="c#">
   "server": {
   "server": {
     "behaviors": [
     "behaviors": [
       { "code": "repulseagents" },
       { "code": "repulseagents" },
       {
       {
         "code": "controlledphysics",
         "code": "controlledphysics", // Adds physic interaction
         "stepHeight": 0.2
         "stepHeight": 0.2
       },
       },
       {
       {
         "code": "health",
         "code": "health", // Adds a health bar to the entity
         "currenthealth": 4,
         "currenthealth": 4,
         "maxhealth": 4
         "maxhealth": 4
       },
       },
       {
       {
         "code": "deaddecay",
         "code": "deaddecay", // Makes the dead entity stay for one hour
         "hoursToDecay": 1
         "hoursToDecay": 1
       },
       },
       {
       {
         "code": "floatupwhenstuck",
         "code": "floatupwhenstuck", // Fixes corpse get stuck in ground
         "onlyWhenDead": true
         "onlyWhenDead": true
       },
       },
       {
       {
         "code": "despawn",
         "code": "despawn", // Makes the entity despawn if there is no player within 48 blocks
         "minPlayerDistance": 48,
         "minPlayerDistance": 48,
         "minSeconds": 5
         "minSeconds": 5
       },
       },
       {
       {
         "code": "emotionstates",
         "code": "emotionstates", // Adds different emotion states
         "states": [
         "states": [
           {
           {
             "code": "fleeondamage",
             "code": "fleeondamage", // After the entity is hit it will try to flee for 10 seconds
             "duration": 10,
             "duration": 10,
             "chance": 0.2,
             "chance": 0.2,
Line 126: Line 129:
       },
       },
       {
       {
         "code": "taskai",
         "code": "taskai", // Handles what the entity does, a task will be processed one at a time
         "aitasks": [
         "aitasks": [
           {
           {
             "code": "idle",
             "code": "idle", // the figure will stand still and think
             "priority": 1.2,
             "priority": 1.2,
             "priorityForCancel": 1.35,
             "priorityForCancel": 1.35,
Line 143: Line 146:
           },
           },
           {
           {
             "code": "wander",
             "code": "wander", // The entity will walk around
             "priority": 1.0,
             "priority": 1.0,
             "movespeed": 0.008,
             "movespeed": 0.008,
Line 151: Line 154:
           },
           },
           {
           {
             "code": "lookaround",
             "code": "lookaround", // The entity will look around
             "priority": 0.5
             "priority": 0.5
           }
           }
Line 158: Line 161:
     ]
     ]
   },
   },
</syntaxhighlight>


=== Result ===
=== Result ===
If we put everything together it should look like this:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">

Revision as of 10:00, 15 April 2019


We highly recommend to read the tutorial Getting Started first. This tutorial will cover the basics of adding an entity to the game using JSON files. There is a full list of all properties which can be defined inside the json file here.

Little Figure

The idea is create a little passive figure, made out of wood. The modid of our mod will be figure.

EntityType

Common

So first of all we have to create the entity type file assets/figure/entities/land/littlefigure.json. Now we go through all the properties:

code: The unique identifier for your entity. A prefix of your mod id will be added automatically. Our case its figure:littlefigure.

class: The class of the entity, it can be used to program special features for it. We don't need it at the moment, so we set it to EntityAgent.

hitboxSize: The size of the hitbox.

  "hitboxSize": {
    "x": 0.4,
    "y": 0.5
  },

deadHitboxSize: The size of the hitbox when the entity has died.

  "deadHitboxSize": {
    "x": 0.4,
    "y": 0.5
  },

eyeHeight: The height of the eyes, which is 0.4 for the little figure.

drops: A list of items to be dropped (can also include chances). We leave it empty for now: [].

sounds: Set the sounds for the entity

    "hurt": "creature/figure-hurt",
    "death": "creature/figure-death",
    "idle": "creature/figure-idle"

Client

The client type has different properties for client and server. This will cover the client side (rendering, shape, texture):

  "client": {
    "renderer": "Shape", // How the entity will be rendered, "Shape" is the right one in almost all cases.
    "shape": { "base": "entity/land/littlefigure" }, // a path to our shape
    "texture": { "base": "game:block/wood/planks/birch1" }, // the figure should have the texture of birch wood. Therefore the prefix "game" is needed
    "behaviors": [
      { "code": "repulseagents" },
      {
        "code": "controlledphysics", // Adds physics to the entity
        "stepHeight": 0.2
      },
      {
        "code": "floatupwhenstuck", // Fixes corpse get stuck in ground
        "onlyWhenDead": true
      },
      { "code": "interpolateposition" } // Smooths out movement of entity
    ],
    "animations": [ // Animations which have to be implemented by the shape as well
      {
        "code": "hurt",
        "animation": "hurt",
        "animationSpeed": 2.2,
        "weight": 10,
        "blendMode": "AddAverage"
      },
      {
        "code": "die",
        "animation": "die",
        "animationSpeed": 1.25,
        "weight": 10,
        "blendMode": "AddAverage"
      }
    ]
  },

Server

The server side handles the "brain" of the entity.

  "server": {
    "behaviors": [
      { "code": "repulseagents" },
      {
        "code": "controlledphysics", // Adds physic interaction
        "stepHeight": 0.2
      },
      {
        "code": "health", // Adds a health bar to the entity
        "currenthealth": 4,
        "maxhealth": 4
      },
      {
        "code": "deaddecay", // Makes the dead entity stay for one hour
        "hoursToDecay": 1
      },
      {
        "code": "floatupwhenstuck", // Fixes corpse get stuck in ground
        "onlyWhenDead": true
      },
      {
        "code": "despawn", // Makes the entity despawn if there is no player within 48 blocks
        "minPlayerDistance": 48,
        "minSeconds": 5
      },
      {
        "code": "emotionstates", // Adds different emotion states
        "states": [
          {
            "code": "fleeondamage", // After the entity is hit it will try to flee for 10 seconds
            "duration": 10,
            "chance": 0.2,
            "slot": 0,
            "prority": 1,
            "accumType": "max"
          }
        ]
      },
      {
        "code": "taskai", // Handles what the entity does, a task will be processed one at a time
        "aitasks": [
          {
            "code": "idle", // the figure will stand still and think
            "priority": 1.2,
            "priorityForCancel": 1.35,
            "minduration": 4000,
            "maxduration": 6000,
            "chance": 0.001,
            "initialMinCoolDown": 2000,
            "initialMaxCoolDown": 150000,
            "mincooldown": 300000,
            "maxcooldown": 10000000,
            "animation": "think",
            "animationSpeed": 1.25
          },
          {
            "code": "wander", // The entity will walk around
            "priority": 1.0,
            "movespeed": 0.008,
            "animationSpeed": 1.6,
            "animation": "run",
            "preferredLightLevel": 15
          },
          {
            "code": "lookaround", // The entity will look around
            "priority": 0.5
          }
        ]
      }
    ]
  },

Result

If we put everything together it should look like this:

{
  "code": "littlefigure",
  "class": "EntityAgent",
  "hitboxSize": {
    "x": 0.4,
    "y": 0.5
  },
  "deadHitboxSize": {
    "x": 0.4,
    "y": 0.5
  },
  "eyeHeight": 0.4,
  "drops": [],
  "client": {
    "renderer": "Shape",
    "shape": { "base": "entity/land/littlefigure" },
    "texture": { "base": "game:block/wood/planks/birch1" },
    "behaviors": [
      { "code": "repulseagents" },
      {
        "code": "controlledphysics",
        "stepHeight": 0.2
      },
      {
        "code": "floatupwhenstuck",
        "onlyWhenDead": true
      },
      { "code": "interpolateposition" }
    ],
    "animations": [
      {
        "code": "hurt",
        "animation": "hurt",
        "animationSpeed": 2.2,
        "weight": 10,
        "blendMode": "AddAverage"
      },
      {
        "code": "die",
        "animation": "die",
        "animationSpeed": 1.25,
        "weight": 10,
        "blendMode": "AddAverage"
      }
    ]
  },
  "server": {
    "behaviors": [
      { "code": "repulseagents" },
      {
        "code": "controlledphysics",
        "stepHeight": 0.2
      },
      {
        "code": "health",
        "currenthealth": 4,
        "maxhealth": 4
      },
      {
        "code": "deaddecay",
        "hoursToDecay": 1
      },
      {
        "code": "floatupwhenstuck",
        "onlyWhenDead": true
      },
      {
        "code": "despawn",
        "minPlayerDistance": 48,
        "minSeconds": 5
      },
      {
        "code": "emotionstates",
        "states": [
          {
            "code": "fleeondamage",
            "duration": 10,
            "chance": 0.2,
            "slot": 0,
            "prority": 1,
            "accumType": "max"
          }
        ]
      },
      {
        "code": "taskai",
        "aitasks": [
          {
            "code": "idle",
            "priority": 1.2,
            "priorityForCancel": 1.35,
            "minduration": 4000,
            "maxduration": 6000,
            "chance": 0.001,
            "initialMinCoolDown": 2000,
            "initialMaxCoolDown": 150000,
            "mincooldown": 300000,
            "maxcooldown": 10000000,
            "animation": "think",
            "animationSpeed": 1.25
          },
          {
            "code": "wander",
            "priority": 1.0,
            "movespeed": 0.008,
            "animationSpeed": 1.6,
            "animation": "run",
            "preferredLightLevel": 15
          },
          {
            "code": "lookaround",
            "priority": 0.5
          }
        ]
      }
    ]
  },
  "sounds": {
    "hurt": "creature/figure-hurt",
    "death": "creature/figure-death",
    "idle": "creature/figure-idle"
  }
}

Shape

Behaviors

Testing/ Distribution