package info.u_team.u_team_test.enchantment;

import java.util.List;

import info.u_team.u_team_core.enchantment.UEnchantment;
import net.minecraft.enchantment.*;
import net.minecraft.entity.item.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class AutoSmeltEnchantment extends UEnchantment {
	
	public AutoSmeltEnchantment(String name) {
		super(name, Rarity.COMMON, EnchantmentType.DIGGER, new EquipmentSlotType[] { EquipmentSlotType.MAINHAND });
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	@SubscribeEvent
	public void on(HarvestDropsEvent event) {
		if (event.isSilkTouching()) {
			return;
		}
		final PlayerEntity player = event.getHarvester();
		if (player == null) {
			return;
		}
		final World world = player.getEntityWorld();
		if (world.isRemote) {
			return;
		}
		final ItemStack stack = player.getHeldItemMainhand();
		if (stack.isEmpty()) {
			return;
		}
		final int level = EnchantmentHelper.getEnchantmentLevel(this, stack);
		if (level == 0) {
			return;
		}
		final List<ItemStack> drops = event.getDrops();
		for (int i = 0; i < drops.size(); i++) {
			final ItemStack drop = drops.get(i);
			final Inventory inventory = new Inventory(1);
			inventory.setInventorySlotContents(0, drop);
			
			final int index = i;
			
			world.getRecipeManager().getRecipe(IRecipeType.SMELTING, inventory, world).ifPresent(recipe -> {
				final ItemStack newDrop = recipe.getCraftingResult(inventory);
				if (newDrop != null && !newDrop.isEmpty()) {
					drops.set(index, newDrop);
					final BlockPos pos = event.getPos();
					int amount = drop.getCount();
					recipe.getIcon();
					final float exp = recipe.getExperience();
					
					if (exp == 0.0F) {
						amount = 0;
					} else if (exp < 1.0F) {
						int calc = MathHelper.floor(amount * exp);
						
						if (calc < MathHelper.ceil(amount * exp) && (float) Math.random() < amount * exp - calc) {
							++calc;
						}
						amount = calc;
					}
					
					while (amount > 0) {
						final int split = ExperienceOrbEntity.getXPSplit(amount);
						amount -= split;
						world.addEntity(new ExperienceOrbEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, split));
					}
				}
			});
		}
	}
}

@@ -43,32 +43,8 @@
 t;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -133,2419 +133,380 @@
 ent.
-*;%0Aimport net.minecraft.entity.item.ExperienceOrbEntity;%0Aimport net.minecraft.entity.player.PlayerEntity;%0Aimport net.minecraft.inventory.*;%0Aimport net.minecraft.item.ItemStack;%0Aimport net.minecraft.item.crafting.IRecipeType;%0Aimport net.minecraft.util.math.*;%0Aimport net.minecraft.world.World;%0Aimport net.minecraftforge.common.MinecraftForge;%0Aimport net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;%0Aimport net.minecraftforge.eventbus.api.SubscribeEvent;%0A%0Apublic class AutoSmeltEnchantment extends UEnchantment %7B%0A%09%0A%09public AutoSmeltEnchantment(String name) %7B%0A%09%09super(name, Rarity.COMMON, EnchantmentType.DIGGER, new EquipmentSlotType%5B%5D %7B EquipmentSlotType.MAINHAND %7D);%0A%09%09MinecraftForge.EVENT_BUS.register(this);%0A%09%7D%0A%09%0A%09@SubscribeEvent%0A%09public void on(HarvestDropsEvent event) %7B%0A%09%09if (event.isSilkTouching()) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final PlayerEntity player = event.getHarvester();%0A%09%09if (player == null) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final World world = player.getEntityWorld();%0A%09%09if (world.isRemote) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final ItemStack stack = player.getHeldItemMainhand();%0A%09%09if (stack.isEmpty()) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final int level = EnchantmentHelper.getEnchantmentLevel(this, stack);%0A%09%09if (level == 0) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final List%3CItemStack%3E drops = event.getDrops();%0A%09%09for (int i = 0; i %3C drops.size(); i++) %7B%0A%09%09%09final ItemStack drop = drops.get(i);%0A%09%09%09final Inventory inventory = new Inventory(1);%0A%09%09%09inventory.setInventorySlotContents(0, drop);%0A%09%09%09%0A%09%09%09final int index = i;%0A%09%09%09%0A%09%09%09world.getRecipeManager().getRecipe(IRecipeType.SMELTING, inventory, world).ifPresent(recipe -%3E %7B%0A%09%09%09%09final ItemStack newDrop = recipe.getCraftingResult(inventory);%0A%09%09%09%09if (newDrop != null && !newDrop.isEmpty()) %7B%0A%09%09%09%09%09drops.set(index, newDrop);%0A%09%09%09%09%09final BlockPos pos = event.getPos();%0A%09%09%09%09%09int amount = drop.getCount();%0A%09%09%09%09%09recipe.getIcon();%0A%09%09%09%09%09final float exp = recipe.getExperience();%0A%09%09%09%09%09%0A%09%09%09%09%09if (exp == 0.0F) %7B%0A%09%09%09%09%09%09amount = 0;%0A%09%09%09%09%09%7D else if (exp %3C 1.0F) %7B%0A%09%09%09%09%09%09int calc = MathHelper.floor(amount * exp);%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09if (calc %3C MathHelper.ceil(amount * exp) && (float) Math.random() %3C amount * exp - calc) %7B%0A%09%09%09%09%09%09%09++calc;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09amount = calc;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09%0A%09%09%09%09%09while (amount %3E 0) %7B%0A%09%09%09%09%09%09final int split = ExperienceOrbEntity.getXPSplit(amount);%0A%09%09%09%09%09%09amount -= split;%0A%09%09%09%09%09%09world.addEntity(new ExperienceOrbEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, split));%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D
+EnchantmentType;%0Aimport net.minecraft.inventory.EquipmentSlotType;%0Aimport net.minecraftforge.common.MinecraftForge;%0A%0Apublic class AutoSmeltEnchantment extends UEnchantment %7B%0A%09%0A%09public AutoSmeltEnchantment(String name) %7B%0A%09%09super(name, Rarity.COMMON, EnchantmentType.DIGGER, new EquipmentSlotType%5B%5D %7B EquipmentSlotType.MAINHAND %7D);%0A%09%09MinecraftForge.EVENT_BUS.register(this);
 %0A%09%7D%0A

Remove old autosmelt code