Posted November 20, 201212 yr 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.
November 21, 201212 yr 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.
November 25, 201212 yr Author 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); } }
November 25, 201212 yr 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); 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 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.
February 3, 201312 yr Author 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. 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();
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.