Posted June 28, 201510 yr 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.
June 28, 201510 yr 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.
June 28, 201510 yr 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.