StartupEvents.
registry('entity_type', event => {
[Link]('sasuke', "entityjs:tamable")
/**
* One-Off values set at the startup of the game.
*/
.immuneTo("minecraft:stone", "minecraft:dirt")
.canSpawnFarFromPlayer(true)
.clientTrackingRange(20)
.mobCategory('monster')
.setRenderType("solid")
.sized(1, 1)
.modelSize(2, 3)
.updateInterval(3)
.defaultDeathPose(true)
.repositionEntityAfterLoad(true)
.isPersistenceRequired(true)
.isAlwaysExperienceDropper(true)
.setDeathSound("minecraft:[Link]")
.canJump(true)
.ambientSoundInterval(100)
.isPushable(true)
.canBreatheUnderwater(true)
.eatingSound("minecraft:[Link]")
.fallSounds("minecraft:[Link].small_fall",
"minecraft:[Link].large_fall")
.fireImmune(false)
.followLeashSpeed(1.5)
.setAmbientSound("minecraft:[Link]")
.mainArm("left")
.saves(true)
.setSoundVolume(0.5)
.setSummonable(true)
.setSwimSound("minecraft:[Link]")
.setSwimSplashSound("minecraft:[Link]")
.setWaterSlowDown(0.6)
.shouldDespawnInPeaceful(true)
.mountJumpingEnabled(true)
.tamableFood([
'minecraft:diamond',
[Link]("minecraft:bedrock")
])
.isFood([
'minecraft:diamond',
[Link]("minecraft:apple")
])
// .noEggItem() // Disables automatic egg item creation
//Customize egg item
.eggItem(item => {
[Link](0);
[Link](0);
})
.canFireProjectileWeapon([
'minecraft:bow',
'minecraft:crossbow'
])
.newGeoLayer(builder => {
// New render layers like what the exploding Creeper or the
Wither has
/*[Link](entity => {
return "kubejs:textures/entity/[Link]"
})*/
})
/**
* These methods below require a set return value, if the value does
not match the required result
* it will automatically default to the super method in the entity
builder and output an error in logs>kubejs>[Link].
*
* Remember all callback functions are also able to be live-edited with
global events!
*
* Example:
* [Link] = context => {
* if ([Link]()) return
* [Link]([Link]);
* }
*
* .onInteract(context => [Link](context)) // Reload this with
/kubejs reload startup_scripts
*/
.addAnimationController('exampleController', 1, event => {
if ([Link] > 0) {
[Link]('spawn');
} else {
[Link]('idle');
}
return true;
})
.setBreedOffspring(context => {
const { entity, mate, level } = context
// Use the context to return a ResourceLocation of an entity to
spawn when the entity mates
return 'minecraft:cow' //Some Resourcelocation representing the
entity to spawn.
})
.addPartEntity("head", 1, 1, builder => {
// Adds an additional hitbox to the entity with builder support
builder
.isPickable(true)
.onPartHurt(context => {
const { entity, part, source, amount } = context
// Custom logic for determining how the parts of the
entity should relay damage
// To the entity. For example, relay double the
damage to the entity when this hitbox is hit
[Link](source, amount * 2)
[Link]("source: " + source + " amount: " +
amount + " part name: " + [Link])
})
})
.aiStep(entity => {
// Custom logic to be executed during the living entity's AI step
// Access information about the entity
// Tick the previously registered part entity/hitbox to be 1
square y-offset to the entity
[Link]("head", 0, 1, 0)
})
.createNavigation(context => {
const { entity, level } = context
// Use the new EntityJSUtils binding to create different path
navigations
// Returning WallClimberNavigation here will allow the entity to
path-find up walls like spiders
return [Link](entity,
level) // Return some path navigation
})
.render(context => {
// Define core logic to render the entity (recommended to
use .scaleModelForRender instead)
if ([Link]()) {
return [Link](0.5, 0.5, 0.5); // Scale
down if the entity is a baby
}
return [Link]; // Otherwise, keep the default pose
stack
})
.scaleModelForRender(context => {
// Define logic to render the entity without changing core logic
such as hitbox rendering
const { entity, widthScale, heightScale, poseStack, model,
isReRender, partialTick, packedLight, packedOverlay } = context
if ([Link] > 0) {
[Link](0.5, 0.5, 0.5)
}
})
.getAttackBoundingBox(entity => {
// Custom logic to calculate the squared melee attack range based
on the provided mob.
return entity;
})
.jumpBoostPower(entity => {
//Sets the jump boost power for the entity when they have the
jump boost effect applied
//Mimic vanilla logic with resistance instead of jump boost
return [Link]("minecraft:resistance") ? (0.1 *
([Link]("minecraft:resistance").getAmplifier() + 1)) : 0.0;
})
.setBlockJumpFactor(entity => {
// Sets block jump factor returning a float value
if ([Link] > 2000) {
return 1.3; // Increase jump factor when the entity is old
enough
}
return 1; // Default jump factor
})
.setMaxFallDistance(entity => {
// Define custom logic to determine the maximum fall distance
before taking damage
// Use information about the LivingEntity provided by the context
if ([Link]()) {
return 1; // Reduced fall distance when entity is on fire
}
return 3; // Default fall distance
})
.animationResource(entity => {
// Return different animation resources based on the entity's
state
// Use information about the LivingEntity provided by the
context.
if ([Link] > 0) {
return // Return some animation path when entity is hurt
} else {
return "kubejs:animations/entity/[Link]"; //
Return Wyrm animation otherwise
}
})
.blockSpeedFactor(entity => {
// Define logic to calculate and return the block speed factor
for the entity
// Use information about the LivingEntity provided by the
context.
const age = [Link];
const maxAge = 5000; // Assuming the maximum age is 5000
// Custom logic to calculate block speed factor based on entity's
age
const factor = age < maxAge ? 1.0 : 0.5; // Reduce speed factor
for older entities
return factor;
})
.calculateFallDamage(context => {
// Define logic to calculate and return the fall damage for the
entity
// Use information about the CalculateFallDamageContext provided
by the context.
const fallHeight = [Link];
const damageMultiplier = [Link];
const entity = [Link];
// Custom logic to calculate fall damage based on fall height and
multiplier
const calculatedDamage = [Link](fallHeight *
damageMultiplier);
return calculatedDamage;
})
.canAddPassenger(context => {
// Define custom logic to determine if a passenger can be added
to the entity
// Use information about the PassengerEntityContext provided by
the context.
// For example, check if the entity is not already carrying too
many passengers.
const maxPassengers = 4; // Assuming a maximum of 4 passengers
return [Link]().size() < maxPassengers;
})
.isAlliedTo(context => {
const { entity, target } = context
return [Link] == 'minecraft:blaze'
})
.canAttack(context => {
// Define conditions to check if the entity can attack the
targetEntity
// Use information about the LivingEntity provided by the
context.
// For example, check if the targetEntity is not the same as the
entity itself.
return [Link] !== [Link];
})
.canAttackType(context => {
// Define conditions to check if the entity can attack the
specified entity type
// Use information about the EntityTypeEntityContext provided by
the context.
// For example, check if the entity type of the target matches a
specific type.
const targetType = [Link];
// Assuming we want the entity to attack only friendly mobs
return targetType;
})
.canBeAffected(context => {
// Define conditions to check if the entity can be affected by
the effect
// Use information about the OnEffectContext provided by the
context.
// For example, check if the entity is not already affected by a
specific effect.
const effect = [Link];
// Assuming we want the entity to be affected only if it doesn't
have the same effect already
return );
})
.canChangeDimensions(entity => {
// Define the conditions for the entity to be able to change
dimensions
// Use information about the LivingEntity provided by the
context.
// For example, allow dimension change only for entities with a
specific tag.
return [Link]("dimension_changer");
})
.canDisableShield(entity => {
// Define the conditions to check if the entity can disable its
shield
// Use information about the LivingEntity provided by the
context.
return [Link] == 'minecraft:diamond_sword'; //
Disable shield if the entity is wielding a diamond sword.
})
.canFireProjectileWeaponPredicate(context => {
// Custom logic to determine whether the entity can fire a
projectile weapon
// Access information about the entity and the projectile weapon
using the provided context.
return [Link] == 'minecraft:bow';
})
.canFreeze(entity => {
// Define conditions for the entity to be able to freeze
// For example, allow freezing only if the entity is in water.
return [Link];
})
.canHoldItem(context => {
// Custom logic to determine whether the entity can hold an item
based on the provided context.
// For example, allow holding an item only if the entity is not a
baby.
return ![Link]();
})
.canBreed(entity => {
// Custom logic to determine if the entity can breed
// Use information about the LivingEntity provided by the
context.
// For example, check if the entity has reached maturity.
const baby = [Link]();
// Assuming we want the entity to be able to breed only if it's
an adult
return baby;
})
.canMate(context => {
// Custom logic to determine if the entity can mate
// For example, allow mating only if both animals are in the same
biome.
let blockpos1 = [Link]
let blockpos2 = [Link]
return [Link]().getBiome(blockpos1) ===
[Link]().getBiome(blockpos2);
})
.canPickUpLoot(entity => {
// Custom logic to determine whether the entity can pick up loot
based on the provided mob.
// Allow loot pickup during nighttime.
return ![Link]().isDay(); // Only allow loot pickup
during nighttime
})
.canStandOnFluid(context => {
// Define conditions for the entity to be able to stand on a
fluid
// Use information about the EntityFluidStateContext provided by
the context.
// Allow standing on water.
let fluid = [Link]("minecraft:water").[Link]
return [Link] == fluid
})
.canTakeItem(context => {
// Define conditions for the entity to be able to take an item
// Use information about the EntityItemLevelContext provided by
the context.
// Allow taking items only if the living entity is not null and
the item stack is not empty.
return [Link] !== null && ![Link]();
})
.dampensVibrations(entity => {
// Determine whether the living entity dampens vibrations
// Return true if the entity dampens vibrations, false otherwise
// For example, return true if the entity has no gravity.
return [Link]();
})
.experienceReward(killedEntity => {
// Define logic to calculate and return the experience reward for
the killedEntity
// Use information about the LivingEntity provided by the
context.
// For example, return 5 times the armor cover percentage of the
entity.
const armorCoverPercentage = [Link] +
1;
return armorCoverPercentage * 5;
})
.hasLineOfSight(context => {
// Check if the target entity is within the same level
if ([Link]() !==
[Link]()) {
return false;
}
// Get the positions of the entities
// In 1.20.1+ this is Vec3d instead of Vec3
const entityPos = new Vec3d([Link](),
[Link](), [Link]());
const targetPos = new Vec3d([Link](),
[Link](), [Link]());
// Calculate the distance between the two entities
const distance = [Link](targetPos);
// Check if the target entity is within a reasonable range
if (distance > 128.0) {
return false;
}
// Allow the entity to "see through" blocks by not implimenting
ClipContext as done in LivingEntity Class.
return true;
})
.setHurtSound(context => {
// Custom logic to determine the hurt sound for the entity
// You can use information from the HurtContext to customize the
sound based on the context
const { entity, damageSource } = context;
// Determine the hurt sound based on the type of damage source
switch ([Link]()) {
case "fire":
return "minecraft:[Link]";
case "fall":
return "minecraft:[Link]";
case "drown":
return "minecraft:[Link]";
case "explosion":
return "minecraft:[Link]";
default:
return "minecraft:[Link]";
}
})
.invertedHealAndHarm(entity => {
//Used by undead mobs to invert potion effects such as Instant
Health & Instant Damage
const blockAboveHasSky = [Link];
return blockAboveHasSky; // Return true if the block below has
sky visibility
})
.isAffectedByFluids(entity => {
// Define logic to determine whether the entity is affected by
fluids
// For example, check if the entity is swimming or flying
return [Link]() || [Link]();
})
.isAffectedByPotions(entity => {
// Define conditions to check if the entity is affected by
potions
// For example, check if the entity has any active potion effects
return [Link]().size() > 0;
})
.isAttackable(entity => {
// Define conditions to check if the entity is attackable
// For example, check if the entity is not invulnerable
return ![Link]();
})
.isCurrentlyGlowing(entity => {
// Define the conditions to check if the entity is currently
glowing
// For example, check if the entity has a regeneration or glowing
effect applied
return [Link]("minecraft:regeneration") ||
[Link]("minecraft:glowing");
})
.isFlapping(entity => {
// Mimics the Ender Dragon's Flapping Behavior
// Define logic to determine whether the entity is currently
flapping
const flapTime = [Link]; // Current flap time
const oFlapTime = [Link]; // Previous flap time
// Calculate cosine values for the current and previous flap
times
const f = [Link](flapTime * 6.2831855);
const f1 = [Link](oFlapTime * 6.2831855);
// Check if the entity is flapping based on cosine values
return f1 <= -0.3 && f >= -0.3;
})
.tamableFoodPredicate(context => {
const { entity, item } = context
return [Link] == 'minecraft:carrot' // Return true if the
player's current itemstack will tame the mob.
})
.isFoodPredicate(context => {
// Custom logic to determine if the entity item stack is
considered as food.
// Access information about the item stack using the provided
context.
const itemStack = [Link]; // Get the item stack from the
context
// Example condition: Check if the item stack is edible
return [Link]();
})
.isFreezing(entity => {
// Define the conditions for the entity to start freezing
// Use information about the LivingEntity provided by the
context.
// Start freezing the entity if they're in the taiga biome and
can freeze.
return [Link]().getBiome([Link]) ==
'minecraft:taiga' && [Link]();
})
.isImmobile(entity => {
// Define logic to determine whether the entity is immobile
// Use information about the LivingEntity provided by the
context.
return [Link](); // Example: Entity is immobile if
sleeping
})
.isInvulnerableTo(context => {
// Define conditions for the entity to be invulnerable to the
specific type of damage
// Use information about the DamageContext provided by the
context.
// Example condition: Entity is invulnerable to magic damage
return [Link]() == 'magic';
})
.isSensitiveToWater(entity => {
// Define conditions to check if the entity is in a "Cold Ocean"
biome and sensitive to water
// Use information about the LivingEntity provided by the
context.
// Example condition: Check if the biome ID corresponds to a
"Cold Ocean" biome
return
[Link]().getBiome([Link]).is('minecraft:cold_ocean')
})
.isSleeping(entity => {
// Check if the entity has a sleeping position
// Use information about the LivingEntity provided by the
context.
//Mimics how vanilla does the isSleeping() method.
return [Link]().isPresent();
})
.mayInteract(context => {
// Define conditions for the entity to be allowed to interact
with the world
// Use information about the MayInteractContext provided by the
context.
return [Link]().contains('canInteractWithWorld')
})
.nextStep(entity => {
// Define custom logic to calculate the next step distance based
on the provided entity.
const movementSpeed = [Link](); // Get the
entity's movement speed
//If the entity is not an animal return default vanilla behavior
if (![Link]) return [Link] + 1;
const behaviorFactor = [Link]() ? 1.5 : 1; // Adjust
the step distance based on behavior
// Calculate the next step distance based on movement speed,
size, and behavior
const nextStepDistance = movementSpeed * behaviorFactor;
return nextStepDistance;
})
.onClimbable(entity => {
const blockBelow = [Link]; // Get the block below the
entity
// Check if the block below the entity is climbable (e.g., a
ladder, vine, or scaffold)
const isClimbableBlock =
[Link]('minecraft:my_climbeable_block_tag');
// Check if the entity is currently moving upwards (which might
indicate climbing)
const isMovingUpwards = [Link] > 0;
// Return true if the entity is on a climbable surface and moving
upwards
return isClimbableBlock && isMovingUpwards;
})
.removeWhenFarAway(context => {
// Get information from the context
const { distanceToClosestPlayer } = context;
// Return true if the entity is far away from the closest player
and should be removed
//Fine tune removal logic
return distanceToClosestPlayer > 64;
})
.scale(entity => {
// Define logic to calculate the custom scale for the entity
// For example, you can scale the entity based on its size or
other properties
return [Link]() ? 0.5 : 1;
})
.shouldDropExperience(entity => {
// Define conditions to check if the entity should drop
experience upon death
// Use information about the LivingEntity provided by the
context.
return [Link] == 'minecraft:grass_block'// Only
drop experience if the entity dies on grass
})
.shouldDropLoot(entity => {
// Define logic to determine whether the entity should drop loot
// Use information about the LivingEntity provided by the
context.
return ![Link](); //Only drop loot if they're an adult
})
.showVehicleHealth(entity => {
// Determine whether to show the vehicle health for the living
entity
// Return true to show the vehicle health, false otherwise
return ![Link](); //Only show vehicle's health to
the player if the vehicle is fall flying
})
.visibilityPercent(context => {
// Define logic to calculate and return the visibility percentage
for the targetEntity
// Use information about the Entity provided by the context.
// Our mob is less 'seen' by other mobs in the plains biome by
20%.
return [Link] > 0 ? 0.8 : 1
})
.walkTargetValue(context => {
const { levelReader, pos } = context; // Destructure context for
easier access
// Get the block state below the given position
const blockBelow = [Link]([Link]());
// Adjust walk target value based on the block below, is usually
Grass Block in Vanilla
return [Link](Blocks.AZALEA_LEAVES) ? 10 :
[Link](pos);
})
.canCollideWith(context => {
return true //Some Boolean value determining whether the entity
may collid with another
})
/**
* All methods below return void meaning they don't require a set
return value to function.
* These mostly are similar to KubeJS' normal events where you may do
things on certain events your entities call!
*/
.tick(entity => {
if ([Link] % 100 != 0) return
})
.lavaHurt(entity => {
// Heal the entity by 20 health points
[Link](20);
})
.doAutoAttackOnTouch(context => {
// Attack the target entity with a damage value of 1
[Link](1);
})
.ate(entity => {
// Log a message when the entity eats something
[Link](`${[Link]} just ate!`)
})
.dropCustomDeathLoot(context => {
// Drop custom loot (iron ingot) when the entity dies with a
looting multiplier of 2
if ([Link] == 2)
[Link]('minecraft:iron_ingot', 'up')
})
.eat(context => {
// Heal the entity when it eats something
[Link](20)
})
.lerpTo(context => {
const { x, y, z, yaw, pitch, entity, delta } = context;
// Set the entity's position directly to the target position if
the entity is freezing
if ([Link]()) [Link](x, y, z);
})
.onAddedToWorld(entity => {
// Teleport the entity slightly above its current position when
added to the world
let namespace = [Link]().[Link]
let path = [Link]().[Link]
[Link](`${namespace}:${path}`, entity.x, entity.y + 1,
entity.z, 1, 1)
})
.onBlockedByShield(context => {
const { entity, target } = context
// Log a message when the target is blocked by a shield
[Link](`${target} Get blocked!`)
})
.onClientRemoval(entity => {
// Log a message when the entity is removed on the client side
[Link](`${entity} was removed on the client`)
})
.onDeath(context => {
// Place a diamond ore block below the entity when it dies
[Link]('minecraft:diamond_ore')
})
.onDecreaseAirSupply(entity => {
if ([Link] % 20 != 0) return
// Log the entity's remaining air supply when it decreases
})
.onEffectAdded(context => {
// Log the description ID of an added effect
[Link]([Link])
})
.onEffectRemoved(context => {
// Log the description ID of a removed effect
[Link]([Link])
})
.onEnterCombat(entity => {
// Log a message when the entity enters combat
[Link](`${entity} just entered combat`)
})
.onEquipItem(context => {
// Log the ID of the item being equipped by the entity
if ([Link] % 100 != 0) return
[Link]([Link])
})
.onFlap(entity => {
// Place a gold ore block below the entity when it flaps
[Link]('minecraft:gold_ore')
})
.positionRider(context => {
const { entity, passenger, moveFunction } = context
// Position the entity with the moveFunction() method
})
.onHurt(context => {
// Log the amount of damage received by the entity
[Link]([Link])
})
.onIncreaseAirSupply(entity => {
})
.onItemPickup(context => {
// Log the ID of the item picked up by the entity
[Link]([Link])
})
.onLeaveCombat(entity => {
// Log a message when the entity leaves combat
[Link](`${entity} just left combat!`)
})
.onLivingFall(context => {
// Log a message when the entity falls
[Link](`${[Link]} just fell ${[Link]}
blocks!`)
})
.onLivingHeal(context => {
// Log a message when the entity heals
[Link](`${[Link]} just gained ${[Link]}
health!`)
})
.onLivingJump(entity => {
// Log a message when the entity jumps
[Link](`${entity} just jumped!`)
})
.onRemovedFromWorld(entity => {
// Log a message when the entity is removed from the world
[Link](`${entity} was just removed from the world!`)
})
.onSpawnChildFromBreeding(context => {
// Log a message when the entity breeds with another entity
[Link](`${[Link]} mated with ${[Link]}!
*blush*`)
})
.onSprint(entity => {
// Log a message when the entity starts sprinting
[Link](`${entity} is sprinting!`)
})
.onStartSleeping(context => {
// Log a message when the entity starts sleeping at a specific
position
[Link](`Sleeping at ${[Link]}`)
})
.onStopRiding(entity => {
// Drop a diamond above the entity when it stops riding
[Link]('minecraft:diamond', 'up')
})
.onStopSleeping(entity => {
// Log a message when the entity stops sleeping
[Link](`Stopped sleeping at ${[Link]}`)
})
.onTargetChanged(context => {
//Only firing every 100 ticks to reduce log spam.
if ([Link] % 100 != 0) return
// Log a message when the entity's target changes
if ([Link] == null) return
[Link](`${[Link]} is being targeted!`)
})
.playerTouch(context => {
// Attack the player when touched by the entity
[Link](1)
})
.rideTick(entity => {
// Log a message every 100 ticks if the entity is a vehicle
if ([Link] % 100 != 0) return
[Link]([Link]())
})
.thunderHit(context => {
// Heal the entity when struck by lightning
[Link](15)
})
.onTamed(entity => {
// Do stuff when the entity is tamed.
})
.tameOverride(context => {
const { entity, player } = context
// Mimic the vanilla way of setting the uuid when the entity is
tamed.
[Link]([Link]());
})
//Default vanilla implimentation of tickDeath removes the entity from
the world after 20 ticks
/*.tickDeath(entity => {
// Override the tickDeath method in the entity
})*/
.onInteract(context => [Link](context))
})
/**
*
* @param {[Link]$MobInteractContext} context
* @returns
*/
[Link] = context => {
if ([Link]()) return
[Link]([Link]);
}