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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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