FaviconTexture.java
net.minecraft.client.gui.screens.FaviconTexture
信息
- 全限定名:net.minecraft.client.gui.screens.FaviconTexture
- 类型:public class
- 包:net.minecraft.client.gui.screens
- 源码路径:src/main/java/net/minecraft/client/gui/screens/FaviconTexture.java
- 起始行号:L14
- 实现:AutoCloseable
- 职责:
TODO
字段/常量
-
MISSING_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
textureManager- 类型:
TextureManager - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
textureLocation- 类型:
Identifier - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
texture- 类型:
DynamicTexture - 修饰符:
private - 源码定位:
L20 - 说明:
TODO
- 类型:
-
closed- 类型:
boolean - 修饰符:
private - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private FaviconTexture(TextureManager textureManager, Identifier textureLocation) @ L23
- 构造器名:FaviconTexture
- 源码定位:L23
- 修饰符:private
参数:
- textureManager: TextureManager
- textureLocation: Identifier
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static FaviconTexture forWorld(TextureManager textureManager, String levelId) @ L28
- 方法名:forWorld
- 源码定位:L28
- 返回类型:FaviconTexture
- 修饰符:public static
参数:
- textureManager: TextureManager
- levelId: String
说明:
TODO
public static FaviconTexture forServer(TextureManager textureManager, String address) @ L37
- 方法名:forServer
- 源码定位:L37
- 返回类型:FaviconTexture
- 修饰符:public static
参数:
- textureManager: TextureManager
- address: String
说明:
TODO
public void upload(NativeImage image) @ L41
- 方法名:upload
- 源码定位:L41
- 返回类型:void
- 修饰符:public
参数:
- image: NativeImage
说明:
TODO
public void clear() @ L64
- 方法名:clear
- 源码定位:L64
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public Identifier textureLocation() @ L73
- 方法名:textureLocation
- 源码定位:L73
- 返回类型:Identifier
- 修饰符:public
参数:
- 无
说明:
TODO
public void close() @ L77
- 方法名:close
- 源码定位:L77
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isClosed() @ L83
- 方法名:isClosed
- 源码定位:L83
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
private void checkOpen() @ L87
- 方法名:checkOpen
- 源码定位:L87
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class FaviconTexture implements AutoCloseable {
private static final Identifier MISSING_LOCATION = Identifier.withDefaultNamespace("textures/misc/unknown_server.png");
private static final int WIDTH = 64;
private static final int HEIGHT = 64;
private final TextureManager textureManager;
private final Identifier textureLocation;
private @Nullable DynamicTexture texture;
private boolean closed;
private FaviconTexture(TextureManager textureManager, Identifier textureLocation) {
this.textureManager = textureManager;
this.textureLocation = textureLocation;
}
public static FaviconTexture forWorld(TextureManager textureManager, String levelId) {
return new FaviconTexture(
textureManager,
Identifier.withDefaultNamespace(
"worlds/" + Util.sanitizeName(levelId, Identifier::validPathChar) + "/" + Hashing.sha1().hashUnencodedChars(levelId) + "/icon"
)
);
}
public static FaviconTexture forServer(TextureManager textureManager, String address) {
return new FaviconTexture(textureManager, Identifier.withDefaultNamespace("servers/" + Hashing.sha1().hashUnencodedChars(address) + "/icon"));
}
public void upload(NativeImage image) {
if (image.getWidth() == 64 && image.getHeight() == 64) {
try {
this.checkOpen();
if (this.texture == null) {
this.texture = new DynamicTexture(() -> "Favicon " + this.textureLocation, image);
} else {
this.texture.setPixels(image);
this.texture.upload();
}
this.textureManager.register(this.textureLocation, this.texture);
} catch (Throwable var3) {
image.close();
this.clear();
throw var3;
}
} else {
image.close();
throw new IllegalArgumentException("Icon must be 64x64, but was " + image.getWidth() + "x" + image.getHeight());
}
}
public void clear() {
this.checkOpen();
if (this.texture != null) {
this.textureManager.release(this.textureLocation);
this.texture.close();
this.texture = null;
}
}
public Identifier textureLocation() {
return this.texture != null ? this.textureLocation : MISSING_LOCATION;
}
@Override
public void close() {
this.clear();
this.closed = true;
}
public boolean isClosed() {
return this.closed;
}
private void checkOpen() {
if (this.closed) {
throw new IllegalStateException("Icon already closed");
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
DynamicTexture()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.sanitizeName()
- 引用位置: