Java Code Examples for net.minecraft.item.ItemStack#getHasSubtypes()

The following examples show how to use net.minecraft.item.ItemStack#getHasSubtypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileEntityAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
private boolean canChisel(ItemStack toMerge) {
	// if the output slot is empty we can merge without checking
	if (inventory[OUTPUT] == null) {
		return true;
	}

	// need to check NBT as well as item
	if (!toMerge.isItemEqual(inventory[OUTPUT]) || !ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) {
		return false;
	}

	// we only care about metadata if the item has subtypes
	if (toMerge.getHasSubtypes() && toMerge.getItemDamage() != inventory[OUTPUT].getItemDamage()) {
		return false;
	}

	return ((IChiselItem) inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(getTarget()));
}
 
Example 2
Source File: ToolSpecificStat.java    From GokiStats with MIT License 6 votes vote down vote up
public void addSupportForItem(ItemStack item) {
    reloadConfig();
    if (item == null) {
        return;
    }
    boolean hasSubtypes = item.getHasSubtypes();
    int id = Item.getIdFromItem(item.getItem());
    int meta = 0;

    if (hasSubtypes) {
        meta = item.getItemDamage();
    }
    ItemIdMetadataTuple iimt = new ItemIdMetadataTuple(item.getItem().getRegistryName().toString(), meta);
    if (!this.supports.contains(iimt)) {
        this.supports.add(iimt);
    }
    saveConfig();
}
 
Example 3
Source File: ToolSpecificStat.java    From GokiStats with MIT License 6 votes vote down vote up
public void removeSupportForItem(ItemStack item) {
    if (item != null) {
        ItemIdMetadataTupleComparator iimtc = new ItemIdMetadataTupleComparator();
        reloadConfig();

        ItemIdMetadataTuple iimt = new ItemIdMetadataTuple(item.getItem().getRegistryName().toString(), 0);
        if (item.getHasSubtypes()) {
            iimt.metadata = item.getItemDamage();
        }
        for (int i = 0; i < this.supports.size(); i++) {
            ItemIdMetadataTuple ii = this.supports.get(i);
            if (iimtc.compare(iimt, ii) == 1) {
                this.supports.remove(ii);
                i--;
            }
        }

        saveConfig();
    }
}
 
Example 4
Source File: ItemConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Item getNovaItem(ItemStack itemStack) {
	if (itemStack.getItemDamage() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE) {
		// TODO: Deal withPriority wildcard meta values - important for the ore dictionary
		return getNovaItem(new ItemStack(itemStack.getItem(), 1, 0));
	}

	if (itemStack.getTagCompound() != null && itemStack.getTagCompound() instanceof FWNBTTagCompound) {
		return ((FWNBTTagCompound) itemStack.getTagCompound()).getItem();
	} else {
		ItemFactory itemFactory = registerMinecraftMapping(itemStack.getItem(), itemStack.getItemDamage());

		Data data = itemStack.getTagCompound() != null ? DataConverter.instance().toNova(itemStack.getTagCompound()) : new Data();
		if (!itemStack.getHasSubtypes() && itemStack.getItemDamage() > 0) {
			data.put("damage", itemStack.getItemDamage());
		}

		return itemFactory.build(data);
	}
}
 
Example 5
Source File: ItemConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Item getNovaItem(ItemStack itemStack) {
	if (itemStack.getItemDamage() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE) {
		// TODO: Deal withPriority wildcard meta values - important for the ore dictionary
		return getNovaItem(new ItemStack(itemStack.getItem(), 1, 0));
	}

	if (itemStack.getTagCompound() != null && itemStack.getTagCompound() instanceof FWNBTTagCompound) {
		return ((FWNBTTagCompound) itemStack.getTagCompound()).getItem();
	} else {
		ItemFactory itemFactory = registerMinecraftMapping(itemStack.getItem(), itemStack.getItemDamage());

		Data data = itemStack.getTagCompound() != null ? DataConverter.instance().toNova(itemStack.getTagCompound()) : new Data();
		if (!itemStack.getHasSubtypes() && itemStack.getItemDamage() > 0) {
			data.put("damage", itemStack.getItemDamage());
		}

		return itemFactory.build(data);
	}
}
 
Example 6
Source File: ToolSpecificStat.java    From GokiStats with MIT License 5 votes vote down vote up
public boolean isItemSupported(ItemStack item) {
    for (ItemIdMetadataTuple iimt : this.supports) {
        if (Objects.equals(item.getItem().getRegistryName().toString(), iimt.id)) {
            if (item.getHasSubtypes() && item.getItemDamage() == iimt.metadata) {
                return true;
            } else if (!item.getHasSubtypes()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean canStack(ItemStack stack1, ItemStack stack2) {
    return stack1 == null || stack2 == null ||
            (stack1.getItem() == stack2.getItem() &&
                    (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) &&
                    ItemStack.areItemStackTagsEqual(stack2, stack1)) &&
                    stack1.isStackable();
}
 
Example 8
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
/**
 * @param stack1 The {@link ItemStack} being compared.
 * @param stack2 The {@link ItemStack} to compare to.
 * @return whether the two items are the same in terms of damage and itemID.
 */
public static boolean areStacksSameType(ItemStack stack1, ItemStack stack2) {
    return stack1 != null && stack2 != null &&
            (stack1.getItem() == stack2.getItem() &&
            (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) &&
            ItemStack.areItemStackTagsEqual(stack2, stack1));
}
 
Example 9
Source File: SatelliteRegistry.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * @param stack ItemStack to get the SatelliteProperties of, stacksize insensative 
 * @return the registered SatelliteProperties of the stack, or null if not registered
 */
public static SatelliteProperties getSatelliteProperty(ItemStack stack) {
	
	for(ItemStack keyStack : itemPropertiesRegistry.keySet()) {
		if(keyStack.getItem() == stack.getItem() && ( !keyStack.getHasSubtypes() || keyStack.getItemDamage() == stack.getItemDamage()) ) {
			return itemPropertiesRegistry.get(keyStack);
		}
	}
	
	return null;
}
 
Example 10
Source File: ItemConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public MinecraftItemMapping(ItemStack itemStack) {
	this.item = itemStack.getItem();
	this.meta = itemStack.getHasSubtypes() ? itemStack.getItemDamage() : 0;
}
 
Example 11
Source File: ContainerSeedStorageBase.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Tries to merge an itemstack into a range of slots, return true if the stack was (partly)
 * merged
 */
@Override
protected boolean mergeItemStack(ItemStack stack, int startSlot, int endSlot, boolean iterateBackwards) {
    boolean flag = false;
    int k = iterateBackwards ? endSlot - 1 : startSlot;
    Slot currentSlot;
    ItemStack currentStack;
    //look for identical stacks to merge with
    while (stack.getCount() > 0 && (!iterateBackwards && k < endSlot || iterateBackwards && k >= startSlot)) {
        currentSlot = this.inventorySlots.get(k);
        currentStack = currentSlot.getStack();
        if (currentStack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == currentStack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, currentStack)) {
            int l = currentStack.getCount() + stack.getCount();
            //total stacksize is smaller than the limit: merge entire stack into this stack
            if (l <= stack.getMaxStackSize()) {
                stack.setCount(0);
                currentStack.setCount(l);
                currentSlot.onSlotChanged();
                flag = true;
            } //total stacksize exceeds the limit: merge part of the stack into this stack
            else if (currentStack.getCount() < stack.getMaxStackSize()) {
                stack.setCount(stack.getCount() - stack.getMaxStackSize() - currentStack.getCount());
                currentStack.setCount(stack.getMaxStackSize());
                currentSlot.onSlotChanged();
                flag = true;
            }
        }
        k = iterateBackwards ? k - 1 : k + 1;
    }
    //couldn't completely merge stack with an existing slot, find the first empty slot to put the rest of the stack in
    if (stack.getCount() > 0) {
        k = iterateBackwards ? endSlot - 1 : startSlot;
        while (!iterateBackwards && k < endSlot || iterateBackwards && k >= startSlot) {
            currentSlot = this.inventorySlots.get(k);
            currentStack = currentSlot.getStack();
            if (currentStack.isEmpty()) {
                currentSlot.putStack(stack.copy());
                currentSlot.onSlotChanged();
                stack.setCount(0);
                flag = true;
                break;
            }
            k = iterateBackwards ? k - 1 : k + 1;
        }
    }
    return flag;
}
 
Example 12
Source File: InventoryPlayerTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean stackEqualExact(ItemStack stack1, ItemStack stack2)
{
	return stack1.getItem() == stack2.getItem() && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) && 
			(ItemStack.areItemStackTagsEqual(stack1, stack2) || (stack1.getItem() instanceof IFood && stack2.getItem() instanceof IFood && Food.areEqual(stack1, stack2)));
}
 
Example 13
Source File: ItemConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public MinecraftItemMapping(ItemStack itemStack) {
	this.item = itemStack.getItem();
	this.meta = itemStack.getHasSubtypes() ? itemStack.getItemDamage() : 0;
}
 
Example 14
Source File: BWItem.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BWItem(ItemStack itemStack) {
	this(itemStack.getItem(), itemStack.getHasSubtypes() ? itemStack.getItemDamage() : 0, itemStack.getTagCompound());
}
 
Example 15
Source File: Utils.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean stackEqualExact(ItemStack stack1, ItemStack stack2) {
	return stack1.getItem() == stack2.getItem() && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) && ItemStack.areItemStackTagsEqual(stack1, stack2);
}
 
Example 16
Source File: BWItem.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BWItem(ItemStack itemStack) {
	this(itemStack.getItem(), itemStack.getHasSubtypes() ? itemStack.getItemDamage() : 0, itemStack.getTagCompound());
}
 
Example 17
Source File: TileItemTranslocator.java    From Translocators with MIT License 4 votes vote down vote up
private boolean matches(ItemStack stack, ItemStack filter)
{
    return stack.getItem() == filter.getItem() &&
        (!filter.getHasSubtypes() || filter.getItemDamage() == stack.getItemDamage()) && 
        ItemStack.areItemStackTagsEqual(filter, stack);
}
 
Example 18
Source File: BWItem.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BWItem(ItemStack itemStack) {
	this(itemStack.getItem(), itemStack.getHasSubtypes() ? itemStack.getItemDamage() : 0, itemStack.getTagCompound(), itemStack.serializeNBT().getCompoundTag("ForgeCaps"));
}
 
Example 19
Source File: ContainerPedestal.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
protected boolean mergeItemStack(ItemStack itemstack, int i, int j, boolean flag) {
	// The default implementation in Slot doesn't take into account the Slot.isItemValid() and Slot.getSlotStackLimit() values.
	// So here is a modified implementation. I have only modified the parts with a comment.

	boolean flag1 = false;
	int k = i;
	if (flag) {
		k = j - 1;
	}
	if (itemstack.isStackable()) {
		while (itemstack.stackSize > 0 && (!flag && k < j || flag && k >= i)) {
			Slot slot = (Slot)inventorySlots.get(k);
			ItemStack itemstack1 = slot.getStack();

			if (flag) {
				k--;
			}
			else {
				k++;
			}

			// Check if item is valid:
			if (!slot.isItemValid(itemstack)) {
				continue;
			}

			if (itemstack1 != null && itemstack1.getItem() == itemstack.getItem() && (!itemstack.getHasSubtypes() || itemstack.getItemDamage() == itemstack1.getItemDamage())
					&& ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) {
				//ItemStack.areItemStacksEqual(par0ItemStack, par1ItemStack)
				//ItemStack.areItemStackTagsEqual(par0ItemStack, par1ItemStack)
				int i1 = itemstack1.stackSize + itemstack.stackSize;

				// Don't put more items than the slot can take:
				int maxItemsInDest = Math.min(itemstack1.getMaxStackSize(), slot.getSlotStackLimit());

				if (i1 <= maxItemsInDest) {
					itemstack.stackSize = 0;
					itemstack1.stackSize = i1;
					slot.onSlotChanged();
					flag1 = true;
				}
				else if (itemstack1.stackSize < maxItemsInDest) {
					itemstack.stackSize -= maxItemsInDest - itemstack1.stackSize;
					itemstack1.stackSize = maxItemsInDest;
					slot.onSlotChanged();
					flag1 = true;
				}
			}

		}
	}
	if (itemstack.stackSize > 0) {
		int l;
		if (flag) {
			l = j - 1;
		}
		else {
			l = i;
		}
		do {
			if ((flag || l >= j) && (!flag || l < i)) {
				break;
			}
			Slot slot1 = (Slot)inventorySlots.get(l);
			ItemStack itemstack2 = slot1.getStack();

			if (flag) {
				l--;
			}
			else {
				l++;
			}

			// Check if item is valid:
			if (!slot1.isItemValid(itemstack)) {
				continue;
			}

			if (itemstack2 == null) {

				// Don't put more items than the slot can take:
				int nbItemsInDest = Math.min(itemstack.stackSize, slot1.getSlotStackLimit());
				ItemStack itemStack1 = itemstack.copy();
				itemstack.stackSize -= nbItemsInDest;
				itemStack1.stackSize = nbItemsInDest;

				slot1.putStack(itemStack1);
				slot1.onSlotChanged();
				// itemstack.stackSize = 0;
				flag1 = true;
				break;
			}
		} while (true);
	}
	return flag1;
}
 
Example 20
Source File: MinecraftTypeHelper.java    From malmo with MIT License 4 votes vote down vote up
/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform.
 * @param is the ItemStack containing the item we are attempting to deconstruct.
 * @return an XML DrawItem object containing the item's type, variant, colour etc.
 */
public static DrawItem getDrawItemFromItemStack(ItemStack is)
{
    if (is == null)
        return null;

    DrawItem di = new DrawItem();
    String name = is.getUnlocalizedName();  // Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata.
    if (is.getHasSubtypes())
    {
        // If the item has subtypes, then there are varieties - eg different colours, types, etc.
        // Attempt to map from these subtypes back to variant/colour.
        // Do this by decomposing the unlocalised name:
        List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\.")));
        if (is.getItem() instanceof ItemMonsterPlacer)
        {
            // Special case for eggs:
            itemParts.add(ItemMonsterPlacer.getNamedIdFrom(is).toString());
        }
        // First part will be "tile" or "item".
        // Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc).
        // Third part will be the variant, colour etc.
        Colour col = null;
        Variation var = null;
        for (int part = 2; part < itemParts.size(); part++)
        {
            String section = itemParts.get(part);
            // First see if this matches a colour:
            if (col == null)
            {
                col = attemptToGetAsColour(section);
                if (col == null && var == null) // If it wasn't a colour, check to see if it was a variant:
                    var = attemptToGetAsVariant(section, is);
            }
            else if (var == null)
                var = attemptToGetAsVariant(section, is);
        }
        di.setColour(col);
        di.setVariant(var);
    }
    // Use the item registry name for the item - this is what we use in Types.XSD
    Object obj = Item.REGISTRY.getNameForObject(is.getItem());
    String publicName;
    if (obj instanceof ResourceLocation)
        publicName = ((ResourceLocation)obj).getResourcePath();
    else
        publicName = obj.toString();
    di.setType(publicName);
    return di;
}