public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
    if ("MC|BEdit".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        ItemStack itemstack = Packet.readItemStack(datainputstream);

        if (!ItemWritableBook.validBookTagPages(itemstack.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        ItemStack itemstack2 = playerEntity.inventory.getCurrentItem();

        if (itemstack != null
            && itemstack.itemID == Item.writableBook.shiftedIndex
            && itemstack.itemID == itemstack2.itemID) {
          itemstack2.setTagCompound(itemstack.getTagCompound());
        }
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    } else if ("MC|BSign".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream1 =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        ItemStack itemstack1 = Packet.readItemStack(datainputstream1);

        if (!ItemEditableBook.validBookTagContents(itemstack1.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        ItemStack itemstack3 = playerEntity.inventory.getCurrentItem();

        if (itemstack1 != null
            && itemstack1.itemID == Item.writtenBook.shiftedIndex
            && itemstack3.itemID == Item.writableBook.shiftedIndex) {
          itemstack3.setTagCompound(itemstack1.getTagCompound());
          itemstack3.itemID = Item.writtenBook.shiftedIndex;
        }
      } catch (Exception exception1) {
        exception1.printStackTrace();
      }
    } else if ("MC|TrSel".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream2 =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        int i = datainputstream2.readInt();
        Container container = playerEntity.craftingInventory;

        if (container instanceof ContainerMerchant) {
          ((ContainerMerchant) container).setCurrentRecipeIndex(i);
        }
      } catch (Exception exception2) {
        exception2.printStackTrace();
      }
    } else {
      ModLoader.serverCustomPayload(this, par1Packet250CustomPayload);
    }
  }
Example #2
0
 @Override
 public int hashCode() {
   int hash = 7;
   hash = 41 * hash + stack.getItem().hashCode();
   hash = 41 * hash + stack.getItemDamage();
   hash = 41 * hash + stack.getCount();
   hash = 41 * hash + (stack.getTagCompound() == null ? 0 : stack.getTagCompound().hashCode());
   hash = 41 * hash + (this.wildcardSize ? 1 : 0);
   return hash;
 }
Example #3
0
  @Override
  public IData getTag() {
    if (tag == null) {
      if (stack.getTagCompound() == null) {
        return DataMap.EMPTY;
      }

      tag = NBTConverter.from(stack.getTagCompound(), true);
    }
    return tag;
  }
Example #4
0
  @Override
  public IItemStack removeTag(String tag) {
    ItemStack result = new ItemStack(stack.getItem(), stack.getCount(), stack.getItemDamage());

    if (tag == null) {
      result.setTagCompound(null);
    } else {
      result.getTagCompound().removeTag(tag);
    }
    IData dataTag = NBTConverter.from(result.getTagCompound(), false);
    return new MCItemStack(result, dataTag);
  }
Example #5
0
  @Override
  public IItemStack updateTag(IData tagUpdate) {
    if (tag == null) {
      if (stack.getTagCompound() == null) {
        return withTag(tagUpdate);
      }

      tag = NBTConverter.from(stack.getTagCompound(), true);
    }

    IData updated = tag.update(tagUpdate);
    return withTag(updated);
  }
Example #6
0
 @Override
 public IItemStack withDamage(int damage) {
   if (stack.getItem().getHasSubtypes()) {
     MineTweakerAPI.logWarning("subitems don't have damaged states");
     return this;
   } else {
     ItemStack result = new ItemStack(stack.getItem(), stack.getCount(), damage);
     result.setTagCompound(stack.getTagCompound());
     return new MCItemStack(result, tag);
   }
 }
Example #7
0
  @Override
  public String toString() {
    StringBuilder result = new StringBuilder();
    result.append('<');
    result.append(Item.REGISTRY.getNameForObject(stack.getItem()));

    if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
      result.append(":*");
    } else if (stack.getItemDamage() > 0) {
      result.append(':').append(stack.getItemDamage());
    }
    result.append('>');

    if (stack.getTagCompound() != null) {
      result.append(".withTag(");
      result.append(NBTConverter.from(stack.getTagCompound(), wildcardSize).toString());
      result.append(")");
    }

    return result.toString();
  }
Example #8
0
 @Override
 public IIngredient anyDamage() {
   if (stack.getItem().getHasSubtypes()) {
     MineTweakerAPI.logWarning("subitems don't have damaged states");
     return this;
   } else {
     ItemStack result =
         new ItemStack(stack.getItem(), stack.getCount(), OreDictionary.WILDCARD_VALUE);
     result.setTagCompound(stack.getTagCompound());
     return new MCItemStack(result, tag);
   }
 }
Example #9
0
 @Override
 public boolean matchesExact(IItemStack item) {
   ItemStack internal = getItemStack(item);
   if (internal.getTagCompound() != null && stack.getTagCompound() == null) {
     return false;
   }
   if (internal.getTagCompound() == null && stack.getTagCompound() != null) {
     return false;
   }
   if (internal.getTagCompound() == null && stack.getTagCompound() == null) {
     return stack.getItem() == internal.getItem()
         && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata());
   }
   if (internal.getTagCompound().getKeySet().equals(stack.getTagCompound().getKeySet())) {
     for (String s : internal.getTagCompound().getKeySet()) {
       if (!internal.getTagCompound().getTag(s).equals(stack.getTagCompound().getTag(s))) {
         return false;
       }
     }
   }
   return stack.getItem() == internal.getItem()
       && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata());
 }
Example #10
0
 @Override
 public IItemStack withAmount(int amount) {
   ItemStack result = new ItemStack(stack.getItem(), amount, stack.getItemDamage());
   result.setTagCompound(stack.getTagCompound());
   return new MCItemStack(result, tag);
 }
Example #11
0
 @Override
 public IItemStack anyAmount() {
   ItemStack result = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
   result.setTagCompound(stack.getTagCompound());
   return new MCItemStack(result, tag, true);
 }