Skip to content

Examples

liopyu edited this page Oct 20, 2025 · 3 revisions

Minimal setups you can copy-paste to get things moving—starting with a tiny flying/floating mob you can build on.


Minimal Flying/Floating Entity 🪽

📜 Startup Script

EntityJSEvents.attributes(event => {
    event.modify("kubejs:wyrm", attributes => {
        attributes.add("minecraft:generic.flying_speed", 3)
        attributes.add("minecraft:generic.movement_speed", 0.3)
    })
})
StartupEvents.registry("entity_type", event => {
    let builder = event.create('wyrm', "entityjs:mob")
    builder.setMoveControl(entity => global.setMoveControl(entity))
    builder.createNavigation(context => global.createNavigation(context))
    builder.mobCategory("ambient")
    builder.sized(1, 2)
    builder.isInvulnerableTo(context => global.isInvulnerableTo(context))
})
/**
 * 
 * @param {Internal.ContextUtils$DamageContext} context 
 * @returns 
 */
global.isInvulnerableTo = context => {
    return context.damageSource.getType() == 'fall';
}
let FlyingMoveControl = Java.loadClass("net.minecraft.world.entity.ai.control.FlyingMoveControl")
/**
 * 
 * @param {Internal.LivingEntity} entity 
 * @returns 
 */
global.setMoveControl = entity => {
    return new FlyingMoveControl(entity, 20, true)
}
/**
 * 
 * @param {Internal.ContextUtils$EntityLevelContext} context 
 * @returns 
 */
global.createNavigation = context => {
    let nav = EntityJSUtils.createFlyingPathNavigation(context.entity, context.level)
    nav.setCanFloat(true)
    nav.setCanOpenDoors(false)
    nav.setCanPassDoors(true)
    return nav
}

📜 Server Script

EntityJSEvents.addGoalSelectors("kubejs:wyrm", event => {
    event.waterAvoidingRandomFlying(1, 1)
    event.meleeAttack(1, 1, false)
})

let Player = Java.loadClass("net.minecraft.world.entity.player.Player")
EntityJSEvents.addGoals("kubejs:wyrm", event => {
    let mob = event.entity
    let followRange = mob.getAttribute("minecraft:generic.follow_range").value
    event.nearestAttackableTarget(1, Player, 20, true, false, mob => true, mob.boundingBox.inflate(followRange, 25, followRange))
})
Move Control FlyingMoveControl(entity, 20, true) for smooth airborne steering.
Navigation Flying path navigation with floating enabled and door-passing allowed.
Attributes Sets flying_speed and movement_speed for responsive flight.
Goals Random flying wander plus a basic melee attack loop.
Targeting Targets the nearest player using the entity's follow range as a search radius.
Damage Immunity Ignores fall damage via isInvulnerableTo.

Clone this wiki locally