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.9] Autosmelting Pickaxe; new EntityItem drop doesn't spawn every time

Featured Replies

Posted

So I have a basic autosmelting pickaxe setup, utilizing HarvestDropsEvent.

@SubscribeEvent
public void OnBlockBreak(HarvestDropsEvent e)
{
	EntityPlayer player = e.getHarvester();
	//If the player is holding the blazing pickaxe in their main hand
	if(player != null && player.getHeldItemMainhand().getItem() == ModItems.blazingPick)
	{
		if(!e.getWorld().isRemote)
		{
			for(int i = 0; i < e.getDrops().size(); i++)
			{

				ItemStack dropstack = FurnaceRecipes.instance().getSmeltingResult(e.getDrops().get(i));
				if(dropstack != null)
				{
					System.out.printf("%s smelts to: %s\n",
                                                e.getDrops().get(i).getDisplayName(),dropstack.getDisplayName());

					if(e.getWorld().spawnEntityInWorld(new EntityItem(e.getWorld(),                                  
                                                e.getPos().getX()+0.5,e.getPos().getY() + 0.5, e.getPos().getZ() + 0.5, dropstack)))
					{
						System.out.printf("Dropped item at %s, %s, %s\n", e.getPos().getX() + 0.5, 
                                                        e.getPos().getY() + 0.5, e.getPos().getZ() + 0.5);
					}
					else
					{
						System.out.println("Dropping item failed.");
					}
				} else {System.out.printf("%s has no smelting output.\n",
                                                        e.getDrops().get(i).getDisplayName());}
			}
		}
	}
	e.setDropChance(0);
}

 

Strangely, this code causes the event to "smelt" the drops the first time it smelts the drops, but if you try to mine a block that produces the same drops after that first one (eg. mining the same block again, or mining stone then cobblestone), it doesn't spawn the new EntityItem.

 

For example, I can mine three blocks of Iron Ore, but only the first one drops the smelted item, the others just don't drop anything as the drop chance has been set to 0. However, I can go and mine some gold, and it'll drop from the first one, but this doesn't reset anything, and trying to mine the iron will still spawn no new drops.

 

All of this seems to run correctly, since the System.out.println/printf calls still run. I have no idea why it would run through the code but not spawn the EntityItem. Any ideas?

Make sure you spawn the EntityItem using a COPY of the ItemStack (i.e. dropstack.copy()) - IIRC, #getSmeltingResult returns only a single ItemStack instance, not a new one each time, so after you have picked up the first stack dropped, every drop after that will have a stack size of zero.

 

Usually in that case, however, the item will still spawn but picking it up doesn't give you anything. It's possible they have changed this behavior since 1.7.10/1.8.

  • Author

@coolAlias: That worked! Thank you!

 

@Anon10W1z: Thanks for the offer, but I wanted to make this pickaxe as sort of a personal challenge, since I'd never actually made one like it. No copy/paste for me. :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.