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] How to cancel an item drop/toss by player, without losing the item?

Featured Replies

Posted

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.

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.

  • 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);
	}
}

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.

  • 2 months later...
  • 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.

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.