Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

 

I'm developing a custom tileentity with a guiless inventory. You can put items on it's top side and get them out of there. I have two problems here. The first and more important problem is that i can't get the world to spawn the item when the player interacts with the block. I call world.spawnEntity on the server side with an EntityItem filled with the ItemStack. On client, the item pops up and disappears instantly, without me getting the item in the player inventory. The corresponding code looks like this:

 

    public boolean onPlayerRightClickOnTop(EntityPlayer player, float hitX, float hitZ) {
        if (world.isRemote) {
            return false;
        }

        int i = hitX > 0.33f ? (hitX > 0.66f ? 2 : 1) : 0;
        int j = hitZ > 0.33f ? (hitZ > 0.66f ? 2 : 1) : 0;

        ItemStack activeStack = player.getHeldItemMainhand();

        if (player.isSneaking()) {
            if (!inventory[i][j].isEmpty()) {
                EntityItem entityItem = new EntityItem(world, pos.getX() + hitX, pos.getY() + 1.2, pos.getZ() + hitZ, inventory[i][j]);
                world.spawnEntity(entityItem);
                inventory[i][j].setCount(0);
                sendDataToClients();
                return true;
            } else if (!activeStack.isEmpty()) {
                inventory[i][j] = activeStack.copy();
                activeStack.setCount(0);
                sendDataToClients();
                return true;
            }
        } else if (!activeStack.isEmpty()) {
            if (inventory[i][j].isEmpty()) {
                inventory[i][j] = activeStack.splitStack(1);
                sendDataToClients();
                return true;
            } else if (inventory[i][j].isItemEqual(activeStack)
                    && inventory[i][j].getCount() < inventory[i][j].getMaxStackSize()) {
                inventory[i][j].setCount(inventory[i][j].getCount()+1);
                activeStack.splitStack(1);
                sendDataToClients();
                return true;
            }
        }

        return false;
    }

 

 

My second problem is that the items rendered on the block look totally dark, no lightning at all. I tried it with and without the lightning related lines, but i noticed no change. The rendering code is like this:

 

    @Override
    public void render(TileEntityCraftingPillar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
        super.render(te, x, y, z, partialTicks, destroyStage, alpha);

        EntityItem entityItem = new EntityItem(getWorld());
        entityItem.hoverStart = 0;

        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (!te.getItemStackAt(i, j).isEmpty()) {
                    GlStateManager.pushMatrix();

                    GlStateManager.translate(x + 1./6 + 1./3*i, y + 1, z + 1./6 + 1./3*j);
                    //GlStateManager.translate(-x, -y, -z);
                    GlStateManager.scale(0.33, 0.33, 0.33);

                    GlStateManager.pushAttrib();
                    RenderHelper.enableStandardItemLighting();

                    entityItem.setItem(te.getItemStackAt(i, j));
                    Minecraft.getMinecraft().getRenderManager().doRenderEntity(entityItem,
                            0, 0, 0, 0, 0, false);
                    //RenderEntityItem
                    //Minecraft.getMinecraft().getRenderItem().renderItem(te.getItemStackAt(i, j), ItemCameraTransforms.TransformType.FIXED);

                    RenderHelper.disableStandardItemLighting();
                    GlStateManager.popAttrib();

                    GlStateManager.popMatrix();
                }
            }
        }
    }

 

 

 

Screenshot of the rendering result:

 

pMRQbWZ.png

 

 

 

The GitHub project can be found here.

 

Thank you for your help in advance!

Edited by FBalazs

Sorry for my bad English!

FBalazs

  • Author
2 minutes ago, fcelon said:

Try watching this video. 

 

I will watch it when i get home, currently i'm working from mobile internet and it's expensive O_O
By the way, i managed to fix the spawning issue. I passed the reference of the inventory itemstack to the entity, instead of copying it. So when i set count in the inventory to zero, it caused the entity to set it's count to zero as well. I hope i can fix the lightning issue after watching the video.

Sorry for my bad English!

FBalazs

Don't create a new EntityItem each frame. Especially because you are using it only to re-route to the code that renders the ItemStack in pretty much the same way you've commented out. 

On 8/5/2017 at 10:36 PM, FBalazs said:

//Minecraft.getMinecraft().getRenderItem().renderItem(te.getItemStackAt(i, j), ItemCameraTransforms.TransformType.FIX

 

As you've said the lightmap coordinates are incorrect. Set them manually with OpenGlHelper.setLightmapTextureCoords. The first parameter is the texture unit(OpenGlHelper.lightmapTexUnit), second and third are your lightmap coordinates. Do not forget to reset them back to what they were after you are done - their current values are stored at OpenGlHelper.lastBrightnessX/Y

Ooookay, so I have overriden the following deprecated method and now the lighting is working as expected: 

 @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

How can I find a potential non-deprecated method for this? (and isFullCube).

 

Also I found the isVisuallyOpaque method, does it do anything?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.