your current location:首页 > news>1.18 Module Development Access and Simple Functional Implementation [Forge] Minecraft Forge Minecraft Game

1.18 Module Development Access and Simple Functional Implementation [Forge] Minecraft Forge Minecraft Game

2024-12-10 17:48:18|Myriagame |source:minecraft skins

hint

Last module development tutorial: ModuleManager and configuration files and simple functions.

Accessstransformer access to the use of converters

Jian Shao

AccessortransFormer is referred to as AT, which can modify the access modification of the specified field or method and whether it is fired by Final. It is different from Mixin that it can access the variables or functions modified by the modified modifier.

use

First of all, you need to add the following in the MINECRAFT item of the Build. Gradle file, and create a new file account in the Meta-INF directory of the module resource directory:

 Minecraft {

[...]

Accessstransformer = File ('SRC/main/Resources/Meta-INF/Accessstransformer.cfg')

}

Finally, build the project.

Note: When the module is loaded in a non-development environment, FORGE will only load the Meta-INF/Accessstransformer.cfg AT configuration file in the module file.

The SRGNAME is used in the AT configuration file. We can use the characteristics of Mixin to obtain SRGNAME, such as the Timer variable located in the Minecraft class, which is used to control the number of operations per second per second.

 Package cn.ksmcbrigade.em.mixin;

import network.minecraft.client.minecraft;

Import network.minecraft.client.timer;

import org.spongepowered.asm.mixin.mixin;

Import org.spongepowered.asm.mixin.gen.accessor;

@Mixin (minecraft.class)

Public Interface Minecraftmixin {

@Accessor ("Timer")

Timer gettimer ();

}

 {{

"Required": true,

"Minversion": "0.8",

"Package": "CN.KSMCBRIGADE.EM.MIXIN",

"CompatibilityLevel": "java_8",, "java_8",

"Refmap": "Em.refmap.json",

"Mixins": [[

],,,

"Client": [[

"Minecraftmixin"

],,,

"Injectors": {

"DefaultRequire": 1

}

}

Use Accessor to comment here to obtain a specified variable. To execute the specified function, you need to use Invoker to comment.Then run the BUILD task to export the module file, and finally open the modid.refmap.json in the module file by decompressing the software to check the SRGNAME of the specified variable:

 {{

"Mappings": {

"CN/KSMCBRIGADE/EM/MIXIN/MINECRAFTMIXIN": {

"Timer": "F_90991_: lnet/Minecraft/Client/Timer;" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

}

},

"Data": {{

"Searge": {

"CN/KSMCBRIGADE/EM/MIXIN/MINECRAFTMIXIN": {

"Timer": "F_90991_: lnet/Minecraft/Client/Timer;" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

}

}

}

}

The F_90991_ is SRGNAME, and then fill in the access modifier and class path and SRGNAME that needs to be converted into the AT configuration file.

 public-f network

The meaning of -F means removing the final modifier, because the Timer variable is modified by final. If you want to add the final modifier, change the -F to +f.

Tip: This method can still be used for functions.

Simple functional implementation

Timer

This feature can modify the operation speed of the game. First, create a Timer class in the Modules directory, inherit the Module, and then rewrite the enabled and disabled functions:

 Import cn.ksmcBrigade.em.module;

Import java.awt.event.keyevent;

Public Class Timer Extends Module {

Public timer () {

Super ("Timer", keyevent.vk_y); // key v

}

@Override

Public void enabled () Throws Exception {

Super.enabled ();

} @Override

Public void disabled () throws exception {

Super.disabled ();

}

}

Then modify the Timer variable in the enabled function and Disabled function:

@outerride

Public void enabled () Throws Exception {

Minecraft.getInstance (). Timer = new net.minecraft.client.timer (50,0L); // set 50 (2.5)

}

@Override

public void disabled () throws exception {

Minecraft.getInstance (). Timer = new net.minecraft.client.timer (20,0L); // set 20

}

The second parameter of the Timer's constructing function can be filled with 0L by default. The 50 to 2.5 times here, 20 is the default multiple.

Pegasus

Jian Shao

This feature can fly in the right player, ignore whether it has wearing a saddle and whether it has been tamed.

Source of inspiration: Boatfly, Airjump.

accomplish

First create the Pegasus class in the Modules directory, inherit the Module, and then rewrite the UODATE function:

 Package cn.ksmcbrigade.em.modules;

Import cn.ksmcBrigade.em.module;

Import java.awt.event.keyevent;

Public Class Pegasus EXTENDS MODULE {

Public pegasus () {

Super ("pegasus", keyevent.vk_i); // key i

}

@Override

Public void update () Throws Exception {

Super.Update ();

}

}

Then determine whether the player can be converted into the ABSTRACTHORSE class and the space bar in the UPDATE function., Then make the mount jump:

@outerride

Public void update () Throws Exception {Minecraft Mc = Minecraft.getInstance ();

Player player = mc.player;

If (player == null) {

Return;

}

If (player.getvehicle () == null) {

Return;

}

If (! Mc.options.keyjump.isdown ()) {{) {

Return;

}

Entity very = player.getvehicle ();

If (VEHICLE Instanceof Abstracthorse Horse) {{

Horse.setflag (4, true);

Horse.sprintCounter = 7;

Horse.setisjumping (true);

Horse.jumpfromground ();

}

}

Among them, the SETFLAG function and the JumpFromground function need to be used to the converter, which are located in the ABSTRACTHORSE and Livingntity classes, respectively.

 public network.minecraft.World.entity.livingntity m_6135 _ () v

public network.mineCraft.World.entity.animal.Horse.abstracthorse m_30597_ (iz) v

Registration function

Then register in the ModuleManager.modulesclass class:

 Public Static Module Timer = New Timer (); // Key Y

Public Static Module Pegasus = New Pegasus (); // Key I

Just run the test.

Complete code

accesstransformer.cfg

 public-f network.minecraft.client.minecraft f_90991_public network.minecraft.ntity.livingentity m_6135 _ () v

public network.mineCraft.World.entity.animal.Horse.abstracthorse m_30597_ (iz) v

Timer.java

 Package cn.ksmcbrigade.em.modules;

Import cn.ksmcBrigade.em.module;

import network.minecraft.client.minecraft;

Import java.awt.event.keyevent;

Public Class Timer Extends Module {

Public timer () {

Super ("Timer", keyevent.vk_y);

}

@Override

Public void enabled () Throws Exception {

Minecraft.getInstance (). Timer = new net.minecraft.client.timer (50,0L);

}

@Override

Public void disabled () throws exception {

Minecraft.getInstance (). Timer = new net.minecraft.client.timer (20,0L);

}

}

Pegasus.java

 Package cn.ksmcbrigade.em.modules;

Import cn.ksmcBrigade.em.module;

import network.minecraft.client.minecraft;

import network.minecraft.World.entity.entity;

import network.minecraft.World.entity.animal.Horse.abstracthouse;

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

Import java.awt.event.keyevent;

Public Class Pegasus EXTENDS MODULE {

Public pegasus () {super ("pegasus", keyevent.vk_i);

}

@Override

Public void update () Throws Exception {

Minecraft mc = minecraft.getInstance ();

Player player = mc.player;

If (player == null) {

Return;

}

If (player.getvehicle () == null) {

Return;

}

If (! Mc.options.keyjump.isdown ()) {{) {

Return;

}

Entity very = player.getvehicle ();

If (VEHICLE Instanceof Abstracthorse Horse) {{

Horse.setflag (4, true);

Horse.sprintCounter = 7;

Horse.setisjumping (true);

Horse.jumpfromground ();

}}

}

ModuleManager.modulesClass

 Static Class ModulesClass {

Public static module nofall = new not ("not", keyevent.vk_n);

Public static module xyz = new xyz ("xyz", keyevent.vk_b);

Public static module timer = new timer (); // key y

Public module pegasus = new pegasus (); // key I

}