44 lines
1.4 KiB
Java
44 lines
1.4 KiB
Java
package net.minecraft.client.renderer.texture;
|
|
|
|
import com.mojang.blaze3d.platform.NativeImage;
|
|
import com.mojang.blaze3d.platform.TextureUtil;
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
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;
|
|
NativeImage nativeImage = textureContents.image();
|
|
if (!RenderSystem.isOnRenderThreadOrInit()) {
|
|
RenderSystem.recordRenderCall(() -> this.doLoad(nativeImage, bl2, bl));
|
|
} else {
|
|
this.doLoad(nativeImage, bl2, bl);
|
|
}
|
|
}
|
|
|
|
private void doLoad(NativeImage image, boolean blur, boolean clamp) {
|
|
TextureUtil.prepareImage(this.getId(), 0, image.getWidth(), image.getHeight());
|
|
this.setFilter(blur, false);
|
|
this.setClamp(clamp);
|
|
image.upload(0, 0, 0, 0, 0, image.getWidth(), image.getHeight(), true);
|
|
}
|
|
|
|
public abstract TextureContents loadContents(ResourceManager resourceManager) throws IOException;
|
|
}
|