your current location:首页 > news>KJS6#Basic Advanced Example [KJS] Kubejs Minecraft Game

KJS6#Basic Advanced Example [KJS] Kubejs Minecraft Game

2024-12-10 17:58:05|Myriagame |source:minecraft skins

This tutorial is set by the author's setting without permission.

Example version is forge 1.19.2;

It contains many basic format methods, and simply shows how to compound these methods.

The code environment uses VSC and Probejs by default.

Complete instance

*For reference learning, code logic is secondary, and sometimes it will save complicated loopholes.

Some brief description

Internet .ntity.persistentdata: Internet.com

It exists in the form of Kubejspersisistentdata: {...}. It belongs to part of the NBT, but NBT cannot freely add a new key value. When there is data storage demand, it can be operated in PersisteentData;Entity.persistentdata ['abc'] = 123, of course, it is recommended to use its own standard method (see the figure below, display part) to facilitate processing different types of values.

Internet.itemstack.getorcreatetag (): internahes

Unlike the internal.Itemstack.nbt: Internet :Compoundtag, the internal.Itemstack.nbt will get the NULL value when the NBT does not exist, and GetorCreatetag will try to add the default value {} to NBT items to NULL. At this time, even '/KJS Hand 'instructions are not aware of the changes of NBT, but the log (see the figure below) obviously can see that the NBT changes from NULL to {}, and although the torch in the game seems to be no different, it can no longer be with the normal.The torch stacks (common bugs in certain modules), so GetorCreateTag needs to be used with caution.

*Even client_scripts will have actual impact. Test it in a single game

schedule delay related

20tick is equivalent to 1 second;

InternaL.ScheduleDevent.RescheDule () can re -execute the entire segment delayed code, and can add conditional limits: After 1 second of second, the player performs new the same delay if the player is not in the ground;

*The extended code will be lost after the archive is closed. For example, the code executes the removal of the items in the hands of the player, and the delay will be returned after 5 seconds.You need to use this function with caution.

Text -related

Text string string can be connected with+number, and sometimes it can be written as a string [] form, such as server.tell ('1'+'2') and server.tell (['1', '2'])All '12';

Text has more free operating space than pure text string, such as server.tell (text.green ('aaa'). Hover ('SSS').Will display green AAA messages, mouse suspension display SSS, click will copy DDD

Digital correlation

NUM ++ will not update the value immediately in the current position. ++ NUM will immediately increase itself. In many cases, it can simplify the code

client_scripts related

Itemevents.Tooltip incident is not completely processed to TOOPTIP. It is obvious that some Tooltip cannot be removs. It is recommended to use the forg E event. Work.

It is also removed 'potion' and 'minecraft', and only Forgeevents can fully meet the expectations: