[KJS6] Some scripts compile [KJS] Kubejs Minecraft Game

This tutorial is set by the author to use the CC By-NC-SA protocol.

Because the KJS 6 deletes all WrapperClass, writing a script for KJS 6 may require a MC to compile environment.

If you want to add your own tutorial, please leave a message or email color in the lower message below.

Transhjs

Author: colorxu2020

Role: an incomplete KJS version of scavenge (Fabric theory available) Jei support is being written

Agree

Support version: KJS6

Run location: server script

Code:

 // Priority: 0

// Copyright © 2023 colorxu2020

// This program is free software: You can be distributed again/or according to the GNU loose general public license published by the Freedom Software Foundation, whether it is the version 3 license, or (according to your decision) any future versionIt will be all right.

// Publish this program to hope that it can be useful, but it is not guaranteed; it is not guaranteed to even sell and meet a specific purpose.Please refer to the GNU loose and general public license to understand the details.

// You should get a copy of the GNU loose common public license with the program.If not, please see <

// This program is freer Software: You can redistribute it and/or model it under the terms of the gnu leser general publicense as public E software foundation, Either Version 3 of the License, or (at your option) Any LaterVersion.

// This program is distingributed in the hope that it will be usedful, but without any warranty; Without even the impolical of merchantability or Fit NESS for a PARTICULAR PURPOSE. See the gnu lesser general public lifeings for more details.

// You Should have received a Copy of the gnu lesser general public lifense along with this program. If not, see .cons t itemstack = java.loadclass ("net.minecraft.wormd.item.Itemstack ");

const registry = java.loadclass ("net.minecraft.core.regization");

Const resourceLocation = java.loadclass ("net.minecraft.Resources.ResourceLocation");

const interactionhand = java.loadClass ("net.minecraft.World.Interactionhand")

const gives = new map ();

const limits = new map ();

const toolreq ​​= new map ();

var init = false;

var init_callback = [];

var init = function () {{)

Console.log ('trashjs loading');

Inited = true;

// Useing Example

Init_callback.Foreach ((k) => k (gives, limits, toolreq));

}

var add_init_callback = function (func) {

Init_callback.push (func);

}

global.trashjs = add_init_callback;

var Gettoolreq ​​= Function (IDN) {

If (! Toolreq.has (IDN)) Return itemstack.empty;

Return itemStack

}

Blockevents.richtclicked (event => {{

If (! Inited) init (); // Delay initialization has ensured that the expansion has been initialized

If (event.gethand ()!! = Interactionhand.main_hand) Return;

Var IDN = String

If (event.getItem ()! = Gettoolreq ​​(IDN)) Return; if (! GIES.HAS (IDN)) Return;

Var Entity = Event.getBlock (). Getentity ();

If (entity! = Null) {

Var data = Entity.getpersisistentdata ();

Data.putInt ("State", Data.getint ("State")+1);

} Else {

If (Limits.get (IDN)! =-1) Console.log ('Trashjs Error: Limit NEQ to-1 But block is not block entity.')

}

Gives.get (IDN). Foreach ((info, idn, mp) => {{{

If (math.random ()

Event.Getentity (). Getinventory (). Add (itemstack (registry.item.get (resourceLocation (IDN)), info [1]));));));)); info [1])));));)); info [1])));););););););)); info [1]))));););););)); info [1])))););

}

})

If (Limits.get (IDN)! =-1 && Data.getIntint ("State")> = Limits.get (IDN)) {

Event.getBlock (). GetLevel (). Removeblock (event.getBlock (). Getpos (), false);

}

});

Explanation of the core part by line:

 if (event.gethand ()! = Interactionhand.main_hand) Return; 

If it is not an event generated by the master, return directly

 var IDN = String (registry.block.getkey (event.getBlock (). GetBlockState (). GetBlock ()).

Get the block ID of the target block through the magical Coremodding

if (event.getItem ()! = Gettoolreq ​​(idn)) Return;

Checking tool requirements (GettoolREQ builds itEMSTACK through ToolReq)

 if (! Gives.has (IDN)) Return; 

Without registering this item, exit

 var entity = event.getBlock (). Getentity (); 

Get block entity

 if (entity! = Null) {

Var data = Entity.getpersisistentdata ();

Data.putInt ("State", Data.getint ("State")+1);

} Else {

If (Limits.get (IDN)! =-1) Console.log ('Trashjs Error: Limit NEQ to-1 But block is not block entity.')

}

If the target block is indeed a block entity, record the number of right -click (used to implement the number of clicks).

 gives.get (IDN). Foreach ((info, idn, mp) => {{

If (math.random ()

Event.Getentity (). Getinventory (). Add (itemstack (registry.item.get (resourceLocation (IDN)), info [1]));));));)); info [1])));));)); info [1])));););););););)); info [1]))));););););)); info [1])))););

}

})

All the drops that may be produced in this block. If you are lucky enough, add items to the item bar (and magical Coremodding).

 if (limits.get (idn)! =-1 && data.getint ("state")> = limits.get (idn)) {

Event.getBlock (). GetLevel (). Removeblock (event.getBlock (). Getpos (), false);

}

If you set the number of clicks and reaches it, remove this block.

API usage

Below is a fixed code high imitation KJS built -in

 Global.trashjs ((GIVES, Limits, Toolreq) => {

// Your code there

});

For example, if you want to register with a wooden sword right -click soil, there is a 20% probability to get saplings. You can pay attention: The anonymous function you register here will be called when you first right -click after entering the archive.

 Global.trashjs ((GIVES, Limits, Toolreq) => {

Gives.Set ('Minecraft: DIRT', New Map ()); // Register, fixed format: gives.set

gives.get ('Minecraft: DIRT'). Set ('oak_sapling', [0.05,1]); // Add drop fixed format: gives.get ()., ])

Limits.Set ('Minecraft: DIRT', -1); // Settings can right-click the unlimited fixation format: limits.set

ToolReq.Set ('Minecraft: DIRT', 'Minecraft: Wooden_sword'); // Setting requires a wooden sword fixed format toolreq.set (, )

});

Utiljs

Author: colorxu2020

Role: Perfect the practical methods of some old KJS to KJ6.

Agree

Support version: KJS6

Run position: start script

 // Copyright © 2023 Colinxu2020

// This program is free software: You can be distributed again/or according to the GNU loose general public license published by the Freedom Software Foundation, whether it is the version 3 license, or (according to your decision) any future versionIt will be all right.

// Publish this program to hope that it can be useful, but it is not guaranteed; it is not guaranteed to even sell and meet a specific purpose.Please refer to the GNU loose and general public license to understand the details.

// You should get a copy of the GNU loose common public license with the program.If not, please see .

// This program is freer Software: You can redistribute it and/or model it under the terms of the gnu leser general publicense as public E software foundation, Either Version 3 of the License, or (at your option) Any LaterVersion.// this program is distributed in the hope that it will be usedful, but without any warranty; OR FITNESS For A PARECULAR PURPOSE. See the gnu lesser general public life design for more details.

// You Should have received a Copy of the GNU LESSERAL PUBLIC LICENSE ALONG With T

var server_cache = undefined;

global.server = function (LV) {

If (lv == UNDEFINED) {

Return null;

}

If (server_cache! = Undefined) Return server_cache;

If (LV.ANYMOUS_PLAYER_PROFILE! = Undefined) {

Server_cache = lv;

Return server_cache;

}

If (LV.GetLevel! = Undefined) {

Lv = lv.getlevel ();

}

If (lv.getserver == Undefined) {

Return null;

}

Server_cache = lv.getserver ();

Return server_cache;

}

global.runcommand = Function (LV, CMD) {

If (cmd == undefined) cmd = lv, lv = undefined;

Var server = global.server (LV);

If (server == null) Return null;

Return server.getCommands (). Performcommand (server.createcommandsourceStack (), cmd);

}

global.runcommandsilent = Function (LV, CMD) {{

If (cmd == undefined) cmd = lv, lv = undefined;

Var server = global.server (LV);

If (server == null) Return null;

Return Server.getCommands (). Performcommand (server.createcommandsourceStack (). Withsuppressetoutput (), cmd); CMD); CMD);

}

API usage:

Get the server:

 global.server (event); // Check the server through the event

global.server (level); // Check the server through the world

Execution instruction:

 Global.runcommand (server_or_level_or_event, Command) 

Execute instructions (no display):

 global.runcommandsilent (server_or_level_or_event, Command)