Class Material

java.lang.Object
codechicken.lib.gui.modular.sprite.Material

public class Material extends Object
This is similar to Minecraft's Material This contains the essential data required to render an atlas sprite.

The primary purpose of this class is to make porting between MC versions easier. It also allows for loading sprites from a custom texture atlas. Minecraft's material class can only load from vanilla atlases.

Created by brandon3055 on 20/08/2023

  • Constructor Summary

    Constructors
    Constructor
    Description
    Material(net.minecraft.resources.ResourceLocation atlasLocation, net.minecraft.resources.ResourceLocation texture, Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.texture.TextureAtlasSprite> spriteFunction)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.resources.ResourceLocation
     
    com.mojang.blaze3d.vertex.VertexConsumer
    buffer(net.minecraft.client.renderer.MultiBufferSource buffers, Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.RenderType> typeBuilder)
    Convenience method to create a vertex consumer using this materials render type.
    static Material
    fromAtlas(net.minecraft.resources.ResourceLocation atlasLocation, String texture)
    Convenient method for getting a material from a vanilla texture atlas.
    static @Nullable Material
    fromSprite(@Nullable net.minecraft.client.renderer.texture.TextureAtlasSprite sprite)
    Create a material from an existing sprite.
    net.minecraft.client.resources.model.Material
     
    net.minecraft.client.renderer.RenderType
    renderType(Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.RenderType> typeBuilder)
    Returns the cached render type for this material.
    net.minecraft.client.renderer.texture.TextureAtlasSprite
     
    net.minecraft.resources.ResourceLocation
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Material

      public Material(net.minecraft.resources.ResourceLocation atlasLocation, net.minecraft.resources.ResourceLocation texture, Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.texture.TextureAtlasSprite> spriteFunction)
  • Method Details

    • atlasLocation

      public net.minecraft.resources.ResourceLocation atlasLocation()
    • texture

      public net.minecraft.resources.ResourceLocation texture()
    • sprite

      public net.minecraft.client.renderer.texture.TextureAtlasSprite sprite()
    • renderType

      public net.minecraft.client.renderer.RenderType renderType(Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.RenderType> typeBuilder)
      Returns the cached render type for this material. The supplied function will be used to create the render type the first time this method is called.
      Parameters:
      typeBuilder - a function that will be used to create the render type if it does not already exist.
      Returns:
      The render type for this material.
    • buffer

      public com.mojang.blaze3d.vertex.VertexConsumer buffer(net.minecraft.client.renderer.MultiBufferSource buffers, Function<net.minecraft.resources.ResourceLocation,net.minecraft.client.renderer.RenderType> typeBuilder)
      Convenience method to create a vertex consumer using this materials render type.
      Parameters:
      buffers - bugger source.
      typeBuilder - a function that will be used to create the render type if it does not already exist.
    • getVanillaMat

      public net.minecraft.client.resources.model.Material getVanillaMat()
    • fromAtlas

      public static Material fromAtlas(net.minecraft.resources.ResourceLocation atlasLocation, String texture)
      Convenient method for getting a material from a vanilla texture atlas.
      Returns:
      an un-cached material from a vanilla atlas.
    • fromSprite

      @Nullable public static @Nullable Material fromSprite(@Nullable @Nullable net.minecraft.client.renderer.texture.TextureAtlasSprite sprite)
      Create a material from an existing sprite. Note: This will only work with sprites from a vanilla atlas.