76 lines
2.6 KiB
Java
76 lines
2.6 KiB
Java
package net.minecraft.client.resources.model;
|
|
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
import java.util.Comparator;
|
|
import java.util.Objects;
|
|
import java.util.function.Function;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
import net.minecraft.client.renderer.RenderType;
|
|
import net.minecraft.client.renderer.entity.ItemRenderer;
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class Material {
|
|
public static final Comparator<Material> COMPARATOR = Comparator.comparing(Material::atlasLocation).thenComparing(Material::texture);
|
|
private final ResourceLocation atlasLocation;
|
|
private final ResourceLocation texture;
|
|
@Nullable
|
|
private RenderType renderType;
|
|
|
|
public Material(ResourceLocation atlasLocation, ResourceLocation texture) {
|
|
this.atlasLocation = atlasLocation;
|
|
this.texture = texture;
|
|
}
|
|
|
|
public ResourceLocation atlasLocation() {
|
|
return this.atlasLocation;
|
|
}
|
|
|
|
public ResourceLocation texture() {
|
|
return this.texture;
|
|
}
|
|
|
|
public TextureAtlasSprite sprite() {
|
|
return (TextureAtlasSprite)Minecraft.getInstance().getTextureAtlas(this.atlasLocation()).apply(this.texture());
|
|
}
|
|
|
|
public RenderType renderType(Function<ResourceLocation, RenderType> renderTypeGetter) {
|
|
if (this.renderType == null) {
|
|
this.renderType = (RenderType)renderTypeGetter.apply(this.atlasLocation);
|
|
}
|
|
|
|
return this.renderType;
|
|
}
|
|
|
|
public VertexConsumer buffer(MultiBufferSource bufferSource, Function<ResourceLocation, RenderType> renderTypeGetter) {
|
|
return this.sprite().wrap(bufferSource.getBuffer(this.renderType(renderTypeGetter)));
|
|
}
|
|
|
|
public VertexConsumer buffer(MultiBufferSource bufferSource, Function<ResourceLocation, RenderType> renderTypeGetter, boolean noEntity, boolean withGlint) {
|
|
return this.sprite().wrap(ItemRenderer.getFoilBuffer(bufferSource, this.renderType(renderTypeGetter), noEntity, withGlint));
|
|
}
|
|
|
|
public boolean equals(Object object) {
|
|
if (this == object) {
|
|
return true;
|
|
} else if (object != null && this.getClass() == object.getClass()) {
|
|
Material material = (Material)object;
|
|
return this.atlasLocation.equals(material.atlasLocation) && this.texture.equals(material.texture);
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public int hashCode() {
|
|
return Objects.hash(new Object[]{this.atlasLocation, this.texture});
|
|
}
|
|
|
|
public String toString() {
|
|
return "Material{atlasLocation=" + this.atlasLocation + ", texture=" + this.texture + "}";
|
|
}
|
|
}
|