Posted January 29, 201312 yr 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?
January 30, 201312 yr 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!
January 30, 201312 yr 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.