RealmsTextureManager.java
com.mojang.realmsclient.util.RealmsTextureManager
信息
- 全限定名:com.mojang.realmsclient.util.RealmsTextureManager
- 类型:public class
- 包:com.mojang.realmsclient.util
- 源码路径:src/main/java/com/mojang/realmsclient/util/RealmsTextureManager.java
- 起始行号:L21
- 职责:
TODO
字段/常量
-
TEXTURES- 类型:
Map<String,RealmsTextureManager.RealmsTexture> - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
TEMPLATE_ICON_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
内部类/嵌套类型
com.mojang.realmsclient.util.RealmsTextureManager.RealmsTexture- 类型:
record - 修饰符:
public - 源码定位:
L65 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static Identifier worldTemplate(String id, String image) @ L26
- 方法名:worldTemplate
- 源码定位:L26
- 返回类型:Identifier
- 修饰符:public static
参数:
- id: String
- image: String
说明:
TODO
private static Identifier getTexture(String id, String encodedImage) @ L30
- 方法名:getTexture
- 源码定位:L30
- 返回类型:Identifier
- 修饰符:private static
参数:
- id: String
- encodedImage: String
说明:
TODO
private static NativeImage loadImage(String encodedImage) @ L49
- 方法名:loadImage
- 源码定位:L49
- 返回类型:NativeImage
- 修饰符:private static
参数:
- encodedImage: String
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsTextureManager {
private static final Map<String, RealmsTextureManager.RealmsTexture> TEXTURES = Maps.newHashMap();
private static final Logger LOGGER = LogUtils.getLogger();
private static final Identifier TEMPLATE_ICON_LOCATION = Identifier.withDefaultNamespace("textures/gui/presets/isles.png");
public static Identifier worldTemplate(String id, @Nullable String image) {
return image == null ? TEMPLATE_ICON_LOCATION : getTexture(id, image);
}
private static Identifier getTexture(String id, String encodedImage) {
RealmsTextureManager.RealmsTexture texture = TEXTURES.get(id);
if (texture != null && texture.image().equals(encodedImage)) {
return texture.textureId;
} else {
NativeImage image = loadImage(encodedImage);
if (image == null) {
Identifier missingTexture = MissingTextureAtlasSprite.getLocation();
TEXTURES.put(id, new RealmsTextureManager.RealmsTexture(encodedImage, missingTexture));
return missingTexture;
} else {
Identifier textureId = Identifier.fromNamespaceAndPath("realms", "dynamic/" + id);
Minecraft.getInstance().getTextureManager().register(textureId, new DynamicTexture(textureId::toString, image));
TEXTURES.put(id, new RealmsTextureManager.RealmsTexture(encodedImage, textureId));
return textureId;
}
}
}
private static @Nullable NativeImage loadImage(String encodedImage) {
byte[] bytes = Base64.getDecoder().decode(encodedImage);
ByteBuffer buffer = MemoryUtil.memAlloc(bytes.length);
try {
return NativeImage.read(buffer.put(bytes).flip());
} catch (IOException var7) {
LOGGER.warn("Failed to load world image: {}", encodedImage, var7);
} finally {
MemoryUtil.memFree(buffer);
}
return null;
}
@OnlyIn(Dist.CLIENT)
public record RealmsTexture(String image, Identifier textureId) {
}
}引用的其他类
-
- 引用位置:
方法调用/返回值 - 关联成员:
NativeImage.read()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
DynamicTexture()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
MissingTextureAtlasSprite.getLocation()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Identifier.fromNamespaceAndPath(), Identifier.withDefaultNamespace()
- 引用位置: