Evert Posted November 20, 2012 Posted November 20, 2012 For a server-side mod, that can make some areas private, so other players can't break or build there. I want to make that those players also can't drop(Q) items there. I can use 'ItemTossEvent', but if that is canceled, the item disappears completely. I tried 'ItemEvent', but that is called with item events where no players are involved and I can't find a way to determine what player dropped the item, so there is no way of knowing if the event has to be canceled. What I'm looking for is: - A method to return the lost item when using 'ItemTossEvent'. or - A method to determine the player name that dropped an item when using 'ItemEvent'. or - Some other way to make this work. Thank you. Quote
N1xx1 Posted November 21, 2012 Posted November 21, 2012 Has ItemTossEvent the player who dropped it? If it has you can just put the item back to player's inventory and delete the item. Quote
Evert Posted November 25, 2012 Author Posted November 25, 2012 Thank you. That works. It is a bit buggy. When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting. public void itemEvent(ItemTossEvent event) { if ( event.isCancelable() ) { ItemStack itemStack = event.entityItem.item; event.setCanceled(true); event.player.inventory.addItemStackToInventory(itemStack); } } Quote
SanAndreaP Posted November 25, 2012 Posted November 25, 2012 On 11/25/2012 at 10:27 AM, Evert said: Thank you. That works. It is a bit buggy. When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting. public void itemEvent(ItemTossEvent event) { if ( event.isCancelable() ) { ItemStack itemStack = event.entityItem.item; event.setCanceled(true); event.player.inventory.addItemStackToInventory(itemStack); } } Maybe use: event.player.inventory.onInventoryChanged(); after: event.player.inventory.addItemStackToInventory(itemStack); Quote Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter Quote This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
Evert Posted November 25, 2012 Author Posted November 25, 2012 I tried it, but it doesn't make a difference. Quote
vemacs Posted February 3, 2013 Posted February 3, 2013 Sorry for necrobumping, but does anybody have a solution? Quote
Evert Posted February 3, 2013 Author Posted February 3, 2013 On 2/3/2013 at 2:28 AM, vemacs said: Sorry for necrobumping, but does anybody have a solution? Like i wrote before. It works, but when items are dropped from the inventory screen, they seem to disappear for a while, but they're not really lost. They reappear after some other action with the inventory or a reconnect. Quote It is a bit buggy. When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting. Using the drop key (default: Q) works fine. public void itemEvent(ItemTossEvent event) { if ( event.isCancelable() ) { ItemStack itemStack = event.entityItem.item; event.setCanceled(true); event.player.inventory.addItemStackToInventory(itemStack); } } Since mc 1.4.6, I had to change one line: ItemStack itemStack = event.entityItem.func_92014_d(); Quote
Recommended Posts
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.