TextureManager.java

net.minecraft.client.renderer.texture.TextureManager

信息

  • 全限定名:net.minecraft.client.renderer.texture.TextureManager
  • 类型:public class
  • 包:net.minecraft.client.renderer.texture
  • 源码路径:src/main/java/net/minecraft/client/renderer/texture/TextureManager.java
  • 起始行号:L30
  • 实现:PreparableReloadListener, AutoCloseable
  • 职责:

    TODO

字段/常量

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L31
    • 说明:

      TODO

  • INTENTIONAL_MISSING_TEXTURE

    • 类型: Identifier
    • 修饰符: public static final
    • 源码定位: L32
    • 说明:

      TODO

  • byPath

    • 类型: Map<Identifier,AbstractTexture>
    • 修饰符: private final
    • 源码定位: L33
    • 说明:

      TODO

  • tickableTextures

    • 类型: Set<TickableTexture>
    • 修饰符: private final
    • 源码定位: L34
    • 说明:

      TODO

  • resourceManager

    • 类型: ResourceManager
    • 修饰符: private final
    • 源码定位: L35
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.renderer.texture.TextureManager.PendingReload
    • 类型: record
    • 修饰符: private
    • 源码定位: L191
    • 说明:

      TODO

构造器

public TextureManager(ResourceManager resourceManager) @ L37

  • 构造器名:TextureManager
  • 源码定位:L37
  • 修饰符:public

参数:

  • resourceManager: ResourceManager

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void registerAndLoad(Identifier textureId, ReloadableTexture texture) @ L43

  • 方法名:registerAndLoad
  • 源码定位:L43
  • 返回类型:void
  • 修饰符:public

参数:

  • textureId: Identifier
  • texture: ReloadableTexture

说明:

TODO

private TextureContents loadContentsSafe(Identifier textureId, ReloadableTexture texture) @ L57

  • 方法名:loadContentsSafe
  • 源码定位:L57
  • 返回类型:TextureContents
  • 修饰符:private

参数:

  • textureId: Identifier
  • texture: ReloadableTexture

说明:

TODO

public void registerForNextReload(Identifier location) @ L66

  • 方法名:registerForNextReload
  • 源码定位:L66
  • 返回类型:void
  • 修饰符:public

参数:

  • location: Identifier

说明:

TODO

public void register(Identifier location, AbstractTexture texture) @ L70

  • 方法名:register
  • 源码定位:L70
  • 返回类型:void
  • 修饰符:public

参数:

  • location: Identifier
  • texture: AbstractTexture

说明:

TODO

private void safeClose(Identifier id, AbstractTexture texture) @ L83

  • 方法名:safeClose
  • 源码定位:L83
  • 返回类型:void
  • 修饰符:private

参数:

  • id: Identifier
  • texture: AbstractTexture

说明:

TODO

public AbstractTexture getTexture(Identifier location) @ L93

  • 方法名:getTexture
  • 源码定位:L93
  • 返回类型:AbstractTexture
  • 修饰符:public

参数:

  • location: Identifier

说明:

TODO

public void tick() @ L104

  • 方法名:tick
  • 源码定位:L104
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void release(Identifier location) @ L110

  • 方法名:release
  • 源码定位:L110
  • 返回类型:void
  • 修饰符:public

参数:

  • location: Identifier

说明:

TODO

public void close() @ L117

  • 方法名:close
  • 源码定位:L117
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public CompletableFuture<Void> reload(PreparableReloadListener.SharedState currentReload, Executor taskExecutor, PreparableReloadListener.PreparationBarrier preparationBarrier, Executor reloadExecutor) @ L124

  • 方法名:reload
  • 源码定位:L124
  • 返回类型:CompletableFuture
  • 修饰符:public

参数:

  • currentReload: PreparableReloadListener.SharedState
  • taskExecutor: Executor
  • preparationBarrier: PreparableReloadListener.PreparationBarrier
  • reloadExecutor: Executor

说明:

TODO

public void dumpAllSheets(Path targetDir) @ L149

  • 方法名:dumpAllSheets
  • 源码定位:L149
  • 返回类型:void
  • 修饰符:public

参数:

  • targetDir: Path

说明:

TODO

private static TextureContents loadContents(ResourceManager manager, Identifier location, ReloadableTexture texture) @ L168

  • 方法名:loadContents
  • 源码定位:L168
  • 返回类型:TextureContents
  • 修饰符:private static

参数:

  • manager: ResourceManager
  • location: Identifier
  • texture: ReloadableTexture

说明:

TODO

private static TextureManager.PendingReload scheduleLoad(ResourceManager manager, Identifier location, ReloadableTexture texture, Executor executor) @ L180

  • 方法名:scheduleLoad
  • 源码定位:L180
  • 返回类型:TextureManager.PendingReload
  • 修饰符:private static

参数:

  • manager: ResourceManager
  • location: Identifier
  • texture: ReloadableTexture
  • executor: Executor

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class TextureManager implements PreparableReloadListener, AutoCloseable {
    private static final Logger LOGGER = LogUtils.getLogger();
    public static final Identifier INTENTIONAL_MISSING_TEXTURE = Identifier.withDefaultNamespace("");
    private final Map<Identifier, AbstractTexture> byPath = new HashMap<>();
    private final Set<TickableTexture> tickableTextures = new HashSet<>();
    private final ResourceManager resourceManager;
 
    public TextureManager(ResourceManager resourceManager) {
        this.resourceManager = resourceManager;
        NativeImage checkerboard = MissingTextureAtlasSprite.generateMissingImage();
        this.register(MissingTextureAtlasSprite.getLocation(), new DynamicTexture(() -> "(intentionally-)Missing Texture", checkerboard));
    }
 
    public void registerAndLoad(Identifier textureId, ReloadableTexture texture) {
        try {
            texture.apply(this.loadContentsSafe(textureId, texture));
        } catch (Throwable var6) {
            CrashReport report = CrashReport.forThrowable(var6, "Uploading texture");
            CrashReportCategory category = report.addCategory("Uploaded texture");
            category.setDetail("Resource location", texture.resourceId());
            category.setDetail("Texture id", textureId);
            throw new ReportedException(report);
        }
 
        this.register(textureId, texture);
    }
 
    private TextureContents loadContentsSafe(Identifier textureId, ReloadableTexture texture) {
        try {
            return loadContents(this.resourceManager, textureId, texture);
        } catch (Exception var4) {
            LOGGER.error("Failed to load texture {} into slot {}", texture.resourceId(), textureId, var4);
            return TextureContents.createMissing();
        }
    }
 
    public void registerForNextReload(Identifier location) {
        this.register(location, new SimpleTexture(location));
    }
 
    public void register(Identifier location, AbstractTexture texture) {
        AbstractTexture prev = this.byPath.put(location, texture);
        if (prev != texture) {
            if (prev != null) {
                this.safeClose(location, prev);
            }
 
            if (texture instanceof TickableTexture tickableTexture) {
                this.tickableTextures.add(tickableTexture);
            }
        }
    }
 
    private void safeClose(Identifier id, AbstractTexture texture) {
        this.tickableTextures.remove(texture);
 
        try {
            texture.close();
        } catch (Exception var4) {
            LOGGER.warn("Failed to close texture {}", id, var4);
        }
    }
 
    public AbstractTexture getTexture(Identifier location) {
        AbstractTexture textureObject = this.byPath.get(location);
        if (textureObject != null) {
            return textureObject;
        } else {
            SimpleTexture texture = new SimpleTexture(location);
            this.registerAndLoad(location, texture);
            return texture;
        }
    }
 
    public void tick() {
        for (TickableTexture tickableTexture : this.tickableTextures) {
            tickableTexture.tick();
        }
    }
 
    public void release(Identifier location) {
        AbstractTexture texture = this.byPath.remove(location);
        if (texture != null) {
            this.safeClose(location, texture);
        }
    }
 
    @Override
    public void close() {
        this.byPath.forEach(this::safeClose);
        this.byPath.clear();
        this.tickableTextures.clear();
    }
 
    @Override
    public CompletableFuture<Void> reload(
        PreparableReloadListener.SharedState currentReload,
        Executor taskExecutor,
        PreparableReloadListener.PreparationBarrier preparationBarrier,
        Executor reloadExecutor
    ) {
        ResourceManager manager = currentReload.resourceManager();
        List<TextureManager.PendingReload> reloads = new ArrayList<>();
        this.byPath.forEach((id, texture) -> {
            if (texture instanceof ReloadableTexture reloadableTexture) {
                reloads.add(scheduleLoad(manager, id, reloadableTexture, taskExecutor));
            }
        });
        return CompletableFuture.allOf(reloads.stream().map(TextureManager.PendingReload::newContents).toArray(CompletableFuture[]::new))
            .thenCompose(preparationBarrier::wait)
            .thenAcceptAsync(unused -> {
                AddRealmPopupScreen.updateCarouselImages(this.resourceManager);
 
                for (TextureManager.PendingReload reload : reloads) {
                    reload.texture.apply(reload.newContents.join());
                }
            }, reloadExecutor);
    }
 
    public void dumpAllSheets(Path targetDir) {
        try {
            Files.createDirectories(targetDir);
        } catch (IOException var3) {
            LOGGER.error("Failed to create directory {}", targetDir, var3);
            return;
        }
 
        this.byPath.forEach((location, texture) -> {
            if (texture instanceof Dumpable dumpable) {
                try {
                    dumpable.dumpContents(location, targetDir);
                } catch (Exception var5) {
                    LOGGER.error("Failed to dump texture {}", location, var5);
                }
            }
        });
    }
 
    private static TextureContents loadContents(ResourceManager manager, Identifier location, ReloadableTexture texture) throws IOException {
        try {
            return texture.loadContents(manager);
        } catch (FileNotFoundException var4) {
            if (location != INTENTIONAL_MISSING_TEXTURE) {
                LOGGER.warn("Missing resource {} referenced from {}", texture.resourceId(), location);
            }
 
            return TextureContents.createMissing();
        }
    }
 
    private static TextureManager.PendingReload scheduleLoad(ResourceManager manager, Identifier location, ReloadableTexture texture, Executor executor) {
        return new TextureManager.PendingReload(texture, CompletableFuture.supplyAsync(() -> {
            try {
                return loadContents(manager, location, texture);
            } catch (IOException var4) {
                throw new UncheckedIOException(var4);
            }
        }, executor));
    }
 
    @OnlyIn(Dist.CLIENT)
    private record PendingReload(ReloadableTexture texture, CompletableFuture<TextureContents> newContents) {
    }
}

引用的其他类