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

So I'm making a custom chest for my first mod.  I've been liberally mixing the code from the default chest in Minecraft as well as looking at IronChests by CPW.  I've gotten to the point where the the Inventory Window works great when you right click on it (opens up, can add/remove items) and the block has my texture along with rendering the chest texture (box with latch on the front face).  However, for reasons I can't figure out, it never performs the chest opening/closing animation.  From what I can tell it's because the openChest method is never getting called.  (Like IronChest, the openChest increments a counter of users using and that is a key for activity in updateEntity() ).  I put some logging in at openChest and it is not firing when I right click on the chest.

 

I can post code if anyone thinks it would help, but I'm 99.999% sure I'm doing something REALLY dumb.  When should "openChest()" get called?  Is there a call path someone can point me to so I can debug this?

I had this problem for a long time before I figured out the problem:

 

    public void openChest()
    {
        ++this.numUsingPlayers;
        this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, Block.chest.blockID, 1, this.numUsingPlayers);
    }

    public void closeChest()
    {
        --this.numUsingPlayers;
        this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, Block.chest.blockID, 1, this.numUsingPlayers);
    }

 

This is from TileEntityChest. Notice something with the block events? it sends a default chest blockID - not your block's blockID. To fix it is simple:

 

    public void openChest()
    {
        ++this.numUsingPlayers;
        this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, getBlockType().blockID, 1, this.numUsingPlayers);
    }

    public void closeChest()
    {
        --this.numUsingPlayers;
        this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, getBlockType().blockID, 1, this.numUsingPlayers);
    }

 

This should fix it's animations, if this for some odd reason crashes, then replace getBlockType().blockID with a call to your chest block's blockID. Tell me if it worked!

  • Author

Thank you both very much for helping me out.  My 1st problem was not having called "openChest" or "closeChest" anywhere in my Container class.  The second was exactly what you pointed out, the code from the vanilla chest updates its own block id.

 

Thank you for getting a neophyte on his way!

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.