PalettedPermutations.java
net.minecraft.client.renderer.texture.atlas.sources.PalettedPermutations
信息
- 全限定名:net.minecraft.client.renderer.texture.atlas.sources.PalettedPermutations
- 类型:public record
- 包:net.minecraft.client.renderer.texture.atlas.sources
- 源码路径:src/main/java/net/minecraft/client/renderer/texture/atlas/sources/PalettedPermutations.java
- 起始行号:L34
- 实现:SpriteSource
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
DEFAULT_SEPARATOR- 类型:
String - 修饰符:
public static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
MAP_CODEC- 类型:
MapCodec<PalettedPermutations> - 修饰符:
public static final - 源码定位:
L38 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.renderer.texture.atlas.sources.PalettedPermutations.PalettedSpriteSupplier- 类型:
record - 修饰符:
private - 源码定位:
L136 - 说明:
TODO
- 类型:
构造器
public PalettedPermutations(List<Identifier> textures, Identifier paletteKey, Map<String,Identifier> permutations) @ L48
- 构造器名:PalettedPermutations
- 源码定位:L48
- 修饰符:public
参数:
- textures: List
- paletteKey: Identifier
- permutations: Map<String,Identifier>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void run(ResourceManager resourceManager, SpriteSource.Output output) @ L52
- 方法名:run
- 源码定位:L52
- 返回类型:void
- 修饰符:public
参数:
- resourceManager: ResourceManager
- output: SpriteSource.Output
说明:
TODO
private static IntUnaryOperator createPaletteMapping(int[] keys, int[] values) @ L79
- 方法名:createPaletteMapping
- 源码定位:L79
- 返回类型:IntUnaryOperator
- 修饰符:private static
参数:
- keys: int[]
- values: int[]
说明:
TODO
private static int[] loadPaletteEntryFromImage(ResourceManager resourceManager, Identifier location) @ L107
- 方法名:loadPaletteEntryFromImage
- 源码定位:L107
- 返回类型:int[]
- 修饰符:private static
参数:
- resourceManager: ResourceManager
- location: Identifier
说明:
TODO
public MapCodec<PalettedPermutations> codec() @ L130
- 方法名:codec
- 源码定位:L130
- 返回类型:MapCodec
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public record PalettedPermutations(List<Identifier> textures, Identifier paletteKey, Map<String, Identifier> permutations, String separator)
implements SpriteSource {
private static final Logger LOGGER = LogUtils.getLogger();
public static final String DEFAULT_SEPARATOR = "_";
public static final MapCodec<PalettedPermutations> MAP_CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(
Codec.list(Identifier.CODEC).fieldOf("textures").forGetter(PalettedPermutations::textures),
Identifier.CODEC.fieldOf("palette_key").forGetter(PalettedPermutations::paletteKey),
Codec.unboundedMap(Codec.STRING, Identifier.CODEC).fieldOf("permutations").forGetter(PalettedPermutations::permutations),
Codec.STRING.optionalFieldOf("separator", "_").forGetter(PalettedPermutations::separator)
)
.apply(i, PalettedPermutations::new)
);
public PalettedPermutations(List<Identifier> textures, Identifier paletteKey, Map<String, Identifier> permutations) {
this(textures, paletteKey, permutations, "_");
}
@Override
public void run(ResourceManager resourceManager, SpriteSource.Output output) {
Supplier<int[]> paletteKeySupplier = Suppliers.memoize(() -> loadPaletteEntryFromImage(resourceManager, this.paletteKey));
Map<String, Supplier<IntUnaryOperator>> palettes = new HashMap<>();
this.permutations
.forEach(
(suffix, palette) -> palettes.put(
suffix, Suppliers.memoize(() -> createPaletteMapping(paletteKeySupplier.get(), loadPaletteEntryFromImage(resourceManager, palette)))
)
);
for (Identifier textureLocation : this.textures) {
Identifier textureId = TEXTURE_ID_CONVERTER.idToFile(textureLocation);
Optional<Resource> resource = resourceManager.getResource(textureId);
if (resource.isEmpty()) {
LOGGER.warn("Unable to find texture {}", textureId);
} else {
LazyLoadedImage baseImage = new LazyLoadedImage(textureId, resource.get(), palettes.size());
for (Entry<String, Supplier<IntUnaryOperator>> entry : palettes.entrySet()) {
Identifier permutationLocation = textureLocation.withSuffix(this.separator + entry.getKey());
output.add(permutationLocation, new PalettedPermutations.PalettedSpriteSupplier(baseImage, entry.getValue(), permutationLocation));
}
}
}
}
private static IntUnaryOperator createPaletteMapping(int[] keys, int[] values) {
if (values.length != keys.length) {
LOGGER.warn("Palette mapping has different sizes: {} and {}", keys.length, values.length);
throw new IllegalArgumentException();
} else {
Int2IntMap palette = new Int2IntOpenHashMap(values.length);
for (int i = 0; i < keys.length; i++) {
int key = keys[i];
if (ARGB.alpha(key) != 0) {
palette.put(ARGB.transparent(key), values[i]);
}
}
return pixel -> {
int pixelAlpha = ARGB.alpha(pixel);
if (pixelAlpha == 0) {
return pixel;
} else {
int pixelRGB = ARGB.transparent(pixel);
int value = palette.getOrDefault(pixelRGB, ARGB.opaque(pixelRGB));
int valueAlpha = ARGB.alpha(value);
return ARGB.color(pixelAlpha * valueAlpha / 255, value);
}
};
}
}
private static int[] loadPaletteEntryFromImage(ResourceManager resourceManager, Identifier location) {
Optional<Resource> resource = resourceManager.getResource(TEXTURE_ID_CONVERTER.idToFile(location));
if (resource.isEmpty()) {
LOGGER.error("Failed to load palette image {}", location);
throw new IllegalArgumentException();
} else {
try {
int[] var5;
try (
InputStream is = resource.get().open();
NativeImage image = NativeImage.read(is);
) {
var5 = image.getPixels();
}
return var5;
} catch (Exception var11) {
LOGGER.error("Couldn't load texture {}", location, var11);
throw new IllegalArgumentException();
}
}
}
@Override
public MapCodec<PalettedPermutations> codec() {
return MAP_CODEC;
}
@OnlyIn(Dist.CLIENT)
private record PalettedSpriteSupplier(LazyLoadedImage baseImage, Supplier<IntUnaryOperator> palette, Identifier permutationLocation)
implements SpriteSource.DiscardableLoader {
@Override
public @Nullable SpriteContents get(SpriteResourceLoader loader) {
Object var3;
try {
NativeImage image = this.baseImage.get().mappedCopy(this.palette.get());
return new SpriteContents(this.permutationLocation, new FrameSize(image.getWidth(), image.getHeight()), image);
} catch (IllegalArgumentException | IOException var7) {
PalettedPermutations.LOGGER.error("unable to apply palette to {}", this.permutationLocation, var7);
var3 = null;
} finally {
this.baseImage.release();
}
return (SpriteContents)var3;
}
@Override
public void discard() {
this.baseImage.release();
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
NativeImage.read()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
SpriteContents()
- 引用位置:
-
- 引用位置:
参数/实现
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
LazyLoadedImage()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
FrameSize()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.alpha(), ARGB.color(), ARGB.opaque(), ARGB.transparent()
- 引用位置: