This tutorial is set by the author to use the CC by-NC protocol.
AnnotionLib can register and other operations without modifying the original variable statement. This tutorial will introduce the way of registration.
Table of contents:
What are the advantages?
How to quote this library
How to register operation
Sample
1. What are the advantages?
You want to register a simple item now, and you may write this:
Public Static Final item test_item = new item//register
public static void init () {
Registry.register (registries.Items, New Identifier ("MOD_ID", "Name"), test_item);
}
// Or use static constructor
Some people will write a special register method to register, so that some code can be omitted.
In any case, this code will look very embarrassed.
What if you use AnnotationLib?
@octregPublic Static Final item test_item = new item
// This will be registered
In the same way, you may need to be put in the item group after you register it, and you can write it with AnnotationLib:
@octreg@Group (@Targetid (namespace = "minecraft", value = "building_blocks")
Public Static Final Block Test_item = New Block (ABSTRACTBLOCK.SETTINGS.CREATE ());
// It can simplify the operation
@Itemreg (group = @targetid (namespace = "minecraft", value = "building_blocks")
Public Static Final item test_item = new item
And all the registrations are controlled by AnnotationLib, and there will be no problem of early registration or forgetting registration.Someone once registered the potion formula with mixin results, causing the register of the square to have a bunch of problems. Check the BUG for three days.
2. How to quote this library?
At present, because there is no official version, you need to introduce manually and use Flatdir.
In the later period, you can use the author Maven to introduce (stay and write before writing)
3. How to register operation
① Create a new nonsense
Create a new class and implement the IannotationsLibentrypoint interface, and then use the @Modid annotation to indicate the ID of your mod
@modid (examplemod.mod_id)Public Class Testregistry Implements IanNotationLibentrypoint {}
Then fill in the entrance point in Fabric.mod.json
{{"Entrypoints": {
"Annotation_lib": [[
"Your Class Here"
]
}}
② Add your items
AnnotationLib currently supports the following types and all the registration of all inheritance types:
ITEM BLOCK EntityType <> Itemgroup SoundEvent StatuseffectIt is recommended that only these types of static attributes are added, otherwise the warning programmer will be reported during the loading process regardless of warning.
Then add a @Objectreg annotation to each item. The lowercase of the attribute name will be registered as a lowercase. Of course, you can also specify it by yourself:
@octreg ("new_name")Start the game, at this time you will find that items are registered.
③ Links of block items
But you will find a problem. In theory, each block has a blockitem that will correspond to it, but one annotation cannot be used for two attributes at the same time.
AnnotionLib provides @Link annotation for link
@link (type = targettype.block, target = @Targetid (namespace = AnnotationLib.mod_id_id, value = "test_block")Public Static item test_block_item = null;
Targettype is the target block type, and currently supports blocks and skull. If it is SKULL, please introduce two targets:
@link (type = targettype.skull, targets = {@Targetid ("test_head"), @Targetid ("test_wall_head")})Public static item test_head = null;
Special attention: 1. If you use @Link annotations, the attribute must be static instead of static final, otherwise the following errors will be reported:
Field with Static Final Modifier Cannot Use @Link Since This is a UnsaFe Operation in Java 12+.: (2. Please assign this variable to NULL, because the MC will automatically detect whether there is an item that is not registered. If it is detected
④ The registration of the physical default Attribute
Each entity must have a default Attribute, otherwise MC will collapse and withdraw.You can register by yourself, but AnnotationLib also provides an annotation @ATTRIBUTEBUILDER from Movement:
// Note: This code should be written into your Entity class instead of items registration class!@Attributebuilder
public static defaultAltributeContainer.Builder Createattributes () {) {) {) {)
DefaultAttributeContainer.Builder Builder = mobentity.createMobattributes ();
// Set the default attribute here
Return Builder;
}
Principle: AnnotationLib will automatically read the parameter class in EntityType and go in to read the Static method
⑤ Add the items to the item group
AnnotionLib provides an annotation @Group to quickly register:
@octreg@Group (@Targetid (namespace = "minecraft", value = "building_blocks")
Public Static Final Block Test_item = New Block (abstractBlock.Settings.create ());
This annotation is mainly used for @Link items. If you think it is too troublesome to register a single item, you can use @Itemreg
@Itemreg (group = @Targetid (namespace = examplemod.mod_id, value = "group")Public Static Final item test_item = new item
Special attention: For unknown reasons, it is not possible to automatically join the item group. Please write the following in the constructor of the item group:
// here Identifier should be consistent with ItemgroupFabriciteMGroup.Builder (). Entries "), Entries))))
4. Sample examples
@SUPPRESSWARNINGS ("Unused")
@Modid (Examplemod.mod_id)
position
@Itemreg (group = @Targetid (namespace = examplemod.mod_id, value = "group")) public static final item test_item = new item (New Fa BriciteMSettings ());
@Objectreg
Public Static Final Block Test_block = New Block (abstractBlock.settings.create ());
@Group (@Targetid (namespace = examplemod.mod_id, value = "group")
@Link (type = targettype.block, targets = {@Targetid (namespace = Annotationlib.mod_id, value = "test_block")})})})})})})})}
Public item test_block_item = null;
@Objectreg
Public Static Final EntityType
Test_entity_type = EntityHelper.build (MyEntity :: New, Spawngroup.Monster, 64, 3, True, 1.6F, 1.8F); }