package minefantasy.container; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; public class SlotAnvil extends Slot { /** The player that is using the GUI where this slot resides. */ private EntityPlayer thePlayer; private int experiance; public float experiancePoints; public SlotAnvil(EntityPlayer player, IInventory inventory, int slotNum, int x, int y) { super(inventory, slotNum, x, y); } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots. */ public boolean isItemValid(ItemStack item) { return false; } /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. */ public ItemStack decrStackSize(int slot) { if (this.getHasStack()) { this.experiance += Math.min(slot, this.getStack().stackSize); } return super.decrStackSize(slot); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an * internal count then calls onCrafting(item). */ protected void onCrafting(ItemStack item, int amount) { this.experiance += amount; this.onCrafting(item); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack stack) { if(thePlayer == null) return; stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.experiance); if (!this.thePlayer.worldObj.isRemote) { int var2 = this.experiance; /** * TODO give anvil experience */ float var3 = experiancePoints; int var4; if (var3 == 0.0F) { var2 = 0; } else if (var3 < 1.0F) { var4 = MathHelper.floor_float((float)var2 * var3); if (var4 < MathHelper.ceiling_float_int((float)var2 * var3) && (float)Math.random() < (float)var2 * var3 - (float)var4) { ++var4; } var2 = var4; } while (var2 > 0) { var4 = EntityXPOrb.getXPSplit(var2); var2 -= var4; this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, var4)); } } this.experiance = 0; } }