### JSON Casting Table Recipe Example Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/recipesschemaadded This is an example of a casting table recipe in JSON format for the `createmetallurgy` mod. ```json { "type": "createmetallurgy:casting_in_table", "ingredients": [ { "item": "createmetallurgy:graphite_plate_mold" }, { "fluid": "createmetallurgy:molten_brass", "amount": 90 } ], "processingTime": 80, "mold_consumed": false, "result": { "item": "create:brass_sheet" } } ``` -------------------------------- ### Querying Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/playernotify Use this GET request to query the documentation with a specific question. The response will include an answer and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/playernotify.md?ask= ``` -------------------------------- ### Query Documentation with HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/delightjs To get more information not present on the page, perform an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/delightjs.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/facing Perform an HTTP GET request on a page URL with the 'ask' query parameter to dynamically query documentation. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/facing.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/createsifting Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/createsifting.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/morejs-1 To get more information not present on the page, perform an HTTP GET request to the current URL with the 'ask' query parameter. The question should be specific and in natural language. The response will include a direct answer and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/morejs-1.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/entityjs/allevent To get more information not present on the page, make an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/entityjs/allevent.md?ask= ``` -------------------------------- ### Perform HTTP GET Request with Query Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/createjs Use this method to query the documentation dynamically. The question should be specific and self-contained. The response will include a direct answer and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/createjs.md?ask= ``` -------------------------------- ### Querying Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/lootjs To get more information not present on the page, make an HTTP GET request to the current page URL with the `ask` query parameter. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/lootjs.md?ask= ``` -------------------------------- ### Example of Combined Input Filters Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/basicsyntax-deleteandmodify This example demonstrates using combined input filters to match recipes that require multiple specific input items. ```javascript {{input : 'stone'},{input : 'redstone'},{input : 'grass'}} ``` -------------------------------- ### KubeJS Recipe Event Example Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/probejs Example of using ServerEvents.recipes for defining crafting recipes. ProbeJS provides autocompletion for 'ServerEvents' and its methods. ```javascript ServerEvents.recipes.add('kubejs:example_recipe', { pattern: ['xxx', 'x x', 'xxx'], key: { 'x': { 'item': 'minecraft:iron_ingot' } }, result: 'kubejs:example_item' }); ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/sceneworldfunction To get more information not directly on the page, perform an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and self-contained. This mechanism is useful for clarification, additional context, or retrieving related documentation. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/sceneworldfunction.md?ask= ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/enchantregistry Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. The question should be specific and in natural language. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/enchantregistry.md?ask= ``` -------------------------------- ### Querying Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/guan-yu-fang-kuai To get more information not present on the page, perform an HTTP GET request with the 'ask' query parameter. The question should be specific and in natural language. The response will contain an answer and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/guan-yu-fang-kuai.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/pondericons To get additional information not directly available on a page, perform an HTTP GET request to the page URL with the 'ask' query parameter. The question should be specific and in natural language. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/internal/pondericons.md?ask= ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/paint Use this method to ask questions about the documentation when information is not directly present. The response includes answers and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/paint.md?ask= ``` -------------------------------- ### Rarity Level Examples Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/digression/rarity Examples of how to reference different rarity levels in KubeJS. These correspond to in-game colors and are used to influence item name display. ```javascript $Rarity.COMMON ``` ```javascript $Rarity.UNCOMMON ``` ```javascript $Rarity.RARE ``` ```javascript $Rarity.EPIC ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/arsnouveaujs Use this method to ask questions about the documentation when information is not directly available. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/arsnouveaujs.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/jeijs To get more information not present on the page, perform an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and in natural language. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/jeijs.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/advancementjs-jin-du Perform an HTTP GET request to the current page URL with the `ask` query parameter to dynamically query the documentation. Use this when the answer is not explicitly present, for clarification, or to retrieve related sections. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/advancementjs-jin-du.md?ask= ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/botanypotsjs To get additional information not directly available on the page, perform an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and in natural language. This mechanism is useful for clarifications or retrieving related documentation sections. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/botanypotsjs.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/resources/sounds Perform an HTTP GET request to query the documentation dynamically. Use the 'ask' query parameter with a specific, self-contained question in natural language. The response will include a direct answer and relevant excerpts. ```HTTP GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/resources/sounds.md?ask= ``` -------------------------------- ### Query Documentation with 'ask' Parameter Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/jin-jie-nei-rong/scene To get additional information not directly present on the page, perform an HTTP GET request on the current page URL with the 'ask' query parameter. The question should be specific and in natural language. The response will contain a direct answer and relevant excerpts. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/jin-jie-nei-rong/scene.md?ask= ``` -------------------------------- ### Configuring Advanced Food Properties Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/itemtype/food This example showcases setting multiple food properties for an item, including hunger restoration, saturation, marking it as meat, making it always edible, and enabling fast consumption. ```javascript event.create("meng:my_food4") .food(foodBuilder=>{ foodBuilder.hunger(10) //设置恢复5个“鸡腿” foodBuilder.saturation(0.5) // 饱和度设置为10*0.5 = 5 foodBuilder.meat() // 设置食物属性为肉,可以被狗食用 foodBuilder.alwaysEdible() //设置为无需消耗饱食度即可使用 foodBuilder.fastToEat() //设置该食物为快速食用类 }) ``` -------------------------------- ### Perform HTTP GET Request to Query Documentation Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/worldgen Use this method to dynamically query documentation when information is not directly available. The question should be specific and self-contained. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/worldgen.md?ask= ``` -------------------------------- ### Query BotaniaJS Documentation Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/botaniajs To get more information not present on this page, you can query the documentation dynamically. Perform an HTTP GET request to the current page URL with the 'ask' query parameter followed by your question. ```http GET https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/botaniajs.md?ask= ``` -------------------------------- ### Example Scene with Base Plate and Idle Time Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/ponder Combines showing the base plate with an idle wait. It's recommended to have at least a one-second pause after displaying the base plate. ```javascript Ponder.registry(event => { event .create("kubejs:submarine_core") .scene("kubejs:submarine", "潜水艇", "kubejs:submarine", (scene, utils) => { // 显示底盘, 同时等待 20 Tick scene.showBasePlate(); scene.idle(20); }); }); ``` -------------------------------- ### Logging Player Type in ProbeJS Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/probejs This example logs the actual type of the player object received in an event to demonstrate potential discrepancies with ProbeJS's inferred types. ```javascript ItemEvents.firstLeftClicked(event=>{ console.log(event.player); }) ``` -------------------------------- ### Keyframe Creation Examples Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/ponder Demonstrates how consecutive keyframe calls work. Two immediate `addKeyframe()` calls result in a single keyframe. Using `addKeyframe()` followed by `addLazyKeyframe()` creates two keyframes with a 5-tick interval. ```javascript // 连续2个 addKeyframe 只会创造一个关键帧 scene.addKeyframe(); scene.addKeyframe(); // 如此则会创造两个关键帧, 其间隔 5 Tick scene.addKeyframe(); scene.addLazyKeyframe(); ``` -------------------------------- ### AoA3 Infusion Altar Recipe Example Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/custom This JSON structure represents a recipe for the AoA3 infusion altar. It defines the ingredients, input item, and the resulting output item. This format is used as a reference for creating custom recipes. ```json { "type": "aoa3:infusion", "ingredients": [ { "item": "aoa3:padded_cloth" }, { "item": "aoa3:padded_cloth" }, { "item": "aoa3:armour_plating" }, { "item": "aoa3:rainbow_druse" }, { "item": "aoa3:rainbow_druse" }, { "item": "aoa3:green_druse" }, { "item": "aoa3:blue_druse" } ], "input": { "item": "aoa3:helmet_frame" }, "result": { "item": "aoa3:crystallis_helmet" } } ``` -------------------------------- ### Fluid Registration with Textures and Tags Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/liquidregistry A more advanced fluid registration example that includes setting custom still and flowing textures, defining bucket colors, and applying tags. This approach uses a loop for multiple fluid definitions. ```javascript StartupEvents.registry("fluid", (event) => { // ModID声明如果选择不更改ModID(默认即"kubejs")直接把ModID这个变量取消 const MODID = "meng:" // 路径常量 const PATH = "block/fluid/" /* * 定义流体 * 在添加下一种流体时要记得在[]后加上逗号 * 并且一定要严格按照格式进行 * [流体id, 颜色] */ let fluidRegisters = [ ["example_fluid", 0x808080], ] fluidRegisters.forEach(([name, color]) => { event.create(MODID + name) // 声明id .thickTexture(color) // 流体颜色 .bucketColor(color) // 桶内流体颜色 .flowingTexture(MODID + PATH + "flowing") // 读取本地流体贴图文件,可在(/Code/This/kubejs/assets/meng/textures/block/fluid)下载(.mcmeta文件也要一起下载!) .stillTexture(MODID + PATH + "still") // 读取本地流体贴图文件,可在(/Code/This/kubejs/assets/meng/textures/block/fluid)下载(.mcmeta文件也要一起下载!) .tag(MODID + "fluid") // 添加流体tag(可选) }) }) ``` -------------------------------- ### Register Server Sign-in Command Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsprojects/signin Registers a '/qd' command to handle player sign-ins. It reads player data from a JSON file, updates sign-in status, and writes changes back. Requires a 'meng/qd.json' file to exist. ```javascript ServerEvents.commandRegistry(event =>{ const { commands: Commands, arguments: Arguments } = event event.register( Commands.literal("qd").executes(value =>{ let username = value.source.getPlayer().username let qdJson = JsonIO.readJson("./meng/qd.json").getAsJsonObject() let time = qdJson.get("time").getAsString() let timeF = qdJson.get("timeF").getAsString() let players = qdJson.get("players").getAsJsonArray() let i = 0 for (let index = 0; index < players.size(); index++) { let player = players.get(index).getAsJsonObject() let playerName = player.get("name").getAsString() if (playerName == username){ let endQdTime = player.get("endQdTime").getAsString() if (timeCompare(endQdTime)){ let qdDay = player.get("qdDay").getAsNumber() let newQdDay = qdDay + 1 player.addProperty("qdDay",newQdDay) player.addProperty("endQdTime",new Date().getTime().toString()) let strDay = newQdDay.toString().split(".")[0] Utils.server.tell("玩家 " + username + "在" + timeF + "签到成功,已经成功签到 " + strDay + "天") }else{ value.source.getPlayer().tell("你已经在今天签到过了,无需重复签到") } i = 1 break } } if(i == 0){ players["add(com.google.gson.JsonElement)"]({name:username,qdDay:"1.0",endQdTime:new Date().getTime().toString()}) Utils.server.tell("玩家 " + username + "在" + timeF + "签到成功,已经成功签到 1 天" ) } JsonIO.write("./meng/qd.json",qdJson) return 1 }) ) }) function getTime(str) { let currentTime = new Date(Number(str)) return currentTime.getFullYear() + "年" + (currentTime.getMonth() + 1) + "月" + currentTime.getDate() + "日" } function timeCompare(str){ let oldTime = new Date(Number(str)) let newTime = new Date() return oldTime.getFullYear() < newTime.getFullYear() || oldTime.getMonth() < newTime.getMonth() || oldTime.getDate() < newTime.getDate() } ``` -------------------------------- ### Registering Basic Tool Items Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/itemtype/tools Use StartupEvents.registry to register new tool items with their respective types like axe, hoe, pickaxe, shovel, and sword. ```javascript StartupEvents.registry("item", event => { // 斧子 event.create("meng:my_axe", "axe") // 锄头 event.create("meng:my_hoe", "hoe") // 镐子 event.create("meng:my_pickaxe", "pickaxe") // 铲子 event.create("meng:my_shovel", "shovel") // 剑 event.create("meng:my_sword", "sword") }) ``` -------------------------------- ### Registering Various Entity Types Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/entityjs/createentity Use StartupEvents.registry('entity_type', event => { ... }) to register different kinds of entities. The 'create' method takes the entity ID and its registration type. Supported types include 'entityjs:living', 'entityjs:mob', 'entityjs:animal', 'entityjs:tamable', 'entityjs:arrow', 'entityjs:projectile', 'entityjs:watercreature', 'entityjs:nonliving', and 'entityjs:geckolib_projectile'. ```javascript StartupEvents.registry('entity_type', event => { event.create('bat', 'entityjs:living') // 生物 event.create('sasuke', 'entityjs:mob') // 普通生物 event.create('wyrm', 'entityjs:animal') // 动物 event.create('dragon', 'entityjs:tamable') // 可驯服的生物 event.create('arrow', "entityjs:arrow") // 箭矢实体 event.create('projectile', "entityjs:projectile") // 投掷物吧 event.create('serpent', "entityjs:watercreature") // 水生 生物 event.create('dummy', "entityjs:nonliving") // 无生命的实体 event.create('projectile', "entityjs:geckolib_projectile") // Projectile builder with Geckolib modelling }) ``` -------------------------------- ### Associate PonderTag During Ponder Creation Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/tags Example demonstrating how to associate an existing PonderTag when creating a new Ponder scene. This is useful for organizing related Ponders. ```javascript Ponder.registry(event => { ↓ == ↑ event.create("minecraft:iron_block") .tag("kubejs:iron_golem") // 只能添加已有的 PonderTag, 添加复数 PonderTag 时无须 [ ], 用逗号隔开 PonderTag 即可 .scene("kubejs:iron_golem_1", "召唤铁傀儡", (scene, util) => { ↓ == ↑ }); }); ``` -------------------------------- ### Registering a Custom Crop Block Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/blocktype/cropreg Use StartupEvents.registry to create a new crop block. This includes defining its age stages, growth tick logic, bonemeal behavior, crop drop, survival conditions, and textures. The 'crop' method sets the item dropped upon harvest, and 'survive' defines environmental requirements for the crop to persist. ```javascript StartupEvents.registry("block", event => { event.create("test_crop", "crop") .age(3,cbb=>{ cbb.shape(0,0,0,0,16,2,16) cbb.shape(1,0,0,0,16,8,16) cbb.shape(2,0,0,0,16,12,16) cbb.shape(3,0,0,0,16,16,16) }) .growTick((blockstate, random) => { return 25; }) .bonemeal(rtc => { return rtc.random.nextInt(2) }) .crop(Item.of("stone")) .survive((blockstate, level, pos) => { // 判断区块是否被加载 if (level.isAreaLoaded(pos,1)){ // 判断是否能够看到天空 if(level.canSeeSky(pos)){ // 获取天空对作物的光照等级是否小于等于8 if (level.getBrightness("sky",pos) <= 8){ // 判断方块下面是否为下界合金块 if (level.getBlockState(pos.below()).is(Blocks.NETHERITE_BLOCK)){ return true } } }else{ // 判断方块产生的光照等级是否小于等于8 if (level.getBrightness("block",pos) <= 8){ if (level.getBlockState(pos.below()).is(Blocks.NETHERITE_BLOCK)){ return true } } } } return false }) .texture("0", "minecraft:block/wheat_stage0") .texture("1", "minecraft:block/wheat_stage3") .texture("2", "minecraft:block/wheat_stage5") .texture("3", "minecraft:block/wheat_stage7") .item(seed => seed.texture("minecraft:wheat_seeds")) }) ``` -------------------------------- ### Add a Lazy Keyframe After a Delay Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/ponder Creates a keyframe that will be added after a specified delay (in ticks) from the current point. For example, `scene.addLazyKeyframe()` adds a keyframe 5 ticks later. ```javascript // 在 5 Tick 后(当前Tick往后数的第六个Tick)创造一个关键帧 scene.addLazyKeyframe(); ``` -------------------------------- ### Place Block with Optional Particle Effect Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/ponder An alternative syntax for `setBlocks` where the boolean parameter controlling particle effects is placed before the block ID. This achieves the same result as the previous example. ```javascript > 值得一提的是, 后两个参数似乎是可以对调的, 即 > > scene.world.setBlocks(\[2, 1, 1], "create:encased_fan", false); = scene.world.setBlocks(\[2, 1, 1], false, "create:encased_fan"); ``` -------------------------------- ### Access and Iterate Global Variables in Startup Scripts Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/globalvariable Demonstrates accessing and iterating over global variables, such as arrays and objects, within startup scripts. Ensure global variables are loaded before accessing them. ```javascript global.testList.forEach(value=>{ global.testLog(value) }); console.log(global.testObj.h) console.log(global.testObj.b) ``` -------------------------------- ### OBJ模型文件示例 Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/digression/forgereadobjmodel 这是一个使用Blockbench创建的OBJ模型文件的示例。它包含了顶点、纹理坐标、法线以及面定义。mtllib指令指定了材质库文件。 ```obj # Made in Blockbench 4.8.3 mtllib qqqqoo.mtl o pyramid v 1 -2.220446049250313e-16 1 v 1 0.9999999999999998 1.0000000000000002 v 0 0.9999999999999998 1.0000000000000002 v 0 -2.220446049250313e-16 1 v 0.5 0.4999999999999999 0.5000000000000001 vt 0.25 0.75 vt 0.25 1 vt 0 1 vt 0 0.75 vt 0 0.479471875 vt 0.25 0.479471875 vt 0.125 0.65625 vt 0.1875 0.620096875 vt 0.4375 0.620096875 vt 0.3125 0.796875 vt 0.265625 0.823221875 vt 0.515625 0.823221875 vt 0.390625 1 vt 0.375 0.479471875 vt 0.625 0.479471875 vt 0.5 0.65625 vn 0 -2.220446049250313e-16 1 vn 0.7071067811865476 1.5700924586837752e-16 -0.7071067811865476 vn 0 0.7071067811865477 -0.7071067811865475 vn 0 -0.7071067811865475 -0.7071067811865477 vn -0.7071067811865476 1.5700924586837752e-16 -0.7071067811865476 usemtl m_c5b90dae-3a75-90c1-2280-8a6b9dc0fba2 f 1/1/1 2/2/1 3/3/1 4/4/1 f 2/5/2 1/6/2 5/7/2 f 3/8/3 2/9/3 5/10/3 f 1/11/4 4/12/4 5/13/4 f 4/14/5 3/15/5 5/16/5 ``` -------------------------------- ### Using InteractionHand Static Properties in KubeJS Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/probejs Example of using the static MAIN_HAND property from the InteractionHand enum to check if the event was triggered by the player's main hand. Requires Java.loadClass. ```javascript const $InteractionHand = Java.loadClass("net.minecraft.world.InteractionHand") ItemEvents.firstLeftClicked(event=>{ let hand = event.hand if ($InteractionHand.MAIN_HAND == hand){ // code } }) ``` -------------------------------- ### Override Villager Gift Loot Table Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/loottables/giftloottable Use this to change the loot table for a specific villager's gift. This example replaces the Armorer's gift loot table to only include diamonds. ```javascript ServerEvents.giftLootTables(e=>{ e.addGift("armorer_gift",l=>{ l.addPool(p=>{ p.addItem("diamond") }) }) }) ``` -------------------------------- ### Configuring Sounds.json for Music Discs (1.21.1+) Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/itemtype/musicdisc The structure for `sounds.json` remains similar for 1.21.1+, ensuring the game can locate and play the associated music files for jukeboxes. ```json { // 这里的 'meng:my_music' 指的是刚才在注册唱片音频那里的 `music_id` "music.my_music": { // 固定格式 "sounds": [ { // 创建声音的文件夹 也就是我们上面的 kubejs/assets/meng/sounds "name": "meng:my_music", // 以声音流输出,建议填写true(唱片) "stream": true } ] }, } ``` -------------------------------- ### Basic KubeJS Casting in Basin Recipe Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/recipesschemaadded A basic KubeJS script to create a casting in basin recipe using `createmetallurgy` schema, outputting a brick from lava and iron ingots. ```javascript ServerEvents.recipes((event) => { let { createmetallurgy } = event.recipes createmetallurgy.casting_in_basin("minecraft:brick", [ Fluid.of("minecraft:lava", 90), "#forge:ingots/iron" ]) }) ``` -------------------------------- ### Register Backpack Keybind (Client-Side) Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsprojects/backpack Sets up a client-side keybind for opening the backpack. This should not be included in server-side packs. ```javascript ClientEvents.init(() => { global.regKeyB = new $KeyMapping( "key.meng.packsack", $GLFWkey.GLFW_KEY_B, "key.keybinding.packsack" ); $KeyMappingRegistry.register(global.regKeyB); }); ``` -------------------------------- ### Add to Villager Gift Loot Table Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/loottables/giftloottable Use this to add items to an existing villager's gift loot table. This example modifies the Armorer's gift to also include a diamond in addition to its existing loot. ```javascript ServerEvents.giftLootTables(e=>{ e.modify("armorer_gift",l=>{ l.addPool(p=>{ p.addItem("diamond") }) }) }) ``` -------------------------------- ### Get Block Tag on Item Right Click Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsprojects/smallproject/blockitemgetblocktag This snippet handles the `firstRightClicked` event. It checks if the item being right-clicked is a block item. If it is, it retrieves the block's tags and logs their locations to the KubeJS server log. This is useful for identifying which block tags a specific item belongs to. ```javascript ItemEvents.firstRightClicked(event => { if (event.getItem().isBlock()){ /** * @type {Internal.BlockItem} */ let item = event.getItem().item let tagList = item.getBlock().defaultBlockState().getTags().toList(); for (const key of tagList) { // 会将内容打印到 /logs/kubejs/server.log 内 console.log(key.location()); } } }) ``` -------------------------------- ### Configuring Sounds.json for Music Discs Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/customs/itemtype/musicdisc Define how your custom music files are recognized by the game. This JSON file maps sound event IDs to actual audio files. ```json { // 注册声音id "music.my_music": { // 固定格式 "sounds": [ { // 创建声音的文件夹 也就是我们上面的 kubejs/assets/meng/sounds "name": "meng:my_music", // 以声音流输出,建议填写true(唱片) "stream": true } ] }, } ``` -------------------------------- ### Jukebox Record to Item Drop Script Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsprojects/jukeboxtoitem This script listens for right-clicks on a jukebox. If the jukebox is playing a record, it schedules a check after 3 seconds. If the record is still playing and has played for at least 2.8 seconds, it removes the record from the jukebox and drops a 'stone' item. This example uses KubeJS for Minecraft modding. ```javascript BlockEvents.rightClicked("jukebox", event => { let block = event.getBlock() // 判断右键唱片机后唱片机是否在播放 if (block.entityData.getBoolean("IsPlating")){ // 设置定时任务在3秒后进行判断 event.server.scheduleInTicks(20 * 3, () => { let newBlock = event.level.getBlock(block.pos) if (newBlock.id == 'minecraft:air') return let blockEntity = newBlock.getEntity() let blockEntityData = newBlock.getEntityData() // 判断物品是否为空气来进行判断是否在播放 // 也可以使用blockEntityData.getBoolean("IsPlating") 来判断 if (!blockEntity.getFirstItem().is("air")) { // 判断播放时长是否大于2.8 (尽可能的接近但是最好不要等于,怕出现其他意外) if ((blockEntityData.getInt("TickCount") - blockEntityData.getInt("RecordStartTick")) / 20 >= 2.8) { // 清除唱片机里面的物品 blockEntity.clearContent() // 在方块上面弹出一个新的物品 newBlock.popItemFromFace("stone", "up") } } }) } }) ``` -------------------------------- ### Modifying Item Tags Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/tags Demonstrates how to manipulate item tags. Use `event.remove()` to remove an item from a tag, `event.removeAll()` to remove all tags from an item, and `event.add()` to add an item to a tag. This example shows removing oak logs from the logs tag, removing all tags from planks, and adding bedrock to the logs tag. ```javascript ServerEvents.tags("item",event=>{ // 将橡木原木从原木的tag中去除 event.remove("minecraft:logs",['minecraft:oak_log']); // 删除所有木板的tag event.removeAll('minecraft:planks'); // 将基岩加入到原木的tag中 event.add("minecraft:logs",['minecraft:bedrock']); }) ``` -------------------------------- ### Shaped Recipe (JSON Syntax) Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/basicsyntax-add Use this for adding shaped crafting recipes with a 3x3 grid. Define output, ingredients, and placeholders. ```javascript ServerEvents.recipes(event => { event.shaped("3x minecraft:stone", [ 'DDD', ' ', 'W W' ], { D: 'minecraft:diamond', W: 'minecraft:white_wool' }); }); ``` -------------------------------- ### Complete KubeJS Casting in Basin Recipe Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsadvanced/recipesschemaadded A complete KubeJS script for a casting in basin recipe, including custom processing time and mold consumption settings. ```javascript ServerEvents.recipes((event) => { let { createmetallurgy } = event.recipes createmetallurgy.casting_in_basin("minecraft:brick", [ Fluid.of("minecraft:lava", 90), "#forge:ingots/iron" ]).processingTime(114).mold_consumed(true) }) ``` -------------------------------- ### Configure Base Plate with Offset and Size Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsaddon/ponderjs/ponder Configures a base plate for the Ponder scene. The parameters define the X and Z offset from the origin and the size of the n*n plate. Note that the built-in plate has a maximum size of 5x5. ```javascript // 在 { } 内使用这个函数, 将会生成 1 个 n * n, 西移 x 格, 北移 z 格的地板(开启开发者模式后便可查看各个方块的坐标及方位) // 其三个参数分别用于配置: X偏移, Z偏移以及地板大小(x < 0 即是东移, z 同理) // P.S 内建地板最多5x5, n>5时, 范围会出现, 但只会设置5x5的方块 scene.configureBasePlate(x, z, n); ``` -------------------------------- ### Smelting and Furnace Recipes Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/basicsyntax-add Add recipes for various furnace-type blocks like furnaces, smokers, blast furnaces, and campfires. Specify output, input, experience, and cook time. ```javascript ServerEvents.recipes(event => { //熔炉 event.smelting('minecraft:bell','minecraft:gold_ingot',1000,2000); //烟熏炉 event.smoking('minecraft:bell','minecraft:gold_ingot',1000,2000); //营火 event.campfireCooking('minecraft:bell','minecraft:gold_ingot',0,2000); //高炉 event.blasting('minecraft:bell','minecraft:gold_ingot',1000,2000); }); ``` -------------------------------- ### Dump Game Data with ProbeJS Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsbasic/probejs Run this command in-game to generate necessary files for VS Code code completion. Re-run after making changes to mods or configurations. ```plaintext /probejs dump ``` -------------------------------- ### Export All Recipes to JSON Files Source: https://gumeng.gitbook.io/kubejs-jiao-cheng-1.20.1/kubejsprojects/smallproject/recipesjsoninfile This script iterates over all registered recipes and writes each recipe's JSON data to a separate file in the './recipes/' directory. Ensure the 'recipes' folder exists in your game's file path before running to avoid errors. ```javascript ServerEvents.recipes(event=>{ event.forEachRecipe({},recipe=>{ JsonIO.write("./recipes/" + String(recipe.getId()).replace(/:|\|\\| | /g, "_") + ".json",recipe.json) }) }) ```