I'm working on my mod in which I'm trying to create new auto smelting tools (cliché I know), and I'm trying to modify the HarvestDropsEvent. I'm new to events, but from everything I've seen it doesn't look like it should be too hard. I'm sure there's probably a better way to do this, but right now this seems like the best option (suggestions are welcomed).
Here's my current code. Right now I'm trying to make it so 3 of my tools auto smelt blocks (I'll fine tune which tools smelt which blocks later, I'm just trying to get it working now).
package com.chocolatemc.event;
import java.util.ArrayList;
import com.chocolatemc.item.ItemManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraftforge.event.world.BlockEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class BlockEventManager {
@SubscribeEvent
public void onEvent(BlockEvent.HarvestDropsEvent event) {
Item breaker = event.harvester.getCurrentEquippedItem().getItem();
if (event.drops != null && event.drops.size() != 0) {
for (int x = event.drops.size() - 1; x >= 0; x--) {
if (FurnaceRecipes.smelting().getSmeltingResult(event.drops.get(x)) != null) {
ItemStack thisItem = FurnaceRecipes.smelting().getSmeltingResult(event.drops.get(x));
if (breaker == ItemManager.fireAxe || breaker == ItemManager.firePickaxe || breaker == ItemManager.fireSpade) {
event.drops.remove(x);
event.drops.add(thisItem);
}
}
}
}
}
}
I have the BlockEventManager registered in my FMLInitializationEvent like this (from what I've seen, this works fine):
MinecraftForge.EVENT_BUS.register(new BlockEventManager());
Basically, every time I try to load up a new world with the new event, I get an error and a crash. I thought it might have had something to do with it doing something with blocks that aren't harvestable, so I added the check to see if the drops array is empty or zero, but I don't think that should be even a question since the event isn't associated with world gen, and it's registered in Init, not PreInit (not 100% sure about those, it's been a while since I looked into those and I don't know them well, probably entirely wrong lol).
Any ideas why it might not be working?