@SubscribeEvent
 public void pickup(EntityItemPickupEvent event) {
   EntityPlayer player = event.entityPlayer;
   EntityItem eitem = event.item;
   ItemStack item = eitem.getEntityItem();
   if (item != null) {
     int c = -1;
     for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
       ItemStack stack = player.inventory.getStackInSlot(i);
       if (stack != null && stack.getItem() instanceof ItemBag) {
         BagInventory inv = ItemBag.getInventory(stack);
         if (inv.isUpgradeInstalled(Upgrade.COLLECTOR.getItem())) {
           c = i;
           break;
         }
       }
     }
     if (c != -1) {
       BagInventory inv = ItemBag.getInventory(player.inventory.getStackInSlot(c));
       ItemStack ret = InvUtil.putIntoFirstSlot(inv, item, false);
       if (ret == null) {
         event.setCanceled(true);
         eitem.setDead();
       } else if (!ItemStack.areItemStacksEqual(item, ret)) {
         eitem.setEntityItemStack(ret);
       }
     }
   }
 }
  @Override
  public void detectAndSendChanges() {
    for (int i = 0; i < this.crafters.size(); ++i) {
      ICrafting icrafting = (ICrafting) this.crafters.get(i);

      if (this.lastFuel != tile.fuel) {
        icrafting.sendProgressBarUpdate(this, 0, tile.fuel);
      }

      if (this.lastFuelMax != tile.maxFuel) {
        icrafting.sendProgressBarUpdate(this, 1, tile.maxFuel);
      }
    }
    this.lastFuel = tile.fuel;
    this.lastFuelMax = tile.maxFuel;

    for (int i = 0; i < this.inventorySlots.size(); ++i) {
      ItemStack itemstack = ((Slot) this.inventorySlots.get(i)).getStack();
      ItemStack itemstack1 = (ItemStack) this.inventoryItemStacks.get(i);

      if (!ItemStack.areItemStacksEqual(itemstack1, itemstack)) {
        if (isGuiContainer) {
          tile.onInventoryChanged();
        }

        itemstack1 = itemstack == null ? null : itemstack.copy();
        this.inventoryItemStacks.set(i, itemstack1);

        for (int j = 0; j < this.crafters.size(); ++j) {
          ((ICrafting) this.crafters.get(j)).sendSlotContents(this, i, itemstack1);
        }
      }
    }
  }
  /**
   * Prepares input to a pattern from the current recipe
   *
   * @param input
   * @param slotNumber
   * @return
   */
  private Object preparePatternInput(final Object input, final int slotNumber) {
    if (input instanceof ArrayList) {
      // Get the prefered item
      ItemStack preferedItem = this.craftingSlots[slotNumber].getStack();

      // Create the list
      ArrayList<ItemStack> ingList = new ArrayList<ItemStack>();

      // Add the prefered item first
      ingList.add(preferedItem);

      // Add the rest
      ArrayList<ItemStack> inputList = (ArrayList<ItemStack>) input;
      for (ItemStack item : inputList) {
        if ((item == null) || (ItemStack.areItemStacksEqual(preferedItem, item))) {
          continue;
        }
        ingList.add(item);
      }

      return ingList;
    }

    return input;
  }
Beispiel #4
0
  @Override
  public void detectAndSendChanges() {
    for (int var1 = 0; var1 < this.inventorySlots.size(); ++var1) {
      ItemStack var2 = ((Slot) this.inventorySlots.get(var1)).getStack();
      ItemStack var3 = (ItemStack) this.inventoryItemStacks.get(var1);

      if (!ItemStack.areItemStacksEqual(var3, var2)) {
        var3 = var2 == null ? null : var2.copy();
        this.inventoryItemStacks.set(var1, var3);

        for (int var4 = 0; var4 < this.crafters.size(); ++var4) {
          ((ICrafting) this.crafters.get(var4)).sendSlotContents(this, var1, var3);
        }
      }
    }
    for (int var1 = 0; var1 < this.crafters.size(); ++var1) {
      ICrafting var2 = (ICrafting) this.crafters.get(var1);
      if (this.soilamt != this.sluice.soilAmount) {
        var2.sendProgressBarUpdate(this, 0, this.sluice.soilAmount);
      }
      if (this.progress != this.sluice.processTimeRemaining) {
        var2.sendProgressBarUpdate(this, 1, this.sluice.processTimeRemaining);
      }
    }

    soilamt = this.sluice.soilAmount;
    progress = this.sluice.processTimeRemaining;
  }
  public void func_147068_g() {
    ItemStack var1 = inventorySlots.getSlot(0).getStack();

    if (!ItemStack.areItemStacksEqual(var1, field_147077_B)) {
      field_147077_B = var1;

      do field_147082_x += field_147074_F.nextInt(4) - field_147074_F.nextInt(4);
      while (field_147071_v <= field_147082_x + 1.0F && field_147071_v >= field_147082_x - 1.0F);
    }

    ++field_147073_u;
    field_147069_w = field_147071_v;
    field_147076_A = field_147080_z;
    boolean var2 = false;

    for (int var3 = 0; var3 < 3; ++var3) if (field_147075_G.enchantLevels[var3] != 0) var2 = true;

    if (var2) field_147080_z += 0.2F;
    else field_147080_z -= 0.2F;

    field_147080_z = MathHelper.clamp_float(field_147080_z, 0.0F, 1.0F);
    float var5 = (field_147082_x - field_147071_v) * 0.4F;
    float var4 = 0.2F;
    var5 = MathHelper.clamp_float(var5, -var4, var4);
    field_147081_y += (var5 - field_147081_y) * 0.9F;
    field_147071_v += field_147081_y;
  }
  public static boolean contains(ArrayList list, ItemStack stack) {
    if (stack == null || stack.getItem() == null) return false;

    Object object = stack.getItem();

    Material material = null;

    if (object instanceof ItemBlock) {
      object = Block.getBlockFromItem((Item) object);
      material = ((Block) object).getMaterial();
    }

    int[] ores = OreDictionary.getOreIDs(stack);

    for (int i = 0; i < list.size(); i++) {
      if (list.get(i) instanceof ItemStack
          && ItemStack.areItemStacksEqual(stack, (ItemStack) list.get(i))) return true;

      if (list.get(i) == object) return true;

      if (list.get(i) == material) return true;

      if (list.get(i) instanceof String)
        for (int j = 0; j < ores.length; j++) {
          if (OreDictionary.getOreName(ores[j]).contains((CharSequence) list.get(i))) return true;
        }
    }
    return false;
  }
 public static void removeRecipe(ItemStack match) {
   for (Iterator<Map.Entry<ItemStack[], ItemStack>> it =
           CircuitFabricatorRecipes.recipes.entrySet().iterator();
       it.hasNext(); ) {
     Map.Entry<ItemStack[], ItemStack> recipe = it.next();
     if (ItemStack.areItemStacksEqual(match, recipe.getValue())) it.remove();
   }
 }
 public boolean matches(ItemStack metal, ItemStack inputCast) {
   return MachineRecipeRegistry.isOreDictMatch(this.metal, metal)
       && metal.stackSize >= this.metal.stackSize
       && ((cast != null
               && cast.getItemDamage() == Short.MAX_VALUE
               && inputCast.getItem() == cast.getItem())
           || ItemStack.areItemStacksEqual(this.cast, inputCast));
 }
  @Override
  public boolean isUseableByPlayer(EntityPlayer player) {
    if (player == null) {
      return true;

    } else {
      return ItemStack.areItemStacksEqual(player.inventory.getCurrentItem(), stack);
    }
  }
Beispiel #10
0
 @Override
 public void setInventorySlotContents(int i, ItemStack is) {
   if (!ItemStack.areItemStacksEqual(storage[i], is)) {
     storage[i] = is;
     if (i == 0) {
       processItems();
       if (!getSealed()) this.unsealtime = (int) TFC_Time.getTotalHours();
     }
   }
 }
Beispiel #11
0
 public static void removeAnyRecipe(ItemStack resultItem) {
   List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
   for (int i = 0; i < recipes.size(); i++) {
     IRecipe tmpRecipe = recipes.get(i);
     ItemStack recipeResult = tmpRecipe.getRecipeOutput();
     if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
       recipes.remove(i--);
     }
   }
 }
  public boolean unregisterLowerTarget(ItemStack stack) {
    for (Record r : records) {
      if (ItemStack.areItemStacksEqual(stack, r.lower)) {
        records.remove(r);
        return true;
      }
    }

    return false;
  }
  @Override
  public void setInventorySlotContents(int par1, ItemStack par2ItemStack) {
    if (par1 == 1
        && (par2ItemStack == null && this.stackList[par1] != null
            || !ItemStack.areItemStacksEqual(par2ItemStack, this.stackList[par1]))) {
      ContainerSlimeling.addAdditionalSlots(
          (ContainerSlimeling) this.currentContainer, this.slimeling, par2ItemStack);
    }

    this.stackList[par1] = par2ItemStack;
  }
 // No NBT Comparision.
 public static boolean hasItemInInventory(
     EntityPlayer player, ItemStack itemStack, boolean shouldConsume, ItemStack replaceStack) {
   int index = 0;
   for (ItemStack tempStack : player.inventory.mainInventory) {
     if (tempStack != null && ItemStack.areItemStacksEqual(itemStack, tempStack)) {
       if (shouldConsume) player.inventory.mainInventory[index] = replaceStack;
       return true;
     }
     index++;
   }
   return false;
 }
  @Override
  public void setInventorySlotContents(int slot, ItemStack itemstack) {
    // reset heat if set to null or a different item
    if (itemstack == null
        || (getStackInSlot(slot) != null
            && !ItemStack.areItemStacksEqual(itemstack, getStackInSlot(slot)))) {
      itemTemperatures[slot] = 0;
    }
    super.setInventorySlotContents(slot, itemstack);

    // when an item gets added, check for its heat required
    updateHeatRequired(slot);
  }
 @Override
 public void loadUsageRecipes(ItemStack ingredient) {
   List<RecipeResearched> allrecipes = AWCraftingManager.INSTANCE.getRecipes();
   for (RecipeResearched irecipe : allrecipes) {
     for (ItemStack stack : irecipe.recipeItems) {
       if (stack == null) {
         continue;
       }
       if (ItemStack.areItemStacksEqual(stack, ingredient)) {
         arecipes.add(new AWCachedRecipe(irecipe));
       }
     }
   }
 }
 public void setOutput(ItemStack stack) {
   if (stack == null) {
     return;
   }
   // ensure that the output is valid
   for (ItemStack candidate : TinkerRegistry.getStencilTableCrafting()) {
     // NBT sensitive
     if (ItemStack.areItemStacksEqual(stack, candidate)) {
       // yay
       output = stack;
       updateResult();
       return;
     }
   }
 }
Beispiel #18
0
  /** Looks for changes made in the container, sends them to every listener. */
  public void detectAndSendChanges() {
    for (int var1 = 0; var1 < this.inventorySlots.size(); ++var1) {
      ItemStack var2 = ((Slot) this.inventorySlots.get(var1)).getStack();
      ItemStack var3 = (ItemStack) this.inventoryItemStacks.get(var1);

      if (!ItemStack.areItemStacksEqual(var3, var2)) {
        var3 = var2 == null ? null : var2.copy();
        this.inventoryItemStacks.set(var1, var3);

        for (int var4 = 0; var4 < this.crafters.size(); ++var4) {
          ((ICrafting) this.crafters.get(var4)).sendSlotContents(this, var1, var3);
        }
      }
    }
  }
  @Override
  public void onInventoryChanged() {
    for (int i = 0; i < 4; i++) {
      final ItemStack stack = getStackInSlot(i);
      if (stack != null) {

        final ItemStack findMatchingRecipe = CounterRecipes.getInstance().findMatchingRecipe(this);

        if (findMatchingRecipe != null
            && !ItemStack.areItemStacksEqual(stack, findMatchingRecipe)) {
          clearInventory(findMatchingRecipe);
          setInventorySlotContents(i, findMatchingRecipe);
        }
      }
    }
  }
  @SuppressWarnings("unchecked")
  private void removeRecipes(String toDelete) {
    ItemStack resultItem = new ItemStack((Item) Item.itemRegistry.getObject(toDelete));

    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

    for (int i = 0; i < recipes.size(); i++) {
      IRecipe tmpRecipe = recipes.get(i);
      ItemStack recipeResult = tmpRecipe.getRecipeOutput();
      if (resultItem != null && recipeResult != null) resultItem.stackSize = recipeResult.stackSize;

      if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
        recipes.remove(i--);
      }
    }
  }
Beispiel #21
0
  protected void resultSelected(ItemStack stack) {
    int prev = container.getCurrentIndex();

    container.resetCurrentIndex();

    for (int i = 0; i < container.getRecipeSize(); ++i) {
      if (ItemStack.areItemStacksEqual(stack, container.getNextRecipe(i))) {
        CraftingEX.NETWORK.sendToServer(new NextRecipeMessage(i));

        container.nextRecipe(i);

        return;
      }
    }

    container.nextRecipe(prev);
  }
 private boolean checkPassword(ItemStack[] pwd) {
   if (pwd == null || pwd.length != password.length) {
     return false;
   }
   for (int i = 0; i < pwd.length; i++) {
     ItemStack pw = password[i];
     ItemStack tst = pwd[i];
     if (pw == null && tst != null) {
       return false;
     }
     if (pw != null) {
       if (tst == null || !ItemStack.areItemStacksEqual(pw, tst)) {
         return false;
       }
     }
   }
   return true;
 }
  private void updateInventory() {
    ArrayList<ItemStack> itemList = new ArrayList<ItemStack>();
    SburbConnection c =
        SkaianetHandler.getClientConnection(
            ServerEditHandler.getData(player.getCommandSenderName()).getTarget());
    ArrayList<ItemStack> tools = new ArrayList<ItemStack>();
    // Fill list with tool items when implemented

    ArrayList<ItemStack> deployItems = DeployList.getItemList();
    Iterator<ItemStack> iter = deployItems.iterator();
    int playerTier = SessionHandler.availableTier(c.getClientName());
    while (iter.hasNext()) {
      ItemStack stack = iter.next();
      if (DeployList.getTier(stack) > playerTier) iter.remove();
      else if (Minestuck.hardMode
          && DeployList.getSecondaryCost(stack) == null
          && c.givenItems()[DeployList.getOrdinal(stack)]) iter.remove();
      else if (stack.getItem().equals(Minestuck.captchaCard))
        if (c.enteredGame()) iter.remove();
        else
          stack
              .getTagCompound()
              .setInteger("contentMeta", SessionHandler.getEntryItem(c.getClientName()));
    }

    for (int i = 0; i < Math.max(tools.size(), deployItems.size()); i++) {
      itemList.add(i >= tools.size() ? null : tools.get(i));
      itemList.add(i >= deployItems.size() ? null : deployItems.get(i));
    }

    boolean changed = false;
    if (itemList.size() != this.items.size()) changed = true;
    else
      for (int i = 0; i < itemList.size(); i++)
        if (!ItemStack.areItemStacksEqual(itemList.get(i), this.items.get(i))) {
          changed = true;
          break;
        }

    if (changed) {
      this.items = itemList;
      sendPacket();
    }
  }
 @Override
 public void tryUseDynamicLight(EntityPlayer player, ItemStack stack) {
   if (player == null && stack == null) {
     dynLightPlayerMod =
         Loader.instance().getIndexedModList().get("DynamicLights_thePlayer").getMod();
     try {
       if (dynLightPlayerMod != null) {
         dynLightFromItemStack =
             dynLightPlayerMod
                 .getClass()
                 .getDeclaredMethod("getLightFromItemStack", ItemStack.class);
         dynLightFromItemStack.setAccessible(true);
         refresh =
             Class.forName("mods.battlegear2.client.utils.DualHeldLight")
                 .getMethod("refresh", EntityPlayer.class, int.class, int.class);
       }
     } catch (Exception e) {
       return;
     }
   }
   if (dynLightFromItemStack != null && refresh != null) {
     if (!ItemStack.areItemStacksEqual(stack, heldCache)) {
       try {
         int lightNew = Integer.class.cast(dynLightFromItemStack.invoke(dynLightPlayerMod, stack));
         int lightOld =
             Integer.class.cast(dynLightFromItemStack.invoke(dynLightPlayerMod, heldCache));
         if (lightNew != lightOld) {
           refresh.invoke(null, player, lightNew, lightOld);
         }
       } catch (Exception e) {
         return;
       }
       heldCache = stack;
     }
   }
 }