| 1 | package net.minecraft.inventory;
|
| 2 |
|
| 3 | import net.minecraft.entity.item.EntityXPOrb;
|
| 4 | import net.minecraft.entity.player.EntityPlayer;
|
| 5 | import net.minecraft.init.Items;
|
| 6 | import net.minecraft.item.ItemStack;
|
| 7 | import net.minecraft.item.crafting.FurnaceRecipes;
|
| 8 | import net.minecraft.stats.AchievementList;
|
| 9 | import net.minecraft.util.MathHelper;
|
| 10 |
|
| 11 | public class SlotFurnaceOutput extends Slot
|
| 12 | {
|
| 13 | /** The player that is using the GUI where this slot resides. */
|
| 14 | private EntityPlayer thePlayer;
|
| 15 | private int field_75228_b;
|
| 16 |
|
| 17 | public SlotFurnaceOutput(EntityPlayer player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
|
| 18 | {
|
| 19 | super(inventoryIn, slotIndex, xPosition, yPosition);
|
| 20 | this.thePlayer = player;
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
| 25 | */
|
| 26 | public boolean isItemValid(ItemStack stack)
|
| 27 | {
|
| 28 | return false;
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
|
| 33 | * stack.
|
| 34 | */
|
| 35 | public ItemStack decrStackSize(int amount)
|
| 36 | {
|
| 37 | if (this.getHasStack())
|
| 38 | {
|
| 39 | this.field_75228_b += Math.min(amount, this.getStack().stackSize);
|
| 40 | }
|
| 41 |
|
| 42 | return super.decrStackSize(amount);
|
| 43 | }
|
| 44 |
|
| 45 | public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
|
| 46 | {
|
| 47 | this.onCrafting(stack);
|
| 48 | super.onPickupFromSlot(playerIn, stack);
|
| 49 | }
|
| 50 |
|
| 51 | /**
|
| 52 | * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
|
| 53 | * internal count then calls onCrafting(item).
|
| 54 | */
|
| 55 | protected void onCrafting(ItemStack stack, int amount)
|
| 56 | {
|
| 57 | this.field_75228_b += amount;
|
| 58 | this.onCrafting(stack);
|
| 59 | }
|
| 60 |
|
| 61 | /**
|
| 62 | * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
| 63 | */
|
| 64 | protected void onCrafting(ItemStack stack)
|
| 65 | {
|
| 66 | stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b);
|
| 67 |
|
| 68 | if (!this.thePlayer.worldObj.isRemote)
|
| 69 | {
|
| 70 | int i = this.field_75228_b;
|
| 71 | float f = FurnaceRecipes.instance().getSmeltingExperience(stack);
|
| 72 |
|
| 73 | if (f == 0.0F)
|
| 74 | {
|
| 75 | i = 0;
|
| 76 | }
|
| 77 | else if (f < 1.0F)
|
| 78 | {
|
| 79 | int j = MathHelper.floor_float((float)i * f);
|
| 80 |
|
| 81 | if (j < MathHelper.ceiling_float_int((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
|
| 82 | {
|
| 83 | ++j;
|
| 84 | }
|
| 85 |
|
| 86 | i = j;
|
| 87 | }
|
| 88 |
|
| 89 | while (i > 0)
|
| 90 | {
|
| 91 | int k = EntityXPOrb.getXPSplit(i);
|
| 92 | i -= k;
|
| 93 | this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, k));
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | this.field_75228_b = 0;
|
| 98 |
|
| 99 | if (stack.getItem() == Items.iron_ingot)
|
| 100 | {
|
| 101 | this.thePlayer.triggerAchievement(AchievementList.acquireIron);
|
| 102 | }
|
| 103 |
|
| 104 | if (stack.getItem() == Items.cooked_fish)
|
| 105 | {
|
| 106 | this.thePlayer.triggerAchievement(AchievementList.cookFish);
|
| 107 | }
|
| 108 | }
|
| 109 | }
|
| 110 |
|