Jump to content

Incredibly stupid newbie question


Dark2phoenix

Recommended Posts

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

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.