Custom Items¶
原文:[Custom Items]
提示 自定义物品事件是启动事件。
自定义物品在启动脚本中创建。如果不重启游戏,它们无法被重载。该事件不可取消。
// Listen to item registry event
StartupEvents.registry('item', e => {
// The texture for this item has to be placed in kubejs/assets/kubejs/textures/item/test_item.png
// If you want a custom item model, you can create one in Blockbench and put it in kubejs/assets/kubejs/models/item/test_item.json
e.create('test_item')
// If you want to specify a different texture location you can do that too, like this:
e.create('test_item_1').texture('mobbo:item/lava') // This texture would be located at kubejs/assets/mobbo/textures/item/lava.png
// You can chain builder methods as much as you like
e.create('test_item_2').maxStackSize(16).glow(true)
// You can specify item type as 2nd argument in create(), some types have different available methods
e.create('custom_sword', 'sword').tier('diamond').attackDamageBaseline(10.0)
})
可用的物品类型:
- basic(这是默认类型)
- sword
- pickaxe
- axe
-
shovel
-
shears
- hoe
- helmet
- chestplate
- leggings
- boots
物品构建器支持的其他方法:[你可以在 create() 之后链式调用这些方法]
maxStackSize(size)displayName(name)unstackable()maxDamage(damage)这是物品的耐久度,不是实际武器伤害。burnTime(ticks)containerItem(item_id)rarity('rarity')tool(type, level)glow(true/false)tooltip(text...)group('group_id')color(index, colorHex)texture(customTextureLocation)parentModel(customParentModelLocation)food(foodBuilder => ...)完整语法见下文
使用工具类型('sword'、'pickaxe'、'axe'、'shovel' 或 'hoe')时可用的方法:
tier('toolTier')modifyTier(tier => ...)语法与自定义工具品质相同,参见「自定义品质」(Custom Tiers)attackDamageBaseline(damage)只有在创建自定义武器(如长矛、战斧等)时才需要修改此值attackDamageBonus(damage)speedBaseline(speed)与 attackDamageBaseline 相同,仅自定义武器类型时修改speed(speed)
默认可用的工具品质:
- wood
- stone
- iron
- gold
- diamond
- netherite
使用盔甲类型('helmet'、'chestplate'、'leggings' 或 'boots')时可用的方法:
tier('armorTier')modifyTier(tier => ...)语法与自定义盔甲品质相同,参见「自定义品质」(Custom Tiers)
默认可用的盔甲品质:
- leather
- chainmail
- iron
- gold
- diamond
- turtle
- netherite
原版分组/创造模式物品栏 ID:
- search
- buildingBlocks
- decorations
- redstone
- transportation
- misc
- food
- tools
- combat
- brewing
自定义食物¶
StartupEvents.registry('item', event => {
event.create('magic_steak').food(food => {
food
.hunger(6)
.saturation(6)//This value does not directly translate to saturation points gained
//The real value can be assumed to be:
//min(hunger * saturation * 2 + saturation, foodAmountAfterEating)
.effect('speed', 600, 0, 1)
.removeEffect('poison')
.alwaysEdible()//Like golden apples
.fastToEat()//Like dried kelp
.meat()//Dogs are willing to eat it
.eaten(ctx => {//runs code upon consumption
ctx.player.tell(Text.gold('Yummy Yummy!'))
//If you want to modify this code then you need to restart the game.
//However, if you make this code call a global startup function
//and place the function *outside* of an event handler
//then you may use the command:
// /kubejs reload startup_scripts
//to reload the function instantly.
//See example below
})
})
event.create('magicer_steak').unstackable().food(food => {
food
.hunger(7)
.saturation(7)
// This references the function below instead of having code directly, so it is reloadable!
.eaten(ctx => global.myAwesomeReloadableFunction(ctx))
})
})
global.myAwesomeReloadableFunction = ctx => {
ctx.player.tell('Hello there!')
ctx.player.tell(Text.of('Change me then reload with ').append(Text.red('/kubejs reload startup_scripts')).append(' to see your changes!'))
}