Skip to content

Mods for NeoForge and Fabric

Entities

A plugin's entity types are mobs, projectiles and objects of its own, which players need a mod to see. Once any plugin adds to one of these registries, vanilla clients are refused: minecraft:block, minecraft:block_entity_type, minecraft:data_component_type (only types with a network codec), minecraft:entity_type, minecraft:item, minecraft:menu, minecraft:particle_type or minecraft:custom_stat. Players then need NeoForge or Fabric with the matching mod, or the Obsidian client with the mod.

Vanilla's mobs, their attributes and their loot are the server's (see Gameplay and the world); build and pack a mod as described in Building and packing.

Entity types

var golem = registry.RegisterEntity("ruby:golem", new EntityProperties
{
    Width = 1.4f,
    Height = 2.7f,
    MaxHealth = 100,
    Behavior = new GolemBehavior()
});

level.SpawnEntity(position, golem);

Kind decides how the entity moves:

  • Mob (the default): falls, takes damage and runs the goals given through IEntity.GoalController.
  • EntityKind.Projectile: flies along the motion it's spawned with, slowed by drag and pulled down by Gravity. It calls IEntityBehavior.HitAsync on the first block or living entity in its way, which removes it. Spawn it with level.SpawnEntity(position, type, motion, owner).
  • EntityKind.Object: falls and rests where it lands.

Every kind calls its behaviour each tick and when a player uses it. IEntityBehavior.InteractAsync returns whether the entity took the interaction; if it did, the held item's UseOnEntityAsync doesn't run. The client mod's entity should be of the same kind, so that their data matches. Entities are saved with the type's identifier, and saved ones are kept as they were while the plugin is gone.

A mob's Category (a MobCategory, Misc by default) is its vanilla mob category. Biomes' spawners and biome modifiers spawn a plugin's mobs naturally while it's loaded, counting against their category's cap. Misc mobs don't spawn naturally, since plugin mobs don't despawn.

PassengerAttachments says where riders sit: one point per seat, in blocks from the entity's feet with the entity facing south (+Z ahead, +X to its left). Passengers beyond the last point share it. Without points, passengers sit on top of the hitbox. A mob carries as many players as it has points, at least one. Register the type with the same points on both sides (in ConfigureRegistry, which both run), since the Obsidian client draws riders and the camera there.

registry.RegisterEntity("ruby:strider", new EntityProperties
{
    Width = 1.2f,
    Height = 1.6f,
    PassengerAttachments = [new VectorF(0, 1.4f, 0.2f), new VectorF(0, 1.4f, -0.6f)]
});

Riding and flying

A player who isn't sneaking mounts a plugin's mob by using it, when the behaviour's CanMount(entity, player) allows it and InteractAsync didn't take the interaction. From code, IPlayer.StartRiding(mob) mounts a player, IEntity.StopRiding() dismounts and IEntity.Vehicle is what an entity rides (see also Travel and portals).

The first passenger steers, and the mob's goals pause meanwhile:

  • a walking mob moves like a horse, at its MovementSpeed (a quarter of it backwards, half sideways), and jumps with jump;
  • a mob with Movement = EntityMovementMode.Flying moves like a happy ghast: towards where the rider looks, strafing sideways and rising with jump, gaining a tenth of its FlyingSpeed each tick. Flying mobs have no gravity or fall damage, and their goals path through the air.
var saddled = EntityDataFields.Boolean();

registry.RegisterEntity("ruby:drake", new EntityProperties
{
    Width = 1.4f,
    Height = 1.2f,
    Movement = EntityMovementMode.Flying,
    FlyingSpeed = 0.5f,
    PassengerAttachments = [new VectorF(0, 1.2f, 0)],
    DataFields = [saddled],
    Behavior = new DrakeBehavior(saddled)
});

sealed class DrakeBehavior(EntityDataField<bool> saddled) : IEntityBehavior
{
    public bool CanMount(IEntity entity, IPlayer player) => entity.GetData(saddled);
}

The Obsidian client predicts a mob its player rides, as vanilla's client does a horse, and sends the server where it went. The server checks those moves as vanilla does and puts the mob back when one is too far off. Clients that don't predict are steered by the server. Register the type with the same Movement, speeds and size on both sides so that both move it alike; attribute modifiers apply on both sides, since attributes are synced.

Synced data fields

DataFields lists a type's synced data fields, like vanilla's SynchedEntityData. Make each with EntityDataFields (Byte, Int, Long, Float, String, Boolean, Item or BlockPos), and read and write them with IEntity.GetData(field) and SetData(field, value). A change is sent on the entity's next tick.

  • Fields get fixed indices after vanilla's, in their order; EntityDataField.Index gives a field's once its type is registered. A field can't have a different index in another type.
  • Only Obsidian clients with the mod are sent them. They read them with entity.TryGetData(field, out var value) or from IClientEntity.Metadata, for example in entity renderers. Register the type with the same fields on both sides.
  • Fields aren't saved. Keep lasting data in an attachment (see Saved data and attachments) and set the field from it, in the behaviour's TickAsync say, or use a synced attachment directly.

Damage and death

IEntityBehavior.HurtAsync(entity, damage) runs when a plugin's mob is about to take damage, after its immunities and before armour and absorption, like NeoForge's LivingIncomingDamageEvent. Change damage.Amount or set damage.Cancelled. damage.Source is a DamageSource: vanilla's damage type (minecraft:player_attack, minecraft:arrow, minecraft:fall and so on), the attacker and the direct entity. DiedAsync(entity, source) runs when it dies, before its loot drops.

A dying plugin mob drops its type's loot table, data/<namespace>/loot_table/entities/<path>.json, as described in Mob loot.

Spawn placement

SpawnPlacement gives natural spawning a type's own rules, like vanilla's spawn placements: OnGround, InWater, InLava or NoRestrictions, each needing room for the hitbox. Natural spawning then skips the spawn list's light and floor rules and asks the behaviour's CanSpawn(level, position), which can check light, blocks or anything else. Without a placement, a mob follows its spawn list's rules: on grass in light for creatures, in water for the water categories, and in the dark otherwise.

Spawn eggs

Set EntityProperties.SpawnEgg = true when registering a mob to register <namespace>:<path>_spawn_egg too. EntityDefinition.SpawnEgg is its item; put it in a CreativeTabProperties.Items list. Supply assets/<ns>/items/<path>_spawn_egg.json, its model and its texture as for any item. ObsidianMod's moth shows all three and a creative tab. For an item you register yourself, ItemProperties.EntityData sets the same component: its RegistryId is the mob type's id and Data holds extra saved fields.

A spawner set with the egg keeps an unloaded plugin's type and resumes when the plugin returns.

Movement

Plugins grant players MovementAbilities (see Movement). Two of them need the Obsidian client:

  • ExtraJumps: jumps in the air before landing, each a new press of jump, as high as a ground jump and forgiving the fall so far (a double jump is ExtraJumps = 1);
  • CanGlide: gliding as with an elytra, without one. A press of jump in the air starts it, landing ends it.
// Boots of the clouds: a double jump while they're worn, from an equipment change handler, say.
player.SetMovementAbilities("ruby:cloud_boots", new MovementAbilities { ExtraJumps = 1 });

// Taken off.
player.RemoveMovementAbilities("ruby:cloud_boots");

Grants with different ids add up, and their extra jumps sum. They use the keys vanilla already sends, so a mod needs no input of its own. For a move on its own key, bind the key on the client and send a payload (see Client) whose server handler grants the ability. On a vanilla client the player just doesn't jump twice or glide.

On this page