EquipmentAssetProvider .java

net.minecraft.client.data.models.EquipmentAssetProvider (class): members: pathProvider, getName, run. strings: "Equipment Asset Definitions", "chainmail".

net.minecraft.client.data.modelsclass153 linesclient7.0 KB

Implements

API Surface (2)

CompletableFuture<?> run(final CachedOutput cache)
String getName()

Fields & Constants (1)

pathProvider

String literals (19)

"equipment"
"leather"
"leather_overlay"
"chainmail"
"copper"
"iron"
"gold"
"diamond"
"turtle_scute"
"netherite"
"armadillo_scute"
"armadillo_scute_overlay"
"elytra"
"saddle"
"_harness"
"trader_llama"
"trader_llama_baby"
"Tried to register equipment asset twice for id: "
"Equipment Asset Definitions"

Full Source

EquipmentAssetProvider.java153 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.data.models;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Optional;
6
import java.util.Map.Entry;
7
import java.util.concurrent.CompletableFuture;
8
import java.util.function.BiConsumer;
9
import net.fabricmc.api.EnvType;
10
import net.fabricmc.api.Environment;
11
import net.minecraft.client.resources.model.EquipmentClientInfo;
12
import net.minecraft.data.CachedOutput;
13
import net.minecraft.data.DataProvider;
14
import net.minecraft.data.PackOutput;
15
import net.minecraft.data.PackOutput.PathProvider;
16
import net.minecraft.data.PackOutput.Target;
17
import net.minecraft.resources.Identifier;
18
import net.minecraft.resources.ResourceKey;
19
import net.minecraft.world.item.DyeColor;
20
import net.minecraft.world.item.equipment.EquipmentAsset;
21
import net.minecraft.world.item.equipment.EquipmentAssets;
22
import net.minecraft.world.item.equipment.trim.TrimMaterials;
23
import net.minecraft.world.item.equipment.trim.TrimMaterials.Palette;
24
25
@Environment(EnvType.CLIENT)
26
public class EquipmentAssetProvider implements DataProvider {
27
	private final PathProvider pathProvider;
28
29
	public EquipmentAssetProvider(final PackOutput output) {
30
		this.pathProvider = output.createPathProvider(Target.RESOURCE_PACK, "equipment");
31
	}
32
33
	private static void bootstrap(final BiConsumer<ResourceKey<EquipmentAsset>, EquipmentClientInfo> consumer) {
34
		consumer.accept(
35
			EquipmentAssets.LEATHER,
36
			EquipmentClientInfo.builder()
37
				.addHumanoidLayers(Identifier.withDefaultNamespace("leather"), true)
38
				.addHumanoidLayers(Identifier.withDefaultNamespace("leather_overlay"), false)
39
				.addLayers(
40
					EquipmentClientInfo.LayerType.HORSE_BODY,
41
					EquipmentClientInfo.Layer.leatherDyeable(Identifier.withDefaultNamespace("leather"), true),
42
					EquipmentClientInfo.Layer.leatherDyeable(Identifier.withDefaultNamespace("leather_overlay"), false)
43
				)
44
				.build()
45
		);
46
		consumer.accept(EquipmentAssets.CHAINMAIL, onlyHumanoid("chainmail").build());
47
		consumer.accept(EquipmentAssets.COPPER, humanoidAndMountArmor("copper").replaceTrimPalette(TrimMaterials.COPPER, Palette.COPPER_DARKER.id()).build());
48
		consumer.accept(EquipmentAssets.IRON, humanoidAndMountArmor("iron").replaceTrimPalette(TrimMaterials.IRON, Palette.IRON_DARKER.id()).build());
49
		consumer.accept(EquipmentAssets.GOLD, humanoidAndMountArmor("gold").replaceTrimPalette(TrimMaterials.GOLD, Palette.GOLD_DARKER.id()).build());
50
		consumer.accept(EquipmentAssets.DIAMOND, humanoidAndMountArmor("diamond").replaceTrimPalette(TrimMaterials.DIAMOND, Palette.DIAMOND_DARKER.id()).build());
51
		consumer.accept(
52
			EquipmentAssets.TURTLE_SCUTE, EquipmentClientInfo.builder().addMainHumanoidLayer(Identifier.withDefaultNamespace("turtle_scute"), false).build()
53
		);
54
		consumer.accept(
55
			EquipmentAssets.NETHERITE, humanoidAndMountArmor("netherite").replaceTrimPalette(TrimMaterials.NETHERITE, Palette.NETHERITE_DARKER.id()).build()
56
		);
57
		consumer.accept(
58
			EquipmentAssets.ARMADILLO_SCUTE,
59
			EquipmentClientInfo.builder()
60
				.addLayers(EquipmentClientInfo.LayerType.WOLF_BODY, EquipmentClientInfo.Layer.onlyIfDyed(Identifier.withDefaultNamespace("armadillo_scute"), false))
61
				.addLayers(EquipmentClientInfo.LayerType.WOLF_BODY, EquipmentClientInfo.Layer.onlyIfDyed(Identifier.withDefaultNamespace("armadillo_scute_overlay"), true))
62
				.build()
63
		);
64
		consumer.accept(
65
			EquipmentAssets.ELYTRA,
66
			EquipmentClientInfo.builder()
67
				.addLayers(EquipmentClientInfo.LayerType.WINGS, new EquipmentClientInfo.Layer(Identifier.withDefaultNamespace("elytra"), Optional.empty(), true))
68
				.build()
69
		);
70
		EquipmentClientInfo.Layer saddleLayer = new EquipmentClientInfo.Layer(Identifier.withDefaultNamespace("saddle"));
71
		consumer.accept(
72
			EquipmentAssets.SADDLE,
73
			EquipmentClientInfo.builder()
74
				.addLayers(EquipmentClientInfo.LayerType.PIG_SADDLE, saddleLayer)
75
				.addLayers(EquipmentClientInfo.LayerType.STRIDER_SADDLE, saddleLayer)
76
				.addLayers(EquipmentClientInfo.LayerType.CAMEL_SADDLE, saddleLayer)
77
				.addLayers(EquipmentClientInfo.LayerType.CAMEL_HUSK_SADDLE, saddleLayer)
78
				.addLayers(EquipmentClientInfo.LayerType.HORSE_SADDLE, saddleLayer)
79
				.addLayers(EquipmentClientInfo.LayerType.DONKEY_SADDLE, saddleLayer)
80
				.addLayers(EquipmentClientInfo.LayerType.MULE_SADDLE, saddleLayer)
81
				.addLayers(EquipmentClientInfo.LayerType.SKELETON_HORSE_SADDLE, saddleLayer)
82
				.addLayers(EquipmentClientInfo.LayerType.ZOMBIE_HORSE_SADDLE, saddleLayer)
83
				.addLayers(EquipmentClientInfo.LayerType.NAUTILUS_SADDLE, saddleLayer)
84
				.build()
85
		);
86
87
		for (Entry<DyeColor, ResourceKey<EquipmentAsset>> entry : EquipmentAssets.HARNESSES.entrySet()) {
88
			DyeColor color = entry.getKey();
89
			ResourceKey<EquipmentAsset> id = entry.getValue();
90
			consumer.accept(
91
				id,
92
				EquipmentClientInfo.builder()
93
					.addLayers(
94
						EquipmentClientInfo.LayerType.HAPPY_GHAST_BODY,
95
						EquipmentClientInfo.Layer.onlyIfDyed(Identifier.withDefaultNamespace(color.getSerializedName() + "_harness"), false)
96
					)
97
					.build()
98
			);
99
		}
100
101
		for (Entry<DyeColor, ResourceKey<EquipmentAsset>> entry : EquipmentAssets.CARPETS.entrySet()) {
102
			DyeColor color = entry.getKey();
103
			ResourceKey<EquipmentAsset> id = entry.getValue();
104
			consumer.accept(
105
				id,
106
				EquipmentClientInfo.builder()
107
					.addLayers(EquipmentClientInfo.LayerType.LLAMA_BODY, new EquipmentClientInfo.Layer(Identifier.withDefaultNamespace(color.getSerializedName())))
108
					.build()
109
			);
110
		}
111
112
		consumer.accept(
113
			EquipmentAssets.TRADER_LLAMA,
114
			EquipmentClientInfo.builder()
115
				.addLayers(EquipmentClientInfo.LayerType.LLAMA_BODY, new EquipmentClientInfo.Layer(Identifier.withDefaultNamespace("trader_llama")))
116
				.build()
117
		);
118
		consumer.accept(
119
			EquipmentAssets.TRADER_LLAMA_BABY,
120
			EquipmentClientInfo.builder()
121
				.addLayers(EquipmentClientInfo.LayerType.LLAMA_BODY, new EquipmentClientInfo.Layer(Identifier.withDefaultNamespace("trader_llama_baby")))
122
				.build()
123
		);
124
	}
125
126
	private static EquipmentClientInfo.Builder onlyHumanoid(final String name) {
127
		return EquipmentClientInfo.builder().addHumanoidLayers(Identifier.withDefaultNamespace(name));
128
	}
129
130
	private static EquipmentClientInfo.Builder humanoidAndMountArmor(final String name) {
131
		return EquipmentClientInfo.builder()
132
			.addHumanoidLayers(Identifier.withDefaultNamespace(name))
133
			.addLayers(EquipmentClientInfo.LayerType.HORSE_BODY, EquipmentClientInfo.Layer.leatherDyeable(Identifier.withDefaultNamespace(name), false))
134
			.addLayers(EquipmentClientInfo.LayerType.NAUTILUS_BODY, EquipmentClientInfo.Layer.leatherDyeable(Identifier.withDefaultNamespace(name), false));
135
	}
136
137
	@Override
138
	public CompletableFuture<?> run(final CachedOutput cache) {
139
		Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentAssets = new HashMap<>();
140
		bootstrap((id, asset) -> {
141
			if (equipmentAssets.putIfAbsent(id, asset) != null) {
142
				throw new IllegalStateException("Tried to register equipment asset twice for id: " + id);
143
			}
144
		});
145
		return DataProvider.saveAll(cache, EquipmentClientInfo.CODEC, this.pathProvider::json, equipmentAssets);
146
	}
147
148
	@Override
149
	public String getName() {
150
		return "Equipment Asset Definitions";
151
	}
152
}
153

Decompiled Minecraft 26.3 source of EquipmentAssetProvider (net/minecraft/client/data/models/EquipmentAssetProvider.java) with Mojang official mappings, stored verbatim on the site.