Skip to content

Commit

Permalink
Extract Minecraft class reference from CustomTextureData
Browse files Browse the repository at this point in the history
  • Loading branch information
Justsnoopy30 committed Nov 27, 2021
1 parent fa90159 commit 7e19cd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -184,7 +185,16 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) {
AbstractTexture customTexture = new NativeImageBackedCustomTexture((CustomTextureData.PngData) textureData);
customTextureIds.put(samplerName, customTexture::getId);
} else if (textureData instanceof CustomTextureData.ResourceData) {
customTextureIds.put(samplerName, ((CustomTextureData.ResourceData) textureData)::getGlId);
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(((CustomTextureData.ResourceData) textureData).getResourceLocation());

IntSupplier glId;
if (texture != null) {
glId = texture::getId;
} else {
// TODO: Should we give something else if the texture isn't there? This will need some thought
glId = MissingTextureAtlasSprite.getTexture()::getId;
}
customTextureIds.put(samplerName, glId);
}
} catch (IOException e) {
Iris.logger.error("Unable to parse the image data for the custom texture on sampler " + samplerName, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ public ResourceData(ResourceLocation resourceLocation) {
this.resourceLocation = resourceLocation;
}

public int getGlId() {
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(resourceLocation);
if (texture != null) {
return texture.getId();
} else {
// TODO: Should we give something else if the texture isn't there? This will need some thought
return MissingTextureAtlasSprite.getTexture().getId();
}
public ResourceLocation getResourceLocation() {
return resourceLocation;
}
}

Expand Down

0 comments on commit 7e19cd4

Please sign in to comment.