Posted September 27, 201411 yr I'm going to begin this right at the start because I think that'd be easier to understand overall. I'm creating a method of disabling Items in certain dimensions - to facilitate the creation of magic/tech only dimensions, prevent people quarrying in the overworld, stuff like that. The method I'm currently using detects if a disabled item is in the player's inventory and disables it from being used by removing it, then creating a new ItemStack of DisabledItem with the original ItemStack stored as an NBT tag. This Item has no interesting properties and so can't be placed in the world as a block, worn as armour, used as a weapon/tool etc. What I would like to do however is to get the "stored" item to render normally, except in the inventory where I want to overlay a small padlock icon. Here is where I am having trouble, I cannot get blocks or items with custom or multi-pass renders to display properly. If anyone could give some advice on how to approach this I'd be very appreciative.
September 27, 201411 yr Hi The Item Rendering topics on this page might give useful clues. http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html I think the easiest way is probably 1) make an ItemStack of the disabled Item 2) copy the vanilla code that prepares and calls the Item renderer, and use it to call the renderer methods of the disabled Item. The hardest part will be getting your renderer to execute at the right time for multi-pass renderers; eg you might need to use one of the post-render events (eg RenderGameOverlayEvent, RenderWorldLastEvent) to render your stuff last; might need to experiment a bit. -TGG
September 27, 201411 yr Author Thanks for the advice - I've got closer (a lot closer) but I've hit a ridiculous wall - the easiest part of the whole thing, rendering basic items in the inventory doesn't work, no matter what method I use to try to do it: tesselator, GL, .renderIcon - all result in an empty looking inventory slot. If you have any ideas about what's going wrong in this, that'd be awesome package com.hilburn.dimensionguard.client; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; public class DisabledRenderer implements IItemRenderer { private static RenderItem renderItem = new RenderItem(); private static ResourceLocation lockTexture = new ResourceLocation("dimensionguard","textures/items/lock.png"); private static Minecraft mc = Minecraft.getMinecraft(); private static RenderBlocks renderBlocksIr = new RenderBlocks(); @Override public boolean handleRenderType (ItemStack item, ItemRenderType type) { switch (type) { case ENTITY: case EQUIPPED: case EQUIPPED_FIRST_PERSON: case INVENTORY: return true; default: case FIRST_PERSON_MAP: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } @Override public void renderItem (ItemRenderType type, ItemStack itemStack, Object... data) { ItemStack thisStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) itemStack.stackTagCompound.getTag("ItemStack")); boolean isInventory = type == ItemRenderType.INVENTORY; if (data.length > 1) { } Tessellator tess = Tessellator.instance; TextureManager texturemanager = mc.getTextureManager(); GL11.glPushMatrix(); Item item = thisStack.getItem(); Block block = Block.getBlockFromItem(item); if (thisStack != null && block != null && block.getRenderBlockPass() != 0){ GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); OpenGlHelper.glBlendFunc(770, 771, 1, 0); } IItemRenderer storedRenderer = MinecraftForgeClient.getItemRenderer(thisStack, type); //======Handles Special Blocks and Items====== if (storedRenderer!=null){ storedRenderer.renderItem(type, thisStack, data); } else{ if (thisStack.getItemSpriteNumber() == 0 && item instanceof ItemBlock && RenderBlocks.renderItemIn3d(block.getRenderType())) { //=====Handles regular blocks====== texturemanager.bindTexture(texturemanager.getResourceLocation(0)); switch (type){ case EQUIPPED_FIRST_PERSON: case EQUIPPED: GL11.glTranslatef(0.5F, 0.5F, 0.5F); break; case ENTITY: default: } if (thisStack != null && block != null && block.getRenderBlockPass() != 0) { GL11.glDepthMask(false); renderBlocksIr.renderBlockAsItem(block, thisStack.getItemDamage(), 1.0F); GL11.glDepthMask(true); } else { renderBlocksIr.renderBlockAsItem(block, thisStack.getItemDamage(), 1.0F); } } else{ //=======Handles Regular Items====== IIcon icon = thisStack.getIconIndex(); float xMax; float yMin; float xMin; float yMax; float depth = 1f / 16f; float width; float height; float xDiff; float yDiff; float xSub; float ySub; xMin = icon.getMinU(); xMax = icon.getMaxU(); yMin = icon.getMinV(); yMax = icon.getMaxV(); width = icon.getIconWidth(); height = icon.getIconHeight(); xDiff = xMin - xMax; yDiff = yMin - yMax; xSub = 0.5f * (xMax - xMin) / width; ySub = 0.5f * (yMax - yMin) / height; if (isInventory) { //=======Render Icon in inventory======== Doesn't Work renderItem.renderIcon(0, 0, icon, 16, 16); } else { GL11.glEnable(GL12.GL_RESCALE_NORMAL); switch (type) { case EQUIPPED_FIRST_PERSON: //TODO: get items to render in the right place case EQUIPPED: GL11.glRotated(90F, 0F, 1F, 0F); GL11.glTranslatef(-0.8F, 0.7F, -0.8F); //GL11.glTranslatef(0, -4 / 16f, 0); break; case ENTITY: GL11.glTranslatef(-0.5f, 0f, depth); // correction of the rotation point when items lie on the ground default: } //=====Front and back===== tess.startDrawingQuads(); tess.setNormal(0, 0, 1); tess.addVertexWithUV(0, 0, 0, xMax, yMax); tess.addVertexWithUV(1, 0, 0, xMin, yMax); tess.addVertexWithUV(1, 1, 0, xMin, yMin); tess.addVertexWithUV(0, 1, 0, xMax, yMin); tess.draw(); tess.startDrawingQuads(); tess.setNormal(0, 0, -1); tess.addVertexWithUV(0, 1, -depth, xMax, yMin); tess.addVertexWithUV(1, 1, -depth, xMin, yMin); tess.addVertexWithUV(1, 0, -depth, xMin, yMax); tess.addVertexWithUV(0, 0, -depth, xMax, yMax); tess.draw(); // =========Sides============ tess.startDrawingQuads(); tess.setNormal(-1, 0, 0); float pos; float iconPos; float w = width, m = xMax, d = xDiff, s = xSub; for (int k = 0, e = (int) w; k < e; ++k) { pos = k / w; iconPos = m + d * pos - s; tess.addVertexWithUV(pos, 0, -depth, iconPos, yMax); tess.addVertexWithUV(pos, 0, 0, iconPos, yMax); tess.addVertexWithUV(pos, 1, 0, iconPos, yMin); tess.addVertexWithUV(pos, 1, -depth, iconPos, yMin); } tess.draw(); tess.startDrawingQuads(); tess.setNormal(1, 0, 0); float posEnd; w = width; m = xMax; d = xDiff; s = xSub; float d2 = 1f / w; for (int k = 0, e = (int) w; k < e; ++k) { pos = k / w; iconPos = m + d * pos - s; posEnd = pos + d2; tess.addVertexWithUV(posEnd, 1, -depth, iconPos, yMin); tess.addVertexWithUV(posEnd, 1, 0, iconPos, yMin); tess.addVertexWithUV(posEnd, 0, 0, iconPos, yMax); tess.addVertexWithUV(posEnd, 0, -depth, iconPos, yMax); } tess.draw(); tess.startDrawingQuads(); tess.setNormal(0, 1, 0); float h = height; m = yMax; d = yDiff; s = ySub; d2 = 1f / h; for (int k = 0, e = (int) h; k < e; ++k) { pos = k / h; iconPos = m + d * pos - s; posEnd = pos + d2; tess.addVertexWithUV(0, posEnd, 0, xMax, iconPos); tess.addVertexWithUV(1, posEnd, 0, xMin, iconPos); tess.addVertexWithUV(1, posEnd, -depth, xMin, iconPos); tess.addVertexWithUV(0, posEnd, -depth, xMax, iconPos); } tess.draw(); tess.startDrawingQuads(); tess.setNormal(0, -1, 0); h = height; m = yMax; d = yDiff; s = ySub; for (int k = 0, e = (int) h; k < e; ++k) { pos = k / h; iconPos = m + d * pos - s; tess.addVertexWithUV(1, pos, 0, xMin, iconPos); tess.addVertexWithUV(0, pos, 0, xMax, iconPos); tess.addVertexWithUV(0, pos, -depth, xMax, iconPos); tess.addVertexWithUV(1, pos, -depth, xMin, iconPos); } tess.draw(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); } } } if (thisStack != null && block != null && block.getRenderBlockPass() != 0) { GL11.glDisable(GL11.GL_BLEND); } //TODO: Overlay lock in inventory GL11.glPopMatrix(); } }
September 28, 201411 yr Don't really know much about this, so a few stupid Qs: Is the item actually in the inventory (do you assign it a slot and stuff)? Could you post some images and stuff?
September 28, 201411 yr Hi Based on this diagram (1.6.4 but probably still correct): http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-inventory-items.html .. I'd guess that you are missing some of the important setup steps from renderItemIntoGUI. Perhaps you could call renderItemIntoGUI() instead of renderIcon? -TGG
September 28, 201411 yr Author Hi Based on this diagram (1.6.4 but probably still correct): http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-inventory-items.html .. I'd guess that you are missing some of the important setup steps from renderItemIntoGUI. Perhaps you could call renderItemIntoGUI() instead of renderIcon? -TGG I have tried both renderItemIntoGUI and renderItemWithEffectsIntoGUI both to no avail unfortunately Don't really know much about this, so a few stupid Qs: Is the item actually in the inventory (do you assign it a slot and stuff)? Could you post some images and stuff? Don't worry - I am a huge fan of stupid questions when it comes to debugging annoying code Here's a quick album (sorry for night screenshots)
September 28, 201411 yr Odd, is there a way to get and call the item renderer or just see if there is a custom renderer and then otherwise just manually render the texture? It looks like you're just using: if (storedRenderer!=null){ storedRenderer.renderItem(type, thisStack, data); } to render normal items?
September 28, 201411 yr You might be able to use something from http://www.minecraftforge.net/wiki/Custom_2D_Inventory_Item_Renderer.
September 28, 201411 yr Author if (storedRenderer!=null){ storedRenderer.renderItem(type, thisStack, data); } Actually handles all the custom renderers by checking for the existence of one in the Renderer Registry, all the rest of the code is basically just vanilla item rendering
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.