public void refreshState() {
   hasValidItem =
       (inventory.getStackInSlot(slot) != null
           && ((inventory.getStackInSlot(slot).getItem() instanceof IConfigurableItem
                   && !((IConfigurableItem) inventory.getStackInSlot(slot).getItem())
                       .getFields(inventory.getStackInSlot(slot), slot)
                       .isEmpty())
               || inventory.getStackInSlot(slot).getItem() instanceof IInventoryTool));
 }
  @Override
  public void renderBackground(
      Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
    Minecraft.getMinecraft().renderEngine.bindTexture(texture);
    int heightOffset = isMouseOver(mouseX, mouseY) ? 36 : 18;
    if (!hasValidItem) drawTexturedModalRect(x, y, 0, 0, getWidth(), getHeight());
    else drawTexturedModalRect(x, y, 0, heightOffset, getWidth(), getHeight());

    if (inventory.getStackInSlot(slot) != null) {
      drawItemStack(inventory.getStackInSlot(slot), x + 1, y + 1, "null");
    }
  }
 @Override
 public void renderFinal(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
   if (isMouseOver(mouseX, mouseY) && hasValidItem) {
     List<String> list = new ArrayList<String>();
     List<ItemConfigField> fields =
         ((IConfigurableItem) inventory.getStackInSlot(slot).getItem())
             .getFields(inventory.getStackInSlot(slot), slot);
     for (ItemConfigField field : fields) {
       list.add(field.getLocalizedName() + ": " + field.getFormatedValue());
     }
     drawHoveringText(list, mouseX + offsetX, mouseY + offsetY + 10, fontRendererObj);
   }
 }
Esempio n. 4
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
     }
   }
 }
Esempio n. 5
0
  public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;
    InventoryPlayer var6 = par4EntityPlayer.inventory;
    Slot var7;
    ItemStack var8;
    int var10;
    ItemStack var11;

    if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
      if (par1 == -999) {
        if (var6.getItemStack() != null && par1 == -999) {
          if (par2 == 0) {
            par4EntityPlayer.dropPlayerItem(var6.getItemStack());
            var6.setItemStack((ItemStack) null);
          }

          if (par2 == 1) {
            // CraftBukkit start - store a reference
            ItemStack itemstack3 = var6.getItemStack();
            par4EntityPlayer.dropPlayerItem(itemstack3.splitStack(1));

            if (itemstack3.stackSize == 0) {
              // CraftBukkit end
              var6.setItemStack((ItemStack) null);
            }
          }
        }
      } else if (par3 == 1) {
        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null && var7.canTakeStack(par4EntityPlayer)) {
          var8 = this.transferStackInSlot(par4EntityPlayer, par1);

          if (var8 != null) {
            int var12 = var8.itemID;
            var5 = var8.copy();

            if (var7 != null && var7.getStack() != null && var7.getStack().itemID == var12) {
              this.retrySlotClick(par1, par2, true, par4EntityPlayer);
            }
          }
        }
      } else {
        if (par1 < 0) {
          return null;
        }

        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null) {
          var8 = var7.getStack();
          ItemStack var13 = var6.getItemStack();

          if (var8 != null) {
            var5 = var8.copy();
          }

          if (var8 == null) {
            if (var13 != null && var7.isItemValid(var13)) {
              var10 = par2 == 0 ? var13.stackSize : 1;

              if (var10 > var7.getSlotStackLimit()) {
                var10 = var7.getSlotStackLimit();
              }

              if (var13.stackSize >= var10) // CraftBukkit
              var7.putStack(var13.splitStack(var10));

              if (var13.stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          } else if (var7.canTakeStack(par4EntityPlayer)) {
            if (var13 == null) {
              var10 = par2 == 0 ? var8.stackSize : (var8.stackSize + 1) / 2;
              var11 = var7.decrStackSize(var10);
              var6.setItemStack(var11);

              if (var8.stackSize == 0) {
                var7.putStack((ItemStack) null);
              }

              var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
            } else if (var7.isItemValid(var13)) {
              if (var8.itemID == var13.itemID
                  && var8.getItemDamage() == var13.getItemDamage()
                  && ItemStack.areItemStackTagsEqual(var8, var13)) {
                var10 = par2 == 0 ? var13.stackSize : 1;

                if (var10 > var7.getSlotStackLimit() - var8.stackSize) {
                  var10 = var7.getSlotStackLimit() - var8.stackSize;
                }

                if (var10 > var13.getMaxStackSize() - var8.stackSize) {
                  var10 = var13.getMaxStackSize() - var8.stackSize;
                }

                var13.splitStack(var10);

                if (var13.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }

                var8.stackSize += var10;
              } else if (var13.stackSize <= var7.getSlotStackLimit()) {
                var7.putStack(var13);
                var6.setItemStack(var8);
              }
            } else if (var8.itemID == var13.itemID
                && var13.getMaxStackSize() > 1
                && (!var8.getHasSubtypes() || var8.getItemDamage() == var13.getItemDamage())
                && ItemStack.areItemStackTagsEqual(var8, var13)) {
              var10 = var8.stackSize;

              if (var10 > 0 && var10 + var13.stackSize <= var13.getMaxStackSize()) {
                var13.stackSize += var10;
                var8 = var7.decrStackSize(var10);

                if (var8.stackSize == 0) {
                  var7.putStack((ItemStack) null);
                }

                var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
              }
            }
          }

          var7.onSlotChanged();
        }
      }
    } else if (par3 == 2 && par2 >= 0 && par2 < 9) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7.canTakeStack(par4EntityPlayer)) {
        var8 = var6.getStackInSlot(par2);
        boolean var9 = var8 == null || var7.inventory == var6 && var7.isItemValid(var8);
        var10 = -1;

        if (!var9) {
          var10 = var6.getFirstEmptyStack();
          var9 |= var10 > -1;
        }

        if (var7.getHasStack() && var9) {
          var11 = var7.getStack();
          var6.setInventorySlotContents(par2, var11);

          if ((var7.inventory != var6 || !var7.isItemValid(var8)) && var8 != null) {
            if (var10 > -1) {
              var6.addItemStackToInventory(var8);
              var7.decrStackSize(var11.stackSize);
              var7.putStack((ItemStack) null);
              var7.onPickupFromSlot(par4EntityPlayer, var11);
            }
          } else {
            var7.decrStackSize(var11.stackSize);
            var7.putStack(var8);
            var7.onPickupFromSlot(par4EntityPlayer, var11);
          }
        } else if (!var7.getHasStack() && var8 != null && var7.isItemValid(var8)) {
          var6.setInventorySlotContents(par2, (ItemStack) null);
          var7.putStack(var8);
        }
      }
    } else if (par3 == 3
        && par4EntityPlayer.capabilities.isCreativeMode
        && var6.getItemStack() == null
        && par1 >= 0) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7 != null && var7.getHasStack()) {
        var8 = var7.getStack().copy();
        var8.stackSize = var8.getMaxStackSize();
        var6.setItemStack(var8);
      }
    }

    return var5;
  }