Jump to content

[1.12] [Solved, May Need Checking] Layering Banner onto Custom Shield


mysticalherobine

Recommended Posts

Okay, so ignore everything beneath the end of the edit, it's now useless. What I did was created my own version of the TileEntityItemStackRenderer in Minecraft, EXCEPT that it adds an if statement for my shield. It provides the exact same functionality as the vanilla one, overwritting it's instance using:

public static void init()
    {
        for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
        {
            SHULKER_BOXES[enumdyecolor.getMetadata()] = new TileEntityShulkerBox(enumdyecolor);
        }

        TileEntityItemStackRenderer.instance = new TileEntityItemStackRendererImpl();
    }

In my own class! Now I'm pretty sure this will break if other mods attempt the same thing, so maybe I should make an API allowing other mods to hook into this, since it makes shield rendering SUPER, and I mean SUPER easy. Should this be a thing, or is it to much?

 

=== END OF EDIT ============

 

 

Hey there! I'm trying to figure out how to layer a banner texture, similar to how Minecraft does it already. I've come to the conclusion that creating an IBakedModel in replace of the default one is best, which turned into this
 

public class ModelShieldEmerald extends ModelBaker implements IBakedModel
{
	private ModelShieldEmerald.ItemOverride itemOverride;

	public ModelShieldEmerald()
	{
		itemOverride = new ModelShieldEmerald.ItemOverride(Collections.EMPTY_LIST);
	}

	public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
	{
		List<BakedQuad> list = baseModel.getQuads(state, side, rand);
		System.out.println("Start");
		for (BakedQuad quad : list)
		{
			int[] data = quad.getVertexData();
			System.out.println(quad.getFormat().toString());
		}
		return baseModel.getQuads(state, side, rand);
	}

	public boolean isAmbientOcclusion()
	{
		return baseModel.isAmbientOcclusion();
	}

	public boolean isGui3d()
	{
		return baseModel.isGui3d();
	}

	public boolean isBuiltInRenderer()
	{
		return baseModel.isBuiltInRenderer();
	}

	public TextureAtlasSprite getParticleTexture()
	{
		return baseModel.getParticleTexture();
	}

	public ItemOverrideList getOverrides()
	{
		return itemOverride;
	}

	public Pair<? extends IBakedModel, Matrix4f> handlePerspective(
			ItemCameraTransforms.TransformType cameraTransformType)
	{
		return Pair.of(this, baseModel.handlePerspective(cameraTransformType).getRight());
	}

	public static class ItemOverride extends ItemOverrideList
	{
		public ItemOverride(List<net.minecraft.client.renderer.block.model.ItemOverride> overridesIn)
		{
			super(overridesIn);
		}

		public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world,
				@Nullable EntityLivingBase entity)
		{
			if (!stack.hasTagCompound())
				return originalModel;
			return (IBakedModel) new ModelShieldEmerald().setBaseModel(originalModel);
		}
	}
}

I'm unsure of how to accomplish this, I really don't understand BakedQuads yet. But the other way, which seems impossible of doing is to go along the lines of what Minecraft does (except it doesn't work how I would expect it)

The vanilla code goes from  net.minecraft.client.renderer.RenderItem#renderItem(ItemStack, IBakedModel)

public void renderItem(ItemStack stack, IBakedModel model)
    {
        if (!stack.isEmpty())
        {
            GlStateManager.pushMatrix();
            GlStateManager.translate(-0.5F, -0.5F, -0.5F);

            if (model.isBuiltInRenderer())
            {
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                GlStateManager.enableRescaleNormal();
                TileEntityItemStackRenderer.instance.renderByItem(stack);
            }
            else
            {
                this.renderModel(model, stack);

                if (stack.hasEffect())
                {
                    this.renderEffect(model);
                }
            }

            GlStateManager.popMatrix();
        }
    }

to the TileEntityItemStackRenderer#renderByItem(ItemStack) - I think that is what it is doing... From there the things are all hard coded, but the shield is rendered as such within that class

if (item == Items.SHIELD)
        {
            if (p_192838_1_.getSubCompound("BlockEntityTag") != null)
            {
                this.banner.setItemValues(p_192838_1_, true);
                Minecraft.getMinecraft().getTextureManager().bindTexture(BannerTextures.SHIELD_DESIGNS.getResourceLocation(this.banner.getPatternResourceLocation(), this.banner.getPatternList(), this.banner.getColorList()));
            }
            else
            {
                Minecraft.getMinecraft().getTextureManager().bindTexture(BannerTextures.SHIELD_BASE_TEXTURE);
            }

            GlStateManager.pushMatrix();
            GlStateManager.scale(1.0F, -1.0F, -1.0F);
            this.modelShield.render();
            GlStateManager.popMatrix();
        }

I'm really not sure what to do from here... I could attempt to layer the banner texture over top using UVs somehow (another topic I'm not sure how to accomplish) or get the item to correctly render similar to the Vanilla code. I have attempted the second option, but with odd results, meaning the shield doesn't render where it should have, nor is it rendering as the actual item.

An help is appreciated, I can provide more details if necessary

Edited by mysticalherobine
Link to comment
Share on other sites

  • 2 weeks later...

BUMP, So I've gotten it working and all, but I fear for compatibility, what if another mod replaces the instance of the TileEntityItemStackRenderer? I've tried using an ItemStackTESR, but it deprecated and doesn't allow you to pass and item to check it's NBTCompounds. So I'm at a loss if I should stick to overwriting the default TileEntityItemStackRenderer, or somehow dealing with baked quads and all the "great" stuff.

Edited by mysticalherobine
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.