Jump to content

[1.8.9] [SOLVED] Problem rendering item based on Tile Entity's inventory


tyqo

Recommended Posts

Hi, I've been struggling this for a while and can't seem to get it to work so was wondering if anybody here would know how to fix my problem.

 

Basically I've got a TileEntity with an inventory, and it can store items through NBT just fine. It has a TileEntitySpecialRenderer which will render the item in inventory slot 0 if it isn't null. The item will get rendered when you first place it into the inventory, but upon re-loading the world the item isn't rendering. I know for certain that the inventory is being saved, because if I break the block then the items come out. For some reason the slot is null in renderTileEntityAt, but when I break the block the item comes out? I'm not sure what the problem could be, so any help would be appreciated. I'm thinking maybe it's something to do with differences between client and server maybe?

 

Here's the Renderer function (the rest of the class is empty):

 

@Override
    public void renderTileEntityAt(
            TileEntity tileEntity, double x, double y, double z, float partialTicks, int destroyStage
    ) {
        TileEntityFrogStorage te = (TileEntityFrogStorage) tileEntity;

        System.out.println(te.getStackInSlot(0));

        if (te.getStackInSlot(0) != null) {
            GL11.glPushMatrix();

            // Handle itemblock position based on 'facing'
            if (te.isStoredItemBlock()) {
                if (te.getBlockMetadata() == 0)         // South - 0
                {
                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4f, (float) z + 0.22F);
                    GL11.glRotatef(0F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 1)    // West - 1
                {
                    GL11.glTranslatef((float) x + 0.78F, (float) y + 0.4f, (float) z + 0.5F);
                    GL11.glRotatef(270F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 2)     // North - 2
                {
                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4f, (float) z + 0.78F);
                    GL11.glRotatef(180F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 3)    // East - 3
                {
                    GL11.glTranslatef((float) x + 0.22F, (float) y + 0.4f, (float) z + 0.5F);
                    GL11.glRotatef(90F, 0F, 1F, 0F);
                }
            } else {
                // Must be a real item not an ItemBlock
                if (te.getBlockMetadata() == 0)         // South - 0
                {
                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4f, (float) z + 0.22F);
                    GL11.glRotatef(180F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 1)    // West - 1
                {
                    GL11.glTranslatef((float) x + 0.78F, (float) y + 0.4f, (float) z + 0.5F);
                    GL11.glRotatef(-270F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 2)    // North - 2
                {
                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4f, (float) z + 0.78F);
                    GL11.glRotatef(0F, 0F, 1F, 0F);
                }
                else if (te.getBlockMetadata() == 3)    // East - 3
                {
                    GL11.glTranslatef((float) x + 0.22F, (float) y + 0.4f, (float) z + 0.5F);
                    GL11.glRotatef(-90F, 0F, 1F, 0F);
                }
            }

            GL11.glScalef(0.5F, 0.5F, 0.5F);

            Minecraft.getMinecraft().getRenderItem().renderItem(
                    te.getStackInSlot(0),
                    ItemCameraTransforms.TransformType.GROUND
            );

            GL11.glPopMatrix();
        }
    }

 

 

The

System.out.println(te.getStackInSlot(0))

is returning null when I first place the entity (which is to be expected since the inventory SHOULD be empty), returning the item in slot 0 correctly when I first place it, but returning null again upon reloading the world.

 

If you need any more information

Link to comment
Share on other sites

Do you have any idea about sides (server/client)?

If not: http://mcforge.readthedocs.org/en/latest/concepts/sides/

 

Anyway - you are most likely not syncing ItemStack field to client, thus - it is null on client, but filled on server (since it drops).

 

You need to use getDescriptionPacket (send) and onDataPacket (receive) (in TileEntity). If you'd have problems - You should find how to use them in probably any open source mod with tiles.

 

P.S - if yo uare interested why client has ItemStack when editing it - you are using container which manipulates slots on both sides, thus - you are auto synced. On the other hand when you load world (or you get into range of seeing block pos) - the packet with contents of TE has to be sent.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I was aware of them but not how they interacted, but I have a much better understanding (I hope) now that I've read through some of the docs.

 

You were right, that was the problem! I (naively) assumed that it was handled automatically, which seems a little silly now. Thank you so much for your help, and even more so for going the extra mile and explaining why it was happening. Coming home from a long day of work, seeing this reply and getting the problem solved was very satisfying  :P

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.