Posted March 15, 20205 yr Hi, I want to be notified on the client side, every time the player breaks a block. However, I wasn't able to find an event that covers that case. Does anyone know how to achieve this? Edited March 16, 20205 yr by henne90gen
March 15, 20205 yr Author I'm creating a mod that keeps track of the items in the players chests and I want it to work on vanilla servers as well. Whenever a player opens a chest I write the contents of the chest to a "database". That's why I need to know when the player destroys a chest, so that I can delete that chest from the "database"
March 15, 20205 yr Author I found a solution for my problem. I'm now using the PlayerInteractEvent.LeftClickBlock to detect when a player clicks on a block. Every time the event fires, I check the surrounding 3x3x3 blocks whether they are chests or not. If a block is not a chest, I simply check my database, whether I have a chest saved for that position and delete it if that's the case. The only downside to this is, that the player has to click on a neighboring block after breaking the chest block. So if anyone knows about a better way of doing this, then please let me know.
March 15, 20205 yr Author Yeah, it's more of a workaround. I didn't expect to find a client side solution that takes into account other players breaking chests. It would be nice though to at least be able to get notified when the current player (the one that is being played by the client) breaks a block.
March 15, 20205 yr Hi If you can't modify the server, and there is only one or a few chests that you're trying to track, then you could consider the client tick event; once every (eg) 20 ticks you could check to see if the chest still exists at the expected location. Likewise you could periodically check the chest contents to see if they have changed. That would detect changes not caused by the local player. I can't think of any other client events which are triggered on updates to changes to chest contents. -TGG
March 16, 20205 yr Author Thanks for the tip. Checking all chests every couple ticks works much better than my initial workaround. However, I can't get the content of the chest this way. At least not the way I tried it. TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof ChestTileEntity) { ChestTileEntity chestTileEntity = (ChestTileEntity) tileEntity; for (int i = 0; i < chestTileEntity.getSizeInventory(); i++) { ItemStack stack = chestTileEntity.getStackInSlot(i); // count items here } } This only gives me an empty inventory.
March 16, 20205 yr Author Ok, I thought so. Thanks for everyones help. Edited March 16, 20205 yr by henne90gen
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.