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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • There's a scheme I got into where they promised to trade Bitcoin for me and take a cut as a commission. Seemed like a good idea at the time. But then, things went south real fast. They ended up transferring   $190,000 worth of my Bitcoin. I was devastated and felt completely helpless. That's when I stumbled upon the Wizard Web Recovery Tool. It was like a beacon of hope amid chaos. With this tool, I could finally start digging into what went wrong and hopefully get my Bitcoin back. Using Wizard Web was surprisingly easy. I just had to plug in some details about my Bitcoin account and let it do its thing. It started scanning the internet, looking for any clues about what happened to my Bitcoin. It felt like having a detective on my side, searching for answers. And guess what? Wizard Web found some leads. It uncovered evidence of the scheme's shady dealings and helped me track down the people responsible for losing my Bitcoin. Armed with this information, I took the case to court. After a long and hard-fought legal battle, the court ruled in my favor. The perpetrators were held accountable for their actions and faced criminal charges for their involvement in the scheme. It was a victory not just for me, but for anyone who's been taken advantage of by these kinds of scams. Thanks to Wizard Web Recovery, I was able to get justice and reclaim what was rightfully mine. It showed me that even in the face of adversity, there's always a way to fight back. And with the right tools and determination, anything is possible.   The following is the contact information for Wizard Web Recovery.   Email: wizard web recovery((@))programmer . net
    • Hello, good morning. I know some programming and I'm interested in mod creation. That's why I've decided to follow a tutorial guide on YouTube by TurtyWurty. https://www.youtube.com/watch?v=DhoX9cmAZqA&t=160s&ab_channel=TurtyWurty I've followed the tutorial perfectly. The problem is that when checking the food, the texture doesn't load for me. However, everything seems fine no matter how much I check. I'm sure it's something trivial, the problem is that I can't find it. Could you help me solve it, please? I leave a zip of my file so you can edit it freely. forge-1.20-Civicraft.rar
    • If you have nvidia graphics, it's important that you make sure Minecraft (and anything Minecraft-related) is set to prefer high performance graphics first. If you only update your AMD drivers it might fix the issue but cause severe performance loss vs Vanilla as it'll be running on the integrated graphics instead of dedicated nvidia graphics
    • Update your drivers: https://www.amd.com/en/support/downloads/drivers.html/processors/ryzen/ryzen-5000-series/amd-ryzen-5-5600g.html
  • Topics

×
×
  • Create New...

Important Information

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