your current location:首页 > news>How to use ChatCommandsManager as the front module [CCM] ChatComMandsManager Minecraft Game

How to use ChatCommandsManager as the front module [CCM] ChatComMandsManager Minecraft Game

2024-12-10 17:47:06|Myriagame |source:minecraft skins

First of all, the ChatCommandsManager module is added to the Run/MODS directory of the project to facilitate debugging.

Then add a function to determine whether the module contains the ChatcommandsManager module.

example:

<<<<<<<<<<], the, the, "assh: java;">> portatic?

For (Imodinfo Modinfo: Modlist.get (). Getmods ()) {) {) {

If (modinfo.getmodid (). Equals ("ccm") {{

Return true;

}

}

Return false;

}

Then call this function to judge in the main function. If not, throw Runtimeexception. On the contrary, the operation of the configuration file is performed (when the module is loadedBecause the ChatCommandsManager module defaults to the last one to be loaded).

example:

 Public POS () Throws IOEXCEPION {

Minecraftforge.event_bus.register (this);

Init (); // The initialization function is called in the main class.

}

Public Static Void Init () Throws IOEXception {{

If (! Hasapi ()) {// Detect whether it contains the ChatcommandsManager module.

Throw New Runtimeexception ("POS MOD Requires ChatCommandsManager Mod!"););

}

If (! New File ("Config/CCM/MODS"). Exist ()) {// Detect and create a directory.

New file ("config/ccm/mods"). Mkdirs ();

}

If (! New File ("Config/CCM/MODS/FPOS.JSON"). ExistS ()) {// Test and write configuration files.

JsonObject Object = New JSONObject (); Object.addproperty ("name", "fpos"); // Write the configuration file "name"

Object.addproperty ("ID", "POS"); // Write the configuration file item "ID"

Object.addproperty ("main", "cn.ksmcbrigade.pos.manager"); // Write the configuration file item "main"

Object.addproperty ("function", "runfpos"); // write the configuration file item "Function"

Files.write (Paths.get ("Config/CCM/MODS/FPOS.JSON"), object.tostring (). Getbytes ()); // Write the configuration to the file.

}

}

The above code may be thrown out of IOEEXception. Please use the Try/Catch package or add an exception signature (the example is an exception signature), otherwise it will not be compiled normally.

Next create a class file specified in the configuration file, and then add a corresponding function to the class file.

example:

 Package cn.ksmcbrigade.pos;

import network.minecraft.client.minecraft;

import network.minecraft.network.chat.component;

import network.minecraft.World.entity.player.player;

Import java.util.arrays;

public class manager {

Pbstic static Void Runfpos

Player player = minecraft.getInstance (). Player;

If (Arrays.equals (Args, New String [0])) {{

Player.SendMessage (Component.nullToEMPTY ("POS:"+Player.getx ()+","+Player.get ()+","+Player.getz ()), Player.getuum ());}

Else {

Player friend = null;

for(Player entity:player.getLevel().getEntitiesOfClass(Player.class,player.getBoundingBox().inflate(1000))){

If (entity.getName (). GetString (). Equals (ARGS [0])) {) {

Friend = Entity;

}

}

If (friend == null) {

Player.SendMessage (component.nulltoEMPTY ("caner find friend!"), Player.getuuid ()););););););

}

Else {

Player.SendMessage (Component.nullToEMPTY ("POS:"+Friend.getx ()+","+Friend.get ()+","+Friend.getz ()), Player.Getuituum ());}

}

}

}

Tip: Player and ARGS parameters of the function must be added even if you do n’t need to add it, otherwise the input instruction will report an error and cause the game to collapse.

Note: You need to export the module after exporting the starter to test in the starter. Testing in the IDE may report an error.