Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


The_Fireplace
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • Forge's custom networking is built on the custom payload packet. You can either use a SimpleChannel (which uses a byte-indexed codec, so you have to handle that on the bukkit side, too) or you can use an EventChannel, which just gives you access to the raw payload packet data. There isn't anything special you need to do to make the two talk to each other. It just works, because both use the same network packet.
    • [16:08:43] [main/ERROR] [LaunchWrapper]: Unable to launch java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292] at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70) [forge.jar:?] at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) [forge.jar:?] Caused by: java.lang.VerifyError: Operand stack overflow Exception Details: Location: net/minecraft/entity/EntityLivingBase.func_70088_a()V @7: aload_0 Reason: Exceeded max stack size. Current Frame: bci: @7 flags: { } locals: { 'net/minecraft/entity/EntityLivingBase' } stack: { 'net/minecraftforge/fml/common/eventhandler/EventBus', uninitialized 3, uninitialized 3 } Bytecode: 0x0000000: b201 09bb 010b 592a b701 0cb6 0112 572a 0x0000010: b401 16b2 0118 03b8 011e b601 242a b401 0x0000020: 16b2 0126 03b8 012b b601 242a b401 16b2 0x0000030: 012d 03b8 0132 b601 242a b401 16b2 0134 0x0000040: 03b8 012b b601 242a b401 16b2 0136 0cb8 0x0000050: 013b b601 24b1 at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.8.0_292] at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[?:1.8.0_292] at java.lang.Class.getConstructor0(Class.java:3075) ~[?:1.8.0_292] at java.lang.Class.getConstructor(Class.java:1825) ~[?:1.8.0_292] at net.minecraft.entity.EntityList.func_191303_a(EntityList.java:410) ~[vi.class:?] at net.minecraft.entity.EntityList.func_151514_a(EntityList.java:280) ~[vi.class:?] at net.minecraft.init.Bootstrap.func_151354_b(Bootstrap.java:505) ~[ni.class:?] at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:1470) ~[MinecraftServer.class:?] ... 12 more
    • 1.7 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.