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.

<SOLVED>[1.12.2] Updating the client's inventory after cancelling BlockEvent.PlaceEvent on the server side

Featured Replies

Posted

Hello,

After cancelling BlockEvent.PlaceEvent on the server side, I'd like to make sure the client knows the block hasn't been placed.

I've tried EntityPlayer.inventory.markDirty(), as well as overwriting the stack in the slot with itself, but neither updated the client. Ideally I'd like a way to do this on the server side only, without having to make changes to the client, because the mod I'm doing this in is intended to run on the server side only. If anyone has any suggestions about how to make this work, please let me know. I'll edit the post if I come up with a solution.

 

EDIT: Solved by adding the following after cancelling the event:

EntityEquipmentSlot hand = event.getHand().equals(EnumHand.MAIN_HAND) ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND;
((EntityPlayerMP) event.getPlayer()).connection.sendPacket(new SPacketEntityEquipment(event.getPlayer().getEntityId(), hand, event.getPlayer().getItemStackFromSlot(hand)));

 

Edited by The_Fireplace
Added solution

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

I've solved this in my build protection system by canceling the event on both server and client side, using the same conditions.  I can do this in my system, but it may not be feasible in yours if the data needed for the check only exists server-side.

Cancelling the event server-side ensures nobody can cheat their way past your protection (for the most part).

Cancelling the event client-side doesn't, but if used in addition to the server-side function can make your protection "prettier" by preventing the inventory desync.  If someone hacks past it, it will just prevent it server-side (again, only if you're also doing the check server-side, in an identical fashion), and give them the inventory desync, so no benefit for them aside from the very brief window of the block not existing client-side which could allow them to jump on top of it or w/e...but if they're hacking past your protection to do that, they could just as easily use simpler hacks to accomplish the same thing.

 

Once again, I only suggest this if you can do your check identically on both server and client.

  • Author
16 hours ago, Laike_Endaril said:

I've solved this in my build protection system by canceling the event on both server and client side, using the same conditions.  I can do this in my system, but it may not be feasible in yours if the data needed for the check only exists server-side.

Cancelling the event server-side ensures nobody can cheat their way past your protection (for the most part).

Cancelling the event client-side doesn't, but if used in addition to the server-side function can make your protection "prettier" by preventing the inventory desync.  If someone hacks past it, it will just prevent it server-side (again, only if you're also doing the check server-side, in an identical fashion), and give them the inventory desync, so no benefit for them aside from the very brief window of the block not existing client-side which could allow them to jump on top of it or w/e...but if they're hacking past your protection to do that, they could just as easily use simpler hacks to accomplish the same thing.

 

Once again, I only suggest this if you can do your check identically on both server and client.

Yeah, the entire mod, including the data used for the check, is only on the server side.

 

Since the original post, I've also tried decreasing the stack size of the block when I cancel the event then adding the block to the inventory, but that didn't fix it either.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

If you want to do it from server-side only, you'll have to see if you can find a packet that harmlessly triggers a client-side inventory sync.  I haven't looked into that, so I won't be much help.

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.