44 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			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();
 | |
| 
 | |
| 		try (NativeImage nativeImage = textureContents.image()) {
 | |
| 			this.doLoad(nativeImage, bl2, bl);
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	protected void doLoad(NativeImage image, boolean blur, boolean clamp) {
 | |
| 		GpuDevice gpuDevice = RenderSystem.getDevice();
 | |
| 		this.texture = gpuDevice.createTexture(this.resourceId::toString, 5, TextureFormat.RGBA8, image.getWidth(), image.getHeight(), 1, 1);
 | |
| 		this.textureView = gpuDevice.createTextureView(this.texture);
 | |
| 		this.setFilter(blur, false);
 | |
| 		this.setClamp(clamp);
 | |
| 		gpuDevice.createCommandEncoder().writeToTexture(this.texture, image);
 | |
| 	}
 | |
| 
 | |
| 	public abstract TextureContents loadContents(ResourceManager resourceManager) throws IOException;
 | |
| }
 |