minecraft-src/net/minecraft/client/renderer/texture/ReloadableTexture.java
2025-07-04 03:45:38 +03:00

44 lines
1.5 KiB
Java

package net.minecraft.client.renderer.texture;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.GpuDevice;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.textures.TextureFormat;
import java.io.IOException;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
@Environment(EnvType.CLIENT)
public abstract class ReloadableTexture extends AbstractTexture {
private final ResourceLocation resourceId;
public ReloadableTexture(ResourceLocation resourceId) {
this.resourceId = resourceId;
}
public ResourceLocation resourceId() {
return this.resourceId;
}
public void apply(TextureContents textureContents) {
boolean bl = textureContents.clamp();
boolean bl2 = textureContents.blur();
this.defaultBlur = bl2;
try (NativeImage nativeImage = textureContents.image()) {
this.doLoad(nativeImage, bl2, bl);
}
}
private void doLoad(NativeImage image, boolean blur, boolean clamp) {
GpuDevice gpuDevice = RenderSystem.getDevice();
this.texture = gpuDevice.createTexture(this.resourceId::toString, TextureFormat.RGBA8, image.getWidth(), image.getHeight(), 1);
this.setFilter(blur, false);
this.setClamp(clamp);
gpuDevice.createCommandEncoder().writeToTexture(this.texture, image);
}
public abstract TextureContents loadContents(ResourceManager resourceManager) throws IOException;
}