Mob Definitions
Declaring a mob
mod.content().entity("golem_friend", EntityDefinition.builder(ResourceId.of("my_mod", "textures/entity/golem_friend.png"))
.maxHealth(20)
.movementSpeed(0.25)
.panicWhenHurt()
.temptedBy(SPARK) // follows you when you hold this item
.spawnEgg(CreativeTab.SPAWN_EGGS)
.behavior(new EntityBehavior() { // onServerTick, onInteract
@Override
public InteractionResult onInteract(EntityInteraction interaction) {
if (!interaction.world().isClientSide()) {
interaction.entity().addEffect(GLOWING_HEART, 100, 0);
}
return InteractionResult.SUCCESS;
}
})
.build());
- You pick standard AI goals (wandering, looking at players, fleeing when hurt, attacking, being tempted by an item) for a game pathfinding mob. Custom goals are in AI goals and riding.
- By default, the mob is drawn with the player model wearing a 64×64 skin texture. To define a box model yourself, see Mob models.
- Create it with
/summon, a spawn egg, orworld.spawnEntity.
| Builder method | Meaning |
|---|---|
size(width, height) | Collision box size |
category(MobCategory) | CREATURE, MONSTER, AMBIENT, WATER_CREATURE |
maxHealth, movementSpeed | Attributes |
noWandering(), panicWhenHurt(), attackPlayers(damage), temptedBy(item) | Pick standard AI goals |
goal(priority, factory), targetGoal(priority, factory) | Custom AI goals |
rideable(steerable) | Can be ridden (steerable if true) |
noGravity(), notPushable() | No gravity; cannot be pushed |
spawnEgg(CreativeTab) | Spawn egg item (<id>_spawn_egg) |
spawnsNaturally(biomes, weight, minGroup, maxGroup) | Natural spawning |
model(EntityModelDefinition) | Box model |
flying(flyingSpeed), swimming() | Flying mob, swimming mob. See "Movement" below |
behavior(EntityBehavior) | onServerTick, onInteract callbacks |
No data fixer registered for <id>Minecraft 26.2 has no data conversion schema for mod entities, so it writes this error log line at startup. It does not affect behavior.
Movement
By default, a mob walks and runs, and floats up to the surface in water (Movement.WALK). Changing the movement style changes pathfinding, movement control, and the default wandering goal together.
| Builder | Behavior |
|---|---|
flying(flyingSpeed) | Finds paths through the air, and hovers in place when it stops (like a bee). No fall damage. Air speed is flyingSpeed (parrot 0.4) |
swimming() | Finds paths only through water, and swims in any direction (like a dolphin). Breathes in water. Crawls slowly out of water. To spawn in water, use category(MobCategory.WATER_CREATURE) |
mod.content().entity("minnow", EntityDefinition.builder(ResourceId.of("my_mod", "textures/entity/minnow.png"))
.size(0.5f, 0.4f)
.category(MobCategory.WATER_CREATURE)
.movementSpeed(1.0)
.swimming()
.build());
MobView.navigateTo(x, y, z, speed) also finds paths in the mob's movement style. A flying mob goes to a point in the air, and a swimming mob goes to a point in the water.
Natural spawning
EntityDefinition.builder(texture)
.spawnsNaturally(BiomeSelector.ids(ResourceId.minecraft("plains")), 5, 1, 2);
- When the server creates the world, the mob is added to the spawn list of the selected biomes (log line
[Poly Mod Loader] Added N natural spawn(s)). - Spawn location rules follow game mobs of the same category. Creatures spawn on bright
#minecraft:animals_spawnable_onblocks, monsters in the dark, and water creatures in water. - Check with
WorldView.naturalSpawns(pos, category). - For code biomes, add it with
BiomeDefinition.builder().spawn(...). See World generation.
Projectiles
mod.content().projectile("bolt", ProjectileDefinition.builder(SPARK) // item look drawn on the client
.damage(2)
.behavior(new ProjectileBehavior() {
@Override
public void onHitEntity(ProjectileHit hit) {
if (hit.entity().orElseThrow() instanceof LivingEntityView living) {
living.addEffect(ResourceId.minecraft("glowing"), 100, 0);
}
}
})
.build());
player.launchProjectile(ResourceId.of("my_mod", "bolt"), 1.5f, 1.0f); // speed, inaccuracy
- It flies like a snowball. At the first thing it hits, it deals damage, calls the behavior callback (
onHitEntity,onHitBlock), and then disappears. - You can set
size,gravity, anddamage. launchProjectilealso fires game projectiles such asminecraft:snowball.
Entity views
| Type | Main methods |
|---|---|
EntityView | uuid, type, name, x/y/z, blockPos, world, isAlive, remove, teleport, changeDimension, data(key) |
LivingEntityView | health, maxHealth, setHealth, hurt(amount), hurt(damageType, amount), addEffect, hasEffect, launchProjectile |
MobView | Pathfinding, gaze, attack target. See AI goals and riding |
PlayerView | sendMessage, give, countItem, mainHandItem, mainHandStack, inventory, openMenu, advancements, hasPermission |
EntityView golem = world.spawnEntity(GOLEM, x, y, z);
List<EntityView> near = world.entitiesNear(x, y, z, 5);
entity.changeDimension(ResourceId.minecraft("the_nether"), x, y, z);