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 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 by henne90gen

  • 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"

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

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

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

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

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.