2024-12-10 17:58:57|Myriagame |source:minecraft skins
This tutorial is set by the author to use the CC By-NC-ND protocol.
Basic grammar
Reflection is an important feature of Kubejs. It allows you to access some safe Java classes to use the function of more than Kubejs.
Use the following statement to obtain a class
const shield = java.loadClass ("net.minecraft.World.Item.shielditem");
This class gets an original item class, corresponding to the category of shields in the game.
Some classes cannot be reflected and obtained, such as
// Reflexes get java.io.file. File reads and write generally requires this classconst file = java.loadClass ('java.io.file')
// The output result of the log
[12:59:55] [Error]! Economic.js#1: Failed to load java class 'java.io.file': class is not allowed by class file!
Class Filter determines which classes can be reflected, and the classes that are not allowed often have the ability to make the integrated package become virus software.However, most categories related to game content can be used normally.
Class can directly call its static method
const $ keymappingregization = java.loadClass ("Dev.architectable.regization.client.Keymappings.Keymappingregization" "
);
$ KeymappingRegistry.register (global.testkey)
You can also use new to get an object
const prop = java.loadClass ("net.mineCraft.World.Item.item $ Properties");const defandroperties = new prop ();
It can be found that the class obtained by reflection is almost the same as the class in Java. When used, just imitate the Java method.More accurate, it is the development of imitating Forge or Neoforge module development and using the development of the Architectury API.
When using Probejs
Each class must be loaded at least once to be recognized by Probejs and generates the required files required for automatic completion.
The class with automatic completion can be reflected
If not, run the following instructions according to the location of the script after reflection, refresh the script
/kubejs relaxed client_scripts/kubejs recoad server_scripts
/kubejs regoad startup_scripts
Run this command and let Probejs generate the file required for this class
/Probejs dump
Example: Register almost the same items
The registration incident provided by Kubejs cannot register such as shields, bows, tridents and other items.Using reflection can register almost the same items, and can also customize some attributes.
// The original shield classconst shield = java.loadclass ("net.minecraft.World.Item.shieldItem"); // Item attribute category
const prop = java.loadclass ("net.minecraft.World.Item.Item $ Properties");
const defandroperties = new prop ();
Startupevents.regization ("item", (event) => {{{{
// Set the attributes of the item, the durability is 1024, and the scarcity is EPIC (for example, the scarcity of the enchanting gold apple is EPIC, and its name is purple)
Defproperties.defaultDurability (1024);
Defproperties.rarity ("EPIC");
Event.createcustom (name, () => {
Let item = new shield (defproperties);
Return item;
});
});
The point is this callback function.We can roughly understand that each time the game needs this item, the backing function must return an instance (object) of an item class.
National Service DNF Dark Ni
2025-01-28 09:19:27The new screenshot of the be
2025-01-28 09:18:57The 15th anniversary wallpap
2025-01-28 09:18:273DM Xuanyuan Sinicization Gr
2025-01-28 09:17:57French magazine is the first
2025-01-28 09:17:27The sneak game "Republic" wi
2025-01-28 09:16:57The story between humans and
2025-01-28 09:16:27Capture "Trinity 3: Artifact
2025-01-28 09:15:27Wind direction change "Myste
2025-01-28 09:14:57DICE's new project "Dream" w
2025-01-28 09:14:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:26Master Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25King Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25Guide Minecraft Skins
Minecraft Skins
2024-12-10 04:11:24Dark Knight Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Sparta Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Moncraft Skins of the War
Minecraft Skins
2024-12-10 04:11:22Red Witch Minecraft Skins
Minecraft Skins
2024-12-10 04:11:22Golden Cavaliers Minecraft S
Minecraft Skins
2024-12-10 04:11:22