Struttura del Progetto 1.20.4
Una panoramica sulla struttura di un progetto per una mod Fabric.
WARNING
Questa pagina si applica alla versione 1.20.4. La documentazione delle versioni meno recenti potrebbe essere incompleta.
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.menu.ExampleModMenuType",
"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",
"com.example.docs.saveddata.ExampleModSavedData",
"com.example.docs.entity.attribute.ExampleModAttributes",
"com.example.docs.recipe.ExampleModRecipes",
"com.example.docs.entity.ExampleModEntity",
"com.example.docs.gamerule.ExampleModGameRules"
],
"client": [
"com.example.docs.client.command.ExampleModClientCommands",
"com.example.docs.ExampleModBlockEntityRenderer",
"com.example.docs.ExampleModDynamicSound",
"com.example.docs.ExampleModClient",
"com.example.docs.ExampleModScreens",
"com.example.docs.rendering.CustomRenderPipeline",
"com.example.docs.rendering.HudRenderingEntrypoint",
"com.example.docs.rendering.RenderingConceptsEntrypoint",
"com.example.docs.network.basic.ExampleModNetworkingBasicClient",
"com.example.docs.appearance.ExampleModAppearanceClient",
"com.example.docs.keymapping.ExampleModKeyMappingsClient",
"com.example.docs.ExampleModRecipesClient",
"com.example.docs.entity.ExampleModCustomEntityClient"
],
"fabric-datagen": ["com.example.docs.datagen.ExampleModDataGenerator"]
},
"mixins": [
"example-mod.mixins.json",
{
"config": "example-mod.client.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=0.19.0",
"minecraft": "~26.1",
"java": ">=25",
"fabric-api": "*"
},
"accessWidener": "example-mod.classtweaker"
}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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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.

