Changes

525 bytes added ,  05:58, 6 October 2022
Add Entity Attributes Section
Line 45: Line 45:  
After creating and configuring the entity type builder, it must be built. This requires the modid and name of the entity type. For an entity type with the name "example_monster" in the mod "examplemod", this would look like <code>builder.build("examplemod:example_monster")</code>.
 
After creating and configuring the entity type builder, it must be built. This requires the modid and name of the entity type. For an entity type with the name "example_monster" in the mod "examplemod", this would look like <code>builder.build("examplemod:example_monster")</code>.
   −
===Tying It Together===
+
=== Tying It Together ===
Given the above information, a basic EntityType might look like the following:{{Tabs/Code Snippets
+
Given the above information, a basic EntityType might look like the following:
 +
{{Tabs/Code Snippets
 
|java=EntityType.Builder.of(ExampleMonsterEntity::new, MobCategory.MONSTER)
 
|java=EntityType.Builder.of(ExampleMonsterEntity::new, MobCategory.MONSTER)
 
     .sized(1.0F, 2.0F)
 
     .sized(1.0F, 2.0F)
Line 52: Line 53:  
     .updateInterval(1)
 
     .updateInterval(1)
 
     .build("examplemod:example_monster")
 
     .build("examplemod:example_monster")
}}To function, this example requires that an entity class of the name <code>ExampleMonsterEntity</code> exist along with the entity type being [[Registration|registered]].
+
}}
 +
To function, this example requires that an entity class of the name <code>ExampleMonsterEntity</code> exist along with the entity type being [[Registration|registered]].
    
== Entity Class ==
 
== Entity Class ==
Line 67: Line 69:     
To define custom behavior, methods must be overriden. Your IDE should have a feature to list all possible methods to override, although some common ones might be: <code>customServerAiStep</code> for server AI, <code>tick</code> for code to execute each tick on client/server, and <code>registerGoals</code> to setup AI goals.
 
To define custom behavior, methods must be overriden. Your IDE should have a feature to list all possible methods to override, although some common ones might be: <code>customServerAiStep</code> for server AI, <code>tick</code> for code to execute each tick on client/server, and <code>registerGoals</code> to setup AI goals.
 +
 +
== Entity Attributes ==
 +
Since 1.17 and later versions, you **MUST** define attributes if your entity class extends <code>LivingEntity</code> or any other class that inherits from it. In Attributes, you can define:
 +
 +
* Max Health
 +
* Movement Speed
 +
* Attack Damage
 +
 +
and more...
 +
 +
In your Entity class, create a static method that creates your attributes:
 +
<code>
 +
// In your Entity class...
 +
 +
public static AttributeSupplier.Builder setAttributes()
 +
{
 +
      return createHostileAttributes().add(Attributes.MAX_HEALTH);
 +
}
 +
</code>
    
== Natural Spawning ==
 
== Natural Spawning ==
 
To make entities naturally spawn, they must be added to the spawn list for each biome that the entity should spawn in. This can be achieved with a [[Biome Modifiers#Add Spawns|<code>forge:add_spawns</code> biome modifier]].
 
To make entities naturally spawn, they must be added to the spawn list for each biome that the entity should spawn in. This can be achieved with a [[Biome Modifiers#Add Spawns|<code>forge:add_spawns</code> biome modifier]].
11

edits