2025-11-24 22:52:51 +03:00

52 lines
1.9 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
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.AddressMode;
import com.mojang.blaze3d.textures.FilterMode;
import com.mojang.blaze3d.textures.TextureFormat;
import java.io.IOException;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureContents;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;
public abstract class ReloadableTexture
extends AbstractTexture {
private final Identifier resourceId;
public ReloadableTexture(Identifier resourceId) {
this.resourceId = resourceId;
}
public Identifier resourceId() {
return this.resourceId;
}
public void apply(TextureContents contents) {
boolean clamp = contents.clamp();
boolean blur = contents.blur();
AddressMode addressMode = clamp ? AddressMode.CLAMP_TO_EDGE : AddressMode.REPEAT;
FilterMode minMag = blur ? FilterMode.LINEAR : FilterMode.NEAREST;
this.sampler = RenderSystem.getSamplerCache().getSampler(addressMode, addressMode, minMag, minMag, false);
try (NativeImage image = contents.image();){
this.doLoad(image);
}
}
protected void doLoad(NativeImage image) {
GpuDevice device = RenderSystem.getDevice();
this.close();
this.texture = device.createTexture(this.resourceId::toString, 5, TextureFormat.RGBA8, image.getWidth(), image.getHeight(), 1, 1);
this.textureView = device.createTextureView(this.texture);
device.createCommandEncoder().writeToTexture(this.texture, image);
}
public abstract TextureContents loadContents(ResourceManager var1) throws IOException;
}