Skip to content

1.19.2 Types

LLytho edited this page Apr 12, 2023 · 1 revision

Enums

Equipment Slots

EquipmentSlot.MAINHAND
EquipmentSlot.OFFHAND
EquipmentSlot.FEET
EquipmentSlot.LEGS
EquipmentSlot.CHEST
EquipmentSlot.HEAD

Loot Types

LootType.UNKNOWN
LootType.BLOCK
LootType.ENTITY
LootType.CHEST
LootType.FISHING
LootType.GIFT

LootContextJS

Holds information for the current loot drop. Is mostly used for .apply().

getType()

Returns the LootType.

getPosition()

getEntity()

Returns an EntityJS or null if no entity exists for the context.

getKillerEntity()

Returns an EntityJS for the killer or null if no entity exists for the context.

getPlayer()

Returns a PlayerJS or null if no player exists for the context. An example of null would be when a Skeleton shoots a Creeper.

getDamageSource()

Returns a DamageSourceJS or null if no source exists.

getTool()

Returns an ItemStackJS for the tool. If no tool exists in the context, it will return an empty item.

getDestroyedBlock()

Returns a BlockContainerJS for block loot. Will be null for every other loot type.

isExploded()

Returns true if the loot drop happens by an explosion.

getExplosionRadius()

Returns the explosion radius. If isExploded() returns false, the radius is 0.

getLevel()

Returns the LevelJS.

getServer()

Returns the ServerJS.

getLuck()

getLooting()

lootSize()

addLoot(item)

removeLoot(ItemFilter)

findLoot(ItemFilter)

hasLoot(ItemFilter)

forEachLoot(callback)

Iterates over each item and calls the given callback for it.

// callback example
const callback = (item) => {
    console.log(item);
};

EntityPredicateBuilderJS

anyType(...types)

Entity tags can also be passed when using # as a prefix. Example: #skeletons.

isOnFire(flag)

isCrouching(flag)

isSprinting(flag)

isSwimming(flag)

isBaby(flag)

isInWater(flag)

isUnderWater(flag)

isMonster(flag)

isCreature(flag)

isOnGround(flag)

isUndeadMob(flag)

isArthropodMob(flag)

isIllegarMob(flag)

isWaterMob(flag)

hasEffect(effect, amplifier) & hasEffect(effect)

nbt(json)

matchMount(callback)

Matching the mount for the current entity. LootJS provides an EntityPredicateBuilderJS for the callback.

LootJS.modifiers((event) => {
    event
        .addLootTypeModifier([LootType.ENTITY])
        .matchEntity((entity) => {
            entity.anyType("#skeletons");
            entity.matchMount((mount) => {
                mount.anyType("minecraft:spider");
            });
        })
        .addLoot("minecraft:magma_cream");
});

This example shows a Skeleton riding a Spider, also known as a spider jockey.

matchTargetedEntity(callback)

Matching the targeted entity for the current entity. LootJS provides a EntityPredicateBuilderJS for the callback.

matchSlot(slot, ItemFilter)

Returns true if the slot contains the specified ItemFilter.

DamageSourcePredicateBuilderJS

anyType(...types)

Returns true if at least one type matches. Possible types are: "inFire", "lightningBolt", "onFire", "lava", "hotFloor", "inWall", "cramming", "drown", "starve", "cactus", "fall", "flyIntoWall", "outOfWorld", "generic", "magic", "wither", "anvil", "fallingBlock", "dragonBreath", "dryout", "sweetBerryBush" and there might be more types added by other mods.

isProjectile(flag)

isExplosion(flag)

doesBypassArmor(flag)

doesBypassInvulnerability(flag)

doesBypassMagic(flag)

isFire(flag)

isMagic(flag)

isLightning(flag)

matchDirectEntity(callback)

Matching the direct entity. LootJS provides a EntityPredicateBuilderJS for the callback.

matchSourceEntity(callback)

Matching the source entity. LootJS provides a EntityPredicateBuilderJS for the callback.

ItemFilters

ItemFilters can be used as filters for different functions in LootJS. Though everywhere where ItemFilter is needed, you can also use the KubeJS methods Item.of() and Ingredient.of().

ItemFilter additionally supports these quick filters:

  • ItemFilter.ALWAYS_FALSE
  • ItemFilter.ALWAYS_TRUE
  • ItemFilter.SWORD
  • ItemFilter.PICKAXE
  • ItemFilter.AXE
  • ItemFilter.SHOVEL
  • ItemFilter.HOE
  • ItemFilter.TOOL
  • ItemFilter.POTION;
  • ItemFilter.HAS_TIER;
  • ItemFilter.PROJECTILE_WEAPON
  • ItemFilter.ARMOR;
  • ItemFilter.WEAPON;
    • Matches all swords, tools, trident and projectile weapons
  • ItemFilter.HEAD_ARMOR
  • ItemFilter.CHEST_ARMOR
  • ItemFilter.LEGS_ARMOR
  • ItemFilter.FEET_ARMOR
  • ItemFilter.FOOD
  • ItemFilter.DAMAGEABLE
  • ItemFilter.DAMAGED
  • ItemFilter.ENCHANTABLE
  • ItemFilter.ENCHANTED
  • ItemFilter.BLOCK
    • Matches if the item can be placed as block
  • ItemFilter.hasEnchantment(enchantment, minLevel, maxLevel) & ItemFilter.hasEnchantment(enchantment)
    • Check if an item has an enchantment

On Forge only you can also use:

  • ForgeItemFilter.canPerformAnyAction(...action)
  • ForgeItemFilter.canPerformAction(...action)
    • Existing default actions on Forge: "axe_dig", "pickaxe_dig", "shovel_dig", "hoe_dig", "sword_dig", "shears_dig", "axe_strip", "axe_scrape", "axe_wax_off", "shovel_flatten", "sword_sweep", "shears_harvest", "shears_carve", "shears_disarm", "till", "shield_block", "fishing_rod_cast". Mods can add their own actions.

NumberProvider

NumberProvider is a vanilla object which gets type wrapped by KubeJS. If a function takes a number provider, you can pass a simple number to use a constant value, an array with a min and a max value [min, max] -> [3, 10] or if you want to have a binomial distribution, you can use { n: a, p: b} -> { n: 3, p: 0.5 }.