Advertisement
Guest User

SlotNaturalisFurnace

a guest
Jul 29th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.55 KB | None | 0 0
  1. package nekpek.mod.Naturalis.PowerFurnace;
  2.  
  3. import net.minecraft.entity.item.EntityXPOrb;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.item.crafting.FurnaceRecipes;
  10. import net.minecraft.stats.AchievementList;
  11. import net.minecraft.util.MathHelper;
  12. import cpw.mods.fml.common.registry.GameRegistry;
  13.  
  14. public class SlotNaturalisFurnace extends Slot
  15.     {
  16.         /** The player that is using the GUI where this slot resides. */
  17.         private final EntityPlayer thePlayer;
  18.         private int field_75228_b;
  19.  
  20.         public SlotNaturalisFurnace(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5)
  21.             {
  22.                 super(par2IInventory, par3, par4, par5);
  23.                 this.thePlayer = par1EntityPlayer;
  24.             }
  25.  
  26.         /**
  27.          * Check if the stack is a valid item for this slot. Always true beside
  28.          * for the armor slots.
  29.          */
  30.         @Override
  31.         public boolean isItemValid(ItemStack par1ItemStack)
  32.             {
  33.                 return false;
  34.             }
  35.  
  36.         /**
  37.          * Decrease the size of the stack in slot (first int arg) by the amount
  38.          * of the second int arg. Returns the new stack.
  39.          */
  40.         @Override
  41.         public ItemStack decrStackSize(int par1)
  42.             {
  43.                 if (this.getHasStack())
  44.                     {
  45.                         this.field_75228_b += Math.min(par1, this.getStack().stackSize);
  46.                     }
  47.  
  48.                 return super.decrStackSize(par1);
  49.             }
  50.  
  51.         @Override
  52.         public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
  53.             {
  54.                 this.onCrafting(par2ItemStack);
  55.                 super.onPickupFromSlot(par1EntityPlayer, par2ItemStack);
  56.             }
  57.  
  58.         /**
  59.          * the itemStack passed in is the output - ie, iron ingots, and
  60.          * pickaxes, not ore and wood. Typically increases an internal count
  61.          * then calls onCrafting(item).
  62.          */
  63.         @Override
  64.         protected void onCrafting(ItemStack par1ItemStack, int par2)
  65.             {
  66.                 this.field_75228_b += par2;
  67.                 this.onCrafting(par1ItemStack);
  68.             }
  69.  
  70.         /**
  71.          * the itemStack passed in is the output - ie, iron ingots, and
  72.          * pickaxes, not ore and wood.
  73.          */
  74.         @Override
  75.         protected void onCrafting(ItemStack par1ItemStack)
  76.             {
  77.                 par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b);
  78.  
  79.                 if (!this.thePlayer.worldObj.isRemote)
  80.                     {
  81.                         int i = this.field_75228_b;
  82.                         float f = FurnaceRecipes.smelting().getExperience(par1ItemStack);
  83.                         int j;
  84.  
  85.                         if (f == 0.0F)
  86.                             {
  87.                                 i = 0;
  88.                             }
  89.                         else
  90.                             if (f < 1.0F)
  91.                                 {
  92.                                     j = MathHelper.floor_float(i * f);
  93.  
  94.                                     if (j < MathHelper.ceiling_float_int(i * f) && (float) Math.random() < i * f - j)
  95.                                         {
  96.                                             ++j;
  97.                                         }
  98.  
  99.                                     i = j;
  100.                                 }
  101.  
  102.                         while (i > 0)
  103.                             {
  104.                                 j = EntityXPOrb.getXPSplit(i);
  105.                                 i -= j;
  106.                                 this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j));
  107.                             }
  108.                     }
  109.  
  110.                 this.field_75228_b = 0;
  111.  
  112.                 GameRegistry.onItemSmelted(thePlayer, par1ItemStack);
  113.  
  114.                 if (par1ItemStack.itemID == Item.ingotIron.itemID)
  115.                     {
  116.                         this.thePlayer.addStat(AchievementList.acquireIron, 1);
  117.                     }
  118.  
  119.                 if (par1ItemStack.itemID == Item.fishCooked.itemID)
  120.                     {
  121.                         this.thePlayer.addStat(AchievementList.cookFish, 1);
  122.                     }
  123.             }
  124.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement