Questa pagina analizzerà la struttura di un progetto per una mod Fabric, e l'utilità di ogni file e cartella nel progetto.
fabric.mod.json
Il file fabric.mod.json è il file principale che descrive la tua mod al Loader di Fabric. Contiene informazioni come l'ID della mod, la versione, e le dipendenze.
Gli attributi più importanti nel file fabric.mod.json sono:
id: L'ID della mod, che dovrebbe essere unico.name: Il nome della mod.environment: L'ambiente in cui la tua mod viene eseguita, comeclient,server, o*per entrambi.entrypoints: Gli entrypoint che la tua mod fornisce, comemainoclient.depends: Le mod da cui la tua mod dipende.mixins: I mixin che la tua mod fornisce.
Puoi trovare un esempio del file fabric.mod.json sotto - questo è il file fabric.mod.json per il progetto di riferimento su cui è basato questo sito di documentazione.
fabric.mod.json del Progetto di Riferimento
json
{
"schemaVersion": 1,
"id": "example-mod",
"version": "1.0.0",
"name": "Example Mod",
"icon": "assets/example-mod/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.example.docs.ExampleMod",
"com.example.docs.event.ExampleModEvents",
"com.example.docs.command.ExampleModCommands",
"com.example.docs.effect.ExampleModEffects",
"com.example.docs.potion.ExampleModPotions",
"com.example.docs.sound.ExampleModSounds",
"com.example.docs.damage.ExampleModDamageTypes",
"com.example.docs.item.ExampleModItems",
"com.example.docs.enchantment.ExampleModEnchantments",
"com.example.docs.block.ExampleModBlocks",
"com.example.docs.block.entity.ExampleModBlockEntities",
"com.example.docs.component.ExampleModComponents",
"com.example.docs.advancement.ExampleModDatagenAdvancement",
"com.example.docs.networking.ExampleModNetworking",
"com.example.docs.networking.basic.ExampleModNetworkingBasic",
"com.example.docs.debug.ExampleModDebug"
],
"client": [
"com.example.docs.client.command.ExampleModClientCommands",
"com.example.docs.ExampleModBlockEntityRenderer",
"com.example.docs.ExampleModDynamicSound",
"com.example.docs.ExampleModClient",
"com.example.docs.rendering.CustomRenderPipeline",
"com.example.docs.rendering.HudRenderingEntrypoint",
"com.example.docs.rendering.RenderingConceptsEntrypoint",
"com.example.docs.network.basic.ExampleModNetworkingBasicClient"
],
"fabric-datagen": [
"com.example.docs.datagen.ExampleModDataGenerator"
]
},
"mixins": [
"example-mod.mixins.json",
{
"config": "example-mod.client.mixins.json",
"environment": "client"
}
],
"depends": {}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Entrypoint
Come detto in precedenza, il file fabric.mod.json contiene un attributo entrypoints - questo attributo è usato per specificare gli entrypoint che la tua mod fornisce.
Il generatore di mod modello crea sia un entrypoint main che client predefiniti - l'entrypoint main è usato per codice comune, mentre l'entrypoint client è usato per codice client specifico. Questi entrypoint vengono chiamati rispettivamente quando il gioco viene avviato.
java
public class ExampleMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "example-mod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Quello sopra è un esempio di un semplice entrypoint main che logga un messaggio alla console quando il gioco si avvia.
src/main/resources
La cartella src/main/resources viene usata per memorizzare le risorse che la tua mod utilizza, come texture, modelli, e suoni.
È anche la posizione di fabric.mod.json e di qualsiasi file di configurazione mixin che la tua mod utilizza.
Le risorse sono memorizzate in una struttura che rispecchia la struttura dei pacchetti risorse - per esempio, una texture per un blocco verrebbe memorizzata in assets/example-mod/textures/block/block.png.
src/client/resources
La cartella src/client/resources viene usata per memorizzare risorse client specifiche, come texture, modelli, e suoni che sono solo utilizzati dal lato client.
src/main/java
La cartella src/main/java viene usata per memorizzare il codice sorgente Java per la tua mod - esiste sia su ambienti client sia server.
src/client/java
La cartella src/client/java viene usata per memorizzare codice sorgente Java client specifico, come codice per il rendering o logica del lato client - come provider per il colore dei blocchi.

