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.

Featured Replies

Posted

In 1.8 I use an event handler to add functionality for an automatic smelting enchantment.

 

 


if (player != null && !player.capabilities.isCreativeMode && EnchantmentHelper.getEnchantmentLevel(this.effectId, player.getHeldItem()) > 0) {
HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;
ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);
if (drop != null) {
	ItemStack smeltStack = new ItemStack(drop.getItem(), 1, drop.getMetadata());
	ItemStack smeltResult = FurnaceRecipes.instance().getSmeltingResult(smeltStack);
	if (smeltResult != null) {
		smeltResult.stackSize *= drop.stackSize;
		event.drops.clear();
		event.drops.add(smeltResult);
	}
}
}

This code works only the first time breaking a certain block. After that, nothing drops. For example, the first time breaking an iron ore yielded one iron ingot. Tries after that all yielded nothing. This is done using the HarvestDropsEvent.

Maker of the Craft++ mod.

Always use itemStack.copy() when editing it. (stacks are mutable)

 

When pulling ItemStack from any kind of registry or something - 1st do something like ItemStack tempStack = stack.copy();

Also:

HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;

Wtf? I really hope you are actually doing it as event, not like this.

And:

ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);

drops can be bigger than just size==1 and then you do event.drops.clear(); which clears them all, kinda bad design in my opinion.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Always use itemStack.copy() when editing it. (stacks are mutable)

 

When pulling ItemStack from any kind of registry or something - 1st do something like ItemStack tempStack = stack.copy();

Also:

HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;

Wtf? I really hope you are actually doing it as event, not like this.

And:

ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);

drops can be bigger than just size==1 and then you do event.drops.clear(); which clears them all, kinda bad design in my opinion.

This is part of a method called from my event handler. I'll try the .copy() method out.

UPDATE: Worked like a charm! Thanks.

Maker of the Craft++ mod.

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.