/**
   * @author blood - May 13th, 2016
   * @reason SpongeForge requires an overwrite so we do it here instead.
   */
  @Overwrite
  public EntityItem dropOneItem(boolean dropAll) {
    if (this.worldObj.isRemote) {
      return this.dropItem(
          this.inventory.decrStackSize(
              this.inventory.currentItem,
              dropAll && this.inventory.getCurrentItem() != null
                  ? this.inventory.getCurrentItem().stackSize
                  : 1),
          false,
          true);
    }

    ItemStack stack = inventory.getCurrentItem();

    if (stack == null) {
      return null;
    }

    if (SpongeImplHooks.onDroppedByPlayer(stack.getItem(), stack, (EntityPlayer) (Object) this)) {
      int count =
          dropAll && this.inventory.getCurrentItem() != null
              ? this.inventory.getCurrentItem().stackSize
              : 1;
      return SpongeImplHooks.onPlayerToss(
          (EntityPlayer) (Object) this,
          inventory.decrStackSize(inventory.currentItem, count),
          true);
    }

    return null;
  }
Пример #2
0
 public void buyGun(int i, InventoryPlayer inventory, GunBoxType type) {
   if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
     FlansMod.proxy.buyGun(type, i);
   }
   if (i <= type.numGuns && type.guns[i] != null) {
     boolean canBuy = true;
     for (ItemStack check : type.gunParts[i]) {
       int numMatchingStuff = 0;
       for (int j = 0; j < inventory.getSizeInventory(); j++) {
         ItemStack stack = inventory.getStackInSlot(j);
         if (stack != null
             && stack.itemID == check.itemID
             && stack.getItemDamage() == check.getItemDamage()) {
           numMatchingStuff += stack.stackSize;
         }
       }
       if (numMatchingStuff < check.stackSize) {
         canBuy = false;
       }
     }
     if (canBuy) {
       for (ItemStack remove : type.gunParts[i]) {
         int amountLeft = remove.stackSize;
         for (int j = 0; j < inventory.getSizeInventory(); j++) {
           ItemStack stack = inventory.getStackInSlot(j);
           if (amountLeft > 0
               && stack != null
               && stack.itemID == remove.itemID
               && stack.getItemDamage() == remove.getItemDamage()) {
             amountLeft -= inventory.decrStackSize(j, amountLeft).stackSize;
           }
         }
       }
       if (!inventory.addItemStackToInventory(new ItemStack(type.guns[i].getItem()))) {
         // Drop gun on floor
       }
     } else {
       // Cant buy
       // TODO : Add flashing red squares around the items you lack
     }
   }
 }