Advertisement
HalestormXV

Untitled

Feb 10th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package halestormxv.objects.blocks.devices.inscriber;
  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.ItemStack;
  8. import net.minecraft.util.math.MathHelper;
  9.  
  10. public class SlotInscriberOutput extends Slot
  11. {
  12.     private final EntityPlayer player;
  13.     private int removeCount;
  14.  
  15.     public SlotInscriberOutput(EntityPlayer player, IInventory inventoryIn, int index, int xPosition, int yPosition)
  16.     {
  17.         super(inventoryIn, index, xPosition, yPosition);
  18.         this.player = player;
  19.     }
  20.  
  21.     @Override
  22.     public boolean isItemValid(ItemStack stack)
  23.     {
  24.         return false;
  25.     }
  26.  
  27.     @Override
  28.     public ItemStack decrStackSize(int amount)
  29.     {
  30.         if(this.getHasStack())
  31.             this.removeCount += Math.min(amount, this.getStack().getCount());
  32.         return super.decrStackSize(amount);
  33.     }
  34.  
  35.     @Override
  36.     public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
  37.     {
  38.         this.onCrafting(stack);
  39.         super.onTake(thePlayer, stack);
  40.         return stack;
  41.     }
  42.  
  43.     @Override
  44.     protected void onCrafting(ItemStack stack, int amount)
  45.     {
  46.         this.removeCount += amount;
  47.         this.onCrafting(stack);
  48.     }
  49.  
  50.     @Override
  51.     protected void onCrafting(ItemStack stack)
  52.     {
  53.         stack.onCrafting(this.player.world, this.player, this.removeCount);
  54.  
  55.         if(!this.player.world.isRemote)
  56.         {
  57.             int i = this.removeCount;
  58.             float f = RunicInscriberRecipes.getInstance().getInscriberExperience(stack);
  59.  
  60.             if(f == 0.0F)
  61.                 i = 0;
  62.             else if(f < 1.0F) {
  63.                 int j = MathHelper.floor((float)i * f);
  64.  
  65.                 if(j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
  66.                     ++j;
  67.                 i = j;
  68.             }
  69.             while (i > 0)
  70.             {
  71.                 int k = EntityXPOrb.getXPSplit(i);
  72.                 i -= k;
  73.  
  74.                 this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
  75.             }
  76.         }
  77.         this.removeCount = 0;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement