SingleFile .java

net.minecraft.client.renderer.texture.atlas.sources.SingleFile (record): members: resourceId, spriteId, run, MAP_CODEC, LOGGER, codec. strings: "resource".

net.minecraft.client.renderer.texture.atlas.sourcesrecord45 linesclient1.6 KB

Implements

API Surface (2)

void run(final ResourceManager resourceManager, final SpriteSource.Output output)
MapCodec<SingleFile> codec()

Fields & Constants (2)

LOGGER
MAP_CODEC

String literals (2)

"resource"
"sprite"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SingleFile.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.texture.atlas.sources;
2
3
import com.mojang.logging.LogUtils;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.Optional;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import net.minecraft.client.renderer.texture.atlas.SpriteSource;
10
import net.minecraft.resources.Identifier;
11
import net.minecraft.server.packs.resources.Resource;
12
import net.minecraft.server.packs.resources.ResourceManager;
13
import org.slf4j.Logger;
14
15
@Environment(EnvType.CLIENT)
16
public record SingleFile(Identifier resourceId, Optional<Identifier> spriteId) implements SpriteSource {
17
	private static final Logger LOGGER = LogUtils.getLogger();
18
	public static final MapCodec<SingleFile> MAP_CODEC = RecordCodecBuilder.mapCodec(
19
		i -> i.group(
20
				Identifier.CODEC.fieldOf("resource").forGetter(SingleFile::resourceId), Identifier.CODEC.optionalFieldOf("sprite").forGetter(SingleFile::spriteId)
21
			)
22
			.apply(i, SingleFile::new)
23
	);
24
25
	public SingleFile(final Identifier resourceId) {
26
		this(resourceId, Optional.empty());
27
	}
28
29
	@Override
30
	public void run(final ResourceManager resourceManager, final SpriteSource.Output output) {
31
		Identifier fullResourceId = TEXTURE_ID_CONVERTER.idToFile(this.resourceId);
32
		Optional<Resource> resource = resourceManager.getResource(fullResourceId);
33
		if (resource.isPresent()) {
34
			output.add(this.spriteId.orElse(this.resourceId), resource.get());
35
		} else {
36
			LOGGER.warn("Missing sprite: {}", fullResourceId);
37
		}
38
	}
39
40
	@Override
41
	public MapCodec<SingleFile> codec() {
42
		return MAP_CODEC;
43
	}
44
}
45

Decompiled Minecraft 26.3 source of SingleFile (net/minecraft/client/renderer/texture/atlas/sources/SingleFile.java) with Mojang official mappings, stored verbatim on the site.