[Development direction] How to use the Curios API to add jewelry and custom jewelry bar (take forge as an example) Curio

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

Zero, write in front

Agreement and Declaration

Note that the content of this article uses the CC: by-NC-SA protocol. The code implemented by the individual is open source with the same protocol.Other described code is mainly based on the Minecraft source code compiled by FORGE. All functions, classes, and member variables are named.Communication.

Curios API's code is open source with LGPL protocol, so when linking or relying on the Curios API, you can use any protocol to open up your MOD.

The Curios API has an official English document, but the content is very small. While introducing WIKI in this article, this article adds personal understanding and made appropriate supplements.You can also view the original Wiki text of the Curios API.

This tutorial uses the default readers to have the basic understanding of Java code ability and MOD development.

Configure build.gradle

First of all, you have to find a suitable Curios API here, such as 1.18.2 Curios API V5.0.9.0.

Then, you want to add the corresponding Maven to download the URL in Build.gradle:

 repositories {

Maven {// top

Url "https://cursemaven.com"

}

Maven {// mirror

Name = "modmaven"

Url = "https://modmaven.dev"

}

}

Then, add Curios in DependenCies:

 Dependencies {

Minecraft 'network.minecraftForge: Forge: 1.18.2-40.1.0'

Compileonly fg.deobf ("Top.Theillusivec4.Curios: Curios-Forge: 1.18.2-5.0.9.0")

}

Here is a compileonly. The goal is to link Curios. You can also use Implementation to ensure that Curios is loaded during the running test (but in most cases, Implementation is used for necessary front modules).

Executive construction, Gradle will help you download Curios for you to call your API.

Configure MODS.TOML.

When you want Curios as your necessary or available prefix, you need to configure Mods.toml.

For example, you can write like this:

 [dependencies.your_modid]]]

Modid = "Curios"

MANDATORY = FALSE

VersionRange = "[5.0.9.0, 5.1.0.0)" Ordering = "None"

Side = "Both"

At this time, Curios has become your optional front.If it is not installed, FML will not report an error. If your code is correct, it is equivalent to running your MOD independently. No linkage content is loaded; if installed, but the version is less than 5.0.9.0 or higher than 5.1.0.0, then FML reports an error; if the installation is installed and the version is correct, the module is loaded normally and links some functions with the Curios API.

1. Jewelry column related

Before 1.20

1. Application of the jewelry bar

Curios API has no jewelry bar in the Curios API. If your MOD is registered with jewelry, you need to apply for the corresponding field to apply normally, otherwise the player will not be equipped with accessories.

The application method of the jewelry bar is very simple. You need to subscribe to the IntermodeNQueueEvent event and communicate with the Curios API MOD through the intermodComms.sendto method.like:

 Private void Enqueueimc (Final IntermodenqueueEvent Event) {

If (modlist.get (). Isloaded ("Curios") {{

IntermodComms.Sendto ("Curios", slottypemessage.register_type, ()-> slottypepreset.getMessageBuilder (). Build ());

IntermodComms.Sendto ("Curios", slottypemessage.register_type, ()-> Slottypepreset.necklace.getMessageBuilder (). Built ());

}

}

The above code applies to Curios, heads (head) and next place (necklace).After entering the game, click the Curios icon in the item bar, and you can see these two columns.

Personally, I recommend what to apply, and try to apply for a field in the slottypepreset.

2. Creation of the Jewelry Bar

If your MOD creates a jewelry bar alone, it means that only the MOD that it is connected with its affiliated MOD and the code level can be used.So this operation may cause compatibility issues, please try to avoid it.

To create a new field, just based on the above code, you need to remove the slottypepreset.xxx.getMessageBuilder (). Build () and replace it with an additional built message:

 Private void Enqueueimc (Final IntermodenqueueEvent Event) {

If (modlist.get (). Isloaded ("Curios") {{

IntermodComms.Sendto ("Curios", SlottypeMessage.register_type, ()-> New SlottypeMessage.builder ("EARINGS"). LOT/EARINGS ")). Priority (240) .size (1).build ());}

}

At this time, a field called earrings is registered, and the icon is located in Assets/ /Textures/slot/earings.png.

3. Modification of the jewelry bar

The Curios API also provides an operation that implements the corresponding function through the IMC method, that is, modify a jewelry bar.You can use it when you want to modify the field or defined field defined by other mods.At this time, the format of the third parameter is similar to the previous article, but you can use Builder :: SIZE (int) method to increase the number of jewelry, builder :: lock () (equivalent to .size (0)) method lockThe bar, the builder :: Hide () method temporarily hides the field position, and the Builder :: cosmetic () method adds a decorative field to the field.

Usage is the same as the above two operations, so I won't go into details and examples here.

1.20 and after

The Curios API plans to cancel the steps of registering and modifying the cumbersome use of IMC to achieve the use of IMC in the 1.22 and subsequent versions.It is possible to freely operate the Curios API's jewelry bar.Of course, the following article also introduces how to allow any items to be put in the jewelry bar, and it is also used in the form of a packet.

First, the new xxx.json is built in data//Curios/Slots. XXX is the name of your field, the ID of your module/data package.

Then, modify xxx.json.SIZE fields are used for the previous jewelry bar registration; if XXX is not an arbitrarily preset field name, it is equivalent to creating a new jewelry field -of course, if other modules created the same name fields, then the same name, thenYou can also use it; and the value of the field in the Schema can realize the previously used jewelry bar modification (if the field replace is set to TRUE, it will replace other packets or preset field settings instead of other settings.Merge; otherwise, it will be merged according to certain rules).The following table shows the SCHEMA and combined rules of this JSON file. Please modify it as required:

Field field type The default value describes the combined rules, the emptiness of the replaceBooleanfalse If it is set to TRUE, replace the setting of the same field in the lower priority packet-is the default number of the Sizeint1 jewelry field, and the use of IMC registered fields.The maximum value of Operationenum ["set," add "," remove "] set and size with. SET: Set the number of fields (maximum value merging); add: increase the number of fields (harmonious merger); remove: reduce: reduceThe number of fields (for harmony) -Rederint1000 column is in the order value in the item bar. The lower the order value, the higher the ranking of the field, the higher the ranking.

The resource ID of the jewelry bar icon replace the add_cosmetic

Whether the Booleanfalse slot contains a beautification slot or USE_NATIVE_GUI that only provides rendering and does not provide functions

Is the BOOLENTRUE slot display and render_toggle in the GUI of Curios

Whether the items of the BOOLENTRUE slot are rendered (see Chapter 3 of this article) and

2. Items related

First of all, any item can be registered as a jewelry, but the specific details need to be explained.

1. Items

This item must implement the iCurioiteM interface. This interface does not provide any abstract functions and does not need to be rewritten.But if you need to achieve the gain that the player can get after wearing items on your body, you need to rewrite some functions.For example, the Onequip function represents the events triggered by the player on the jewelry bar, and the onunequip function represents the events triggered by the player to bring the jewelry from the jewelry bar.In addition, it also supports the rewriting of functions such as equipment sound, judgment before equipment.The following code realizes an abstract class that performs fixed logic operations on each tick: an abstract class:

> port

Public Curiositem (Properties Properties) {{

Super (Properties);

}

@Override

Public Void Curiotick (SlotContext SlotContext, Itemstack Stack) {{

This.equipmentTick (slotcontext.entity ());

}

Protected Abstract void EquipmentTick (LivingNTITY LIVINENTITY);

}

The EquipmentTick function can complete its functions, such as:

@outerride

profcted varularly through

Livingntity.adDeffect (New MobeFFECTINSTANCE (Mobeffects.night_vision, 20, 0, False, FALSE, TRUE));

}

The above code provides the effect of permanent night vision for the creature wearing the jewelry.

Of course, you can even achieve killing halo through livingntity.Level.GetentIes (). Foreach.

2. Fair binding

After using the previous method to apply for the field, whether the field is preset or created by yourself, you can use the following method to achieve the field binding of the jewelry very quickly.

You need to create a tag of xxx.json in each field you applied for in Data/Curios/Tags/Items.Among them, XXX is your field name, and the preset name is the lowercase corresponding to the capital enumeration.

 {{

"Values": [[

"Metal_necklaces: Uranium_necklace",

"Metal_necklaces: Thorium_necklace"

]

}

They are uranium necklaces and tadpole necklaces.I don't know the spoke in the spokes

In this way, the ITEM corresponding to the ID can be bound to the corresponding field through Tag.3. If Curios is your linkage or optional front

Since the SUPPLIER is used when registering item, you can dynamically determine whether the Curios is loaded and instantiated different ITEM classes according to whether it is loaded or not, such as:

 Public Static Final registryObject  Pearl_bracelet = register.register (

"Pearl_bracelet", ()-> Makecuriositem (

Item_group, livingntity-> livingntity.addeffect (New MobeFFFECTINSTANCE (MobeFFECTS.DAMAGE_BOOST, 10, 0, FALSE, TRUE))

Cure

);

Public Static item Makecuriositem

If (modlist.isloaded ("curios") {{) {

Return CuriositemFactory.make (new item.properties (). Stacksto (1) .tab (tab), effect);

}

Return new item (new item.properties (). Stacksto (1) .tab (tab));

}

The CuriositeMFactory class can be written like this:

 Public Final Class CuriositeMFactory {

Public Static item Make (item.properties props, consumer Effect) {

Return New Curiositem (PROPS) {

@Override

Profcted varularly through

Effect.accept (livingntity);}

};

}

}

Through these two layers of packaging and combining Java's lazy loading method, you can use different logic to load according to Curios loading when registering the same item.

If you don't do this, when Curios is not running, your MOD will report an error and prompt you not to find a class.So this is also a commonly used linkage technique for the development of FORGE modules.

Three, rendering

It is very intuitive that the Curios API does not simplify the code to provide accessories rendering for users.However, Curios provides the registration interface of the renderer after equipping the jewelry, that is, the Curiosrenderregistry :: register.So you can register the renderer through the following ways to subscribe to FMLClientSetupevent:

@SubscripeEvent

Public Static Void ONClientSetup (FMLClientSetUPEVENT) {{

Event.enqueuework (()-> {{

If (modlist.get (). Isloaded ("Curios") {{

Curiosrenderrs.registerRenders ();

}

});

}

Curiosrenderers class:

 Public Static void registerRenderrs () {

Curiosrenderregistry.register (mnitems.uranium_necklace.get (), necklacerenerer :: New);

Curiosrenderregistry.register (mnitems.thorium_necklace.get (), necklacernderEr :: New);

}

Necklacerenerer can render necklaces in a way similar to armor:

 Public Class NecklaceRender IMPLEMENTS ICURIORIORENDERER {

Public Static Final ModellayerLocation NECKLACE = New ModellayerLocation (New Resources (Modid, "Next"); "Main"); "Main");

Private Final Humanoidmodel Model; Public NCKLACERENDER () {

This.model = New Humanoidmodel <> (Minecraft.getInstance (). GeTentityModels (). Bakelay (NextLace));

}

@Override

Public > Void Render (Itemstack Stack, SlotContext SlotContext, Posstack MatrixStack, Renderlayerparpar ENT Renderlayerparent,

Multibuffersource rendertypebuffer, int app, flow life

Float PartialTicks, Float Ageinticks, Float Netheadyaw, Float Headpitch) {{

If (stack.getITEM () Instanceofofcuriositem caiositem) {{

Icuriorenderer.followbodyrotations (SlotContext.entity (), this.model); vertexConsume vertexConsumer = rendertypebuffer.getbuffer (rendertype.en Titycutout (New ResourceLocation (

MODID, "Textures/Model/Curios/"+FORGEREGITEMS.Getkey (Curiositem) .getpath ()+".png" "

));

This.model.Rendertobuffer (MatrixStack, VertexConsumer, Light, Overlaytexture.no_over, 1.0F, 1.0F, 1.0F, 1.0F);

}

}

}

Then you can place the necklace model texture of the necklace in Assets/ /Textures/model/curios/xxx.png. The XXX is the name of the item, and the model corresponding to the texture must be a model like Zombie and Player.It should be noted that, like other ModellayerLocation, Necklace needs to be registered through the event.registerlayerDefinition method in the function of the function of the function of the function of the function of the function of the function of EntityRendeEvent.registerlayerDefinition.

 Event.registerlayerDefinition (NextLACERENDER.NECKLACE, ()-> LayerDefinition.create (humanoidmodel.createmesh (New Cubedee Formation (0.25F), 0.0F), 64, 64); 

Fourth, summary

The above is the author's clumsy opinion on the usage of the Curios API module and tutorial.If there are other content that needs to be updated, the author will also modify it as soon as possible!