All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.client.render.tileentity.PaviseBlockRenderer Maven / Gradle / Ivy

package com.magistuarmory.client.render.tileentity;

import com.magistuarmory.EpicKnights;
import com.magistuarmory.block.PaviseBlockEntity;
import com.magistuarmory.client.render.model.ModModels;
import com.magistuarmory.client.render.model.block.PaviseBlockModel;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.datafixers.util.Pair;
import com.mojang.math.Vector3f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.BannerBlock;
import net.minecraft.world.level.block.entity.BannerPattern;
import net.minecraft.world.level.block.state.BlockState;

import java.util.List;


@Environment(EnvType.CLIENT)
public class PaviseBlockRenderer implements BlockEntityRenderer
{
	public static String DIR_PREFIX = "entity/pavese/";
	
	PaviseBlockModel model;
	ModelPart handle;
	ModelPart plate;
	
	public PaviseBlockRenderer(BlockEntityRendererProvider.Context context)
	{
		this.model = new PaviseBlockModel(context.m_173582_(ModModels.PAVISE_BLOCK_LOCATION));
		this.handle = this.model.handle();
		this.plate = this.model.plate();
	}

	@Override
	public int m_142163_() 
	{
		return 128;
	}

	@Override
	public void render(PaviseBlockEntity pavise, float f, PoseStack pose, MultiBufferSource buffer, int p, int overlay)
	{
		pose.m_85836_();
		BlockState blockstate = pavise.m_58900_();
		pose.m_85837_(0.5F, 0.5F, 0.5F);
		float yrot = (float)(-(Integer)blockstate.m_61143_(BannerBlock.f_49007_) * 360) / 16.0F;
		pose.m_85845_(Vector3f.f_122225_.m_122240_(yrot));
		pose.m_85836_();
		pose.m_85841_(1.0F, -1.0F, -1.0F);
		boolean painted = pavise.isPainted();
		Material material = new Material(Sheets.f_110738_, new ResourceLocation(EpicKnights.ID, "entity/" + pavise.getShieldId() + (painted ? "_pattern" : "_nopattern")));
		VertexConsumer vertexconsumer = material.m_119204_().m_118381_(ItemRenderer.m_115222_(buffer, this.model.m_103119_(material.m_119193_()), true, pavise.hasFoil()));
		this.handle.m_104301_(pose, vertexconsumer, p, OverlayTexture.f_118083_);
		this.plate.m_104301_(pose, vertexconsumer, p, OverlayTexture.f_118083_);
		if (painted)
		{
			List, DyeColor>> list = pavise.getPatterns();
			renderPatterns(pose, buffer, p, OverlayTexture.f_118083_, list, this.plate, ModelBakery.f_119224_, pavise.hasFoil());
		}
		pose.m_85849_();
		pose.m_85849_();
	}

	public static void renderPatterns(PoseStack pose, MultiBufferSource buffer, int p, int overlay, List, DyeColor>> list, ModelPart part, Material basematerial, boolean hasfoil)
	{
		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(EpicKnights.ID, DIR_PREFIX + 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);
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy