2024-12-10 17:54:10|Myriagame |source:minecraft skins
This tutorial is set by the author's setting without permission.
1 Previous situation
In the previous tutorial, we successfully established the development environment, and also output Hello World in the form of Fabric Mod.
Of course, only these are not enough.
2 creative power
"The original god of the beginning created the world piled up in this block,
Can the people in the next day continue the glory of the front?"
2.1 Idential symbol
As we all know, MINECRAFT has a ID (Identifier, the identifier) of almost anything.
The difference between the identifier to distinguish between things is like the name of the same thing.
However, compared to the name that is really used for the title, Minecraft requires that each identifier can only refer to one thing.
No name is allowed.(After the tutorial, you can try what will happen by yourself)
If you have a simple contact with the original instructions, you should be able to understand what the latter part is:
/give @s minecraft: Apple
It doesn't matter if you don't understand, you can know it by yourself.
Apple's ID is "Minecraft: Apple".
First of all, we need to know that all the items in Minecraft are inherited from a class called "item" (Item), and
It contains the attributes and behaviors that it should have.
How to create a new item?
Very simple, just need to New.
"What, you don't know what NEW means?
I don't know what class is?
Then hurry up and read the Java basic tutorial!
What, you are too lazy to find ... "
[PS: If there is no need for the Java basic tutorial content, please jump to the 2.3 section]
2.2 The mystery of the world operation
2.2.1 java
(PS: Due to the limited strength and the degree of understanding of Java, maybe there are leaks in some places, please correct me)
Java is a high -end programming language with a completely object, running in JVM (Java Visual Machine, that is, Java virtual machine).
For tutorials, please refer to: java fast success.
2.2.2 Supplementary instructions on classes
In Java, the smallest code unit (can write code) is a class.Class may not be so easy to understand for programmers,
But don't give up, this is an inevitable process.
Class is used to describe a class of things with common/similarity and behavior. Even if there may be differences in specific behaviors, it is generally not deviated.
Inheritance is allowed between classes, inheriting a class can inherit its nature and behavior, or can also be modified.
For better analysis of classes ... Please see the figure below:
This is a portrait of a cat
This is also a portrait of a cat
These two portraits depict cats, so they can be classified as "cat portrait".
This is a portrait of human beings
And this is a portrait of another human (AI, so the style of painting is a bit abrupt)
Both of them are human, so they can be classified to a "portrait of human beings."
Then, what are the common points of these two categories?It's all portraits, right.
That's right, so these two categories inherit from "portrait".
A class is just an abstract concept, not a practical thing, so it is necessary to use it to use (except for static methods).
The instantiated class is called an instance, and the instance belongs to this class, but may have different attributes.
For example: There is a "human" now,
"Zhang San" is an example of "human".
"Li Si" is also an example of "human". "Identity" is "five -star citizen"
What is the difference?Different attributes.
Of course, some classes have some common characteristics, and at this time, it is necessary to use static to modify it as static.
Static methods/fields can be called at any time and can save memory overhead.
2.2.3 Access permissions level table
、 Representatives can be accessed and 可以 Representative cannot be accessed.
Access modifier this class itself, the sub -category of sub -category, the global Public✔✔✔✔protEcted✔✔✔✘less ✔✔✘✘Private✔✘✘✘
The original table is as follows:
2.3 Register
To make a thing has a name, it must be registered at the "registered" (registered name: registrar).
The registration method is as follows:
registry.register(The reason why I do not do the forge tutorial is because this step alone is too complicated)
2.4 Added items
2.4.1 example
Let's add a new food:
// Package statement omitimport network.fabricmc.api.modinitializer;
Import org.slf4j.logger;
Import org.slf4j.loggerFactory;
Public Class ExampleMod Implements Modinitializer {
// ...
Public Static Final Logger Logger = LoggerFactory.getLogger ("Template-Mod");
@Override
public void oninitialize () {
// ...
// No longer need to print this message
// Logger.info ("Hello Fabric World!");
Logger.info ("Example Mod is load!");
}
// Used to store this registered item,
// Convenient to quote.
Public Static Final item test_food;
static {
// Actual registration action.
Test_food = registry.register (builtInRegistries.Item, New ResourceLocation ("modid", "test_food"), new item (new item (new item (new item (new item (new item
// Item attributes: Food attributes: saturation +999
New item.properties (). FOOD (New FoodProperties.builder ().
);
}
/*In addition to being registered as above, it is possible to do this:
*
*Public Static itm test_food;
*
*Public void oninitialize () {) {)
*// Register when the mod initialization
*Test_food = registry.register (...);*}
*
*/
/* so:
*
*Public void oninitialize () {
*// Directly register without using variable proxy:
*Registry.register (...);
*}
*/
}
In this way, we successfully write the registration of the items. Next, we need to add texture and model to our food.
Item model: src/main/resources/assets//models/item/test_food.json Item texture: src/main/resources/assets/
/textures/item/test_food.png Under normal circumstances, the item model needs to inherit "ITEM/Generated", which is a standard item model.
It is no exception here, inherited directly:
{{"Parent": "Item/Generated",
"Textures": {
"": "Texture Location"
"Layer0": "modid: item/test_food"
}
}
The pictures used in texture can be casual. Here is the icon of Fabric as a demonstration (due to the display of the encyclopedia, the picture must be centered, so it may not be so eye -catching):
(Eat a cloth head [])
Then, you need to add the corresponding item name:
Language file (Simplified Chinese): src/main/resources/assets//lang/zh_cn.json Language file (English): src/main/resources/assets/
/lang/en_us.json The format is as follows:
{{"Item.modid.test_food": "Test food"
}
Then you can put it in the game and try it.
2.4.2 Animal attribute analysis
【Unhappy to be continued】
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