Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.magistuarmory.client.render.tileentity.HeraldryItemStackRenderer Maven / Gradle / Ivy
package com.magistuarmory.client.render.tileentity;
import com.magistuarmory.client.render.model.ModModels;
import com.magistuarmory.client.render.model.item.MedievalShieldModel;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.datafixers.util.Pair;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
import net.minecraft.world.level.block.entity.BannerPattern;
import java.util.List;
@Environment(EnvType.CLIENT)
public class HeraldryItemStackRenderer extends BlockEntityWithoutLevelRenderer
{
private Model model;
private final ResourceLocation location;
private final ResourceLocation locationPattern;
private final ResourceLocation locationNoPattern;
private final String patternsDirectory;
public HeraldryItemStackRenderer(String id, ResourceLocation location)
{
super(Minecraft.m_91087_().m_167982_(), Minecraft.m_91087_().m_167973_());
this.location = location;
this.locationPattern = new ResourceLocation(location.m_135827_(), "entity/" + id + "_pattern");
this.locationNoPattern = new ResourceLocation(location.m_135827_(), "entity/" + id + "_nopattern");
this.patternsDirectory = "entity/" + location.m_135815_() + "/";
}
public void loadModel(EntityModelSet context)
{
this.model = new MedievalShieldModel(context.m_171103_(ModModels.createLocation(this.location)));
}
@Override
public void m_108829_(ItemStack stack, ItemTransforms.TransformType transform, PoseStack pose, MultiBufferSource buffer, int p, int overlay)
{
if (this.model instanceof MedievalShieldModel shieldmodel)
{
boolean flag = BlockItem.m_186336_(stack) != null;
pose.m_85836_();
pose.m_85841_(1.0F, -1.0F, -1.0F);
Material material = flag ? new Material(Sheets.f_110738_, locationPattern) : new Material(Sheets.f_110738_, locationNoPattern);
VertexConsumer vertexconsumer = material.m_119204_().m_118381_(ItemRenderer.m_115222_(buffer, this.model.m_103119_(material.m_119193_()), true, stack.m_41790_()));
shieldmodel.handle().m_104306_(pose, vertexconsumer, p, overlay, 1.0F, 1.0F, 1.0F, 1.0F);
if (flag)
{
List, DyeColor>> list = BannerBlockEntity.m_58484_(ShieldItem.m_43102_(stack), BannerBlockEntity.m_58487_(stack));
this.renderPatterns(pose, buffer, p, overlay, shieldmodel.plate(), material, list, stack.m_41790_());
}
else
{
shieldmodel.plate().m_104306_(pose, vertexconsumer, p, overlay, 1.0F, 1.0F, 1.0F, 1.0F);
}
pose.m_85849_();
}
}
public void renderPatterns(PoseStack pose, MultiBufferSource buffer, int p, int overlay, ModelPart part, Material basematerial, List, DyeColor>> list, boolean hasfoil)
{
part.m_104301_(pose, basematerial.m_119197_(buffer, RenderType::m_110452_, hasfoil), p, overlay);
for(int i = 0; i < 17 && i < list.size(); ++i)
{
Pair, DyeColor> pair = list.get(i);
float[] color = pair.getSecond().m_41068_();
if (pair.getFirst().m_203543_().isPresent())
{
Material material = new Material(Sheets.f_110738_, new ResourceLocation(this.location.m_135827_(), this.patternsDirectory + pair.getFirst().m_203543_().get().m_135782_().m_135815_()));
part.m_104306_(pose, material.m_119197_(buffer, RenderType::m_110482_, hasfoil), p, overlay, color[0], color[1], color[2], 1.0F);
}
}
}
}