package net.minecraft.client.renderer.texture; import com.mojang.blaze3d.textures.AddressMode; import com.mojang.blaze3d.textures.FilterMode; import com.mojang.blaze3d.textures.GpuTexture; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.TriState; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public abstract class AbstractTexture implements AutoCloseable { @Nullable protected GpuTexture texture; protected boolean defaultBlur; public void setClamp(boolean clamp) { if (this.texture == null) { throw new IllegalStateException("Texture does not exist, can't change its clamp before something initializes it"); } else { this.texture.setAddressMode(clamp ? AddressMode.CLAMP_TO_EDGE : AddressMode.REPEAT); } } public void setFilter(TriState blur, boolean mipmap) { this.setFilter(blur.toBoolean(this.defaultBlur), mipmap); } /** * @param mipmap {@code true} if a mipmap is being used (mip level is greater than 0) */ public void setFilter(boolean blur, boolean mipmap) { if (this.texture == null) { throw new IllegalStateException("Texture does not exist, can't get change its filter before something initializes it"); } else { this.texture.setTextureFilter(blur ? FilterMode.LINEAR : FilterMode.NEAREST, mipmap); } } public void close() { if (this.texture != null) { this.texture.close(); this.texture = null; } } public GpuTexture getTexture() { if (this.texture == null) { throw new IllegalStateException("Texture does not exist, can't get it before something initializes it"); } else { return this.texture; } } }