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

The following examples show how to use net.minecraft.item.ItemStack#areItemsEqual() . 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: OreDictionaryCrusherRecipe.java    From BaseMetals with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Checks if the given ItemStack instance is the input for this recipe.
 * @param input An ItemStack to test
 * @return Returns true if and only if this recipe should produce an output item from the given 
 * input.
 */
@Override
public boolean isValidInput(ItemStack input) {
	List<ItemStack> validInputs = OreDictionary.getOres(oreDictSource);
	for(int i = 0; i < validInputs.size(); i++){
		if(validInputs.get(i).getMetadata() == OreDictionary.WILDCARD_VALUE){
			// do not compare metadata values
			if(validInputs.get(i).getItem() == input.getItem()){
				return true;
			}
		} else if(ItemStack.areItemsEqual(validInputs.get(i),input)){
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: TileEntitySoymilkAggregator.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean canWork() {
    if (energy >= POWER) { //If energy is suitable
        if (cachedRecipe != null) {
            //Check if current recipe is the same as cached, prevent force refreshing.
            if (!RecipesUtil.compareItems(cachedRecipe.getKey(), this.inventory.get(0))) {
                cachedRecipe = AggregatorRecipes.getResult(this.inventory.get(0));
                processTime = 0;
            }
        } else {
            cachedRecipe = AggregatorRecipes.getResult(this.inventory.get(0));
        }
    }
    // If:
    // 1. have suitable power
    // 2. have suitable recipe
    // 3. is the recipe output equals to the current output
    // 4. Is the current output not full.
    return energy >= POWER + POWER_PASSIVE &&
            cachedRecipe != null &&
            input.getFluidAmount() >= 10 &&
            (inventory.get(1).isEmpty() ||
                    (ItemStack.areItemsEqual(cachedRecipe.getValue(), inventory.get(1)) &&
                            inventory.get(1).getCount() < inventory.get(1).getMaxStackSize()));
}
 
Example 3
Source File: ModuleInstance.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets all of the itemstacks in the player's inventory that match a given itemstack
 * Modified to take a blockstate instead for convenience.
 */
public final List<ItemStack> getAllOfStackFromInventory(@Nonnull EntityPlayer player, @Nonnull IBlockState state) {
	List<ItemStack> stacks = new ArrayList<>();

	World world = player.world;
	ItemStack search = state.getBlock().getItem(world, null, state);

	if (search.isEmpty()) return stacks;

	for (ItemStack stack : player.inventory.mainInventory) {
		if (stack == null || stack.isEmpty()) continue;
		if (!(stack.getItem() instanceof ItemBlock)) continue;

		if (!ItemStack.areItemsEqual(stack, search)) continue;

		stacks.add(stack);
	}

	return stacks;
}
 
Example 4
Source File: KilnManager.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public KilnEntry matches(ItemStack is)
{
	for(KilnEntry entry : recipeMap)
	{
		if(ItemStack.areItemsEqual(is, entry.inStack))
			return entry;
	}
	return null;
}
 
Example 5
Source File: ItemMetalAxe.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean getIsRepairable(final ItemStack intputItem, final ItemStack repairMaterial) {
	List<ItemStack> acceptableItems = OreDictionary.getOres(repairOreDictName);
	for(ItemStack i : acceptableItems ){
		if(ItemStack.areItemsEqual(i, repairMaterial)) return true;
	}
	return false;
}
 
Example 6
Source File: ItemStackKey.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof ItemStackKey)) return false;
    ItemStackKey that = (ItemStackKey) o;
    return ItemStack.areItemsEqual(itemStack, that.itemStack) &&
        ItemStack.areItemStackTagsEqual(itemStack, that.itemStack);
}
 
Example 7
Source File: CraftingHelper.java    From malmo with MIT License 5 votes vote down vote up
/**
 * Compare two ItemStacks and see if their items match - take wildcards into account, don't take stacksize into account.
 *
 * @param A ItemStack A
 * @param B ItemStack B
 * @return true if the stacks contain matching items.
 */
private static boolean itemStackIngredientsMatch(ItemStack A, ItemStack B) {
    if (A == null && B == null)
        return true;
    if (A == null || B == null)
        return false;
    if (A.getMetadata() == OreDictionary.WILDCARD_VALUE || B.getMetadata() == OreDictionary.WILDCARD_VALUE)
        return A.getItem() == B.getItem();
    return ItemStack.areItemsEqual(A, B);
}
 
Example 8
Source File: SakuraEventLoader.java    From Sakura_mod with MIT License 5 votes vote down vote up
@SubscribeEvent
   public static void onFuelRegister(FurnaceFuelBurnTimeEvent event) {
   	if(ItemStack.areItemsEqual(event.getItemStack(), new ItemStack(BlockLoader.BAMBOO)))
   		event.setBurnTime(400);
   	if(ItemStack.areItemsEqual(event.getItemStack(), new ItemStack(ItemLoader.MATERIAL, 1,51)))
   		event.setBurnTime(1600);
   	if(ItemStack.areItemsEqual(event.getItemStack(), new ItemStack(BlockLoader.BAMBOO_CHARCOAL_BLOCK)))
   		event.setBurnTime(8000);
}
 
Example 9
Source File: BlockGrapeSplintStand.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack heldSeed = playerIn.getHeldItem(hand);
	if(worldIn.isRemote) return true;
	if(ItemStack.areItemsEqual(heldSeed, new ItemStack(ItemLoader.MATERIAL, 1, 23))){
		worldIn.setBlockState(pos, BlockLoader.GRAPE_VINE.getDefaultState().withProperty(BlockVanillaCrop.AGE, 0));
		if(!playerIn.isCreative())heldSeed.shrink(1);
		return true;
	}
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 10
Source File: TofuCatalystMap.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public static void removeCatalyst(ItemStack catalyst) {
    for (ItemStack key : catalystEffMap.keySet()) {
        if (ItemStack.areItemsEqual(key, catalyst)) {
            catalystEffMap.remove(key);
            break;
        }
    }
}
 
Example 11
Source File: PlayerInventoryHolder.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Will replace current item in hand with the given one
 * will also update sample item to this item
 */
public void setCurrentItem(ItemStack item) {
    ItemStack itemStack = player.getHeldItem(hand);
    if (!ItemStack.areItemsEqual(sampleItem, itemStack))
        return;
    Preconditions.checkArgument(item.getItem() instanceof ItemUIFactory,
        "Current Item should implement ItemUIFactory");
    this.sampleItem = item;
    player.setHeldItem(hand, item);
}
 
Example 12
Source File: MortarRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public ItemStack[] getResult(List<ItemStack> inputs) {
    ItemStack[] retStack = new ItemStack[0];

    for(Entry<Object[], ItemStack[]> entry : RecipesList.entrySet()){
        boolean flg1 = true;
        if ((inputs.size() != entry.getKey().length)) 
            continue;
    	for (Object obj1 : entry.getKey()) {
    		boolean flg2 = false;
    		for (ItemStack input:inputs) {
    			if(input.isEmpty()) break;
            	if(obj1 instanceof ItemStack){
            		ItemStack stack1 = (ItemStack) obj1;
	                if (ItemStack.areItemsEqual(stack1, input)) {
	                	inputs.remove(input);
	                    flg2 = true;
	                    break;
	                }
                }else if(obj1 instanceof String){
                	NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
                	if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
	                	inputs.remove(input);
                        flg2 = true;
	                    break;
                    }
                }
            }
            if (!flg2) {
                flg1 = false;
                break;
            }
        }

        if (flg1) {
            return entry.getValue();
        }
    }
    
    return retStack;
}
 
Example 13
Source File: ModuleRegistry.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
public ModuleInstance getModule(ItemStack itemStack) {
	for (ModuleInstance module : modules)
		if (ItemStack.areItemsEqual(itemStack, module.getItemStack())) {
			return module;
		}
	return null;
}
 
Example 14
Source File: BarrelRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public FluidStack getResultFluidStack(FluidStack fluid, ItemStack[] inputs) {
	for (Entry<FluidStack, Map<Object[], FluidStack>> entry : RecipesList.entrySet()) {
		if(entry.getKey().isFluidEqual(fluid))
	        for(Entry<Object[], FluidStack> entry2 : entry.getValue().entrySet()){
	            boolean flg1 = true;
            	for (Object obj1 : entry2.getKey()) {
	        		boolean flg2 = false;
	        		for (ItemStack input:inputs) {
	                	if(obj1 instanceof ItemStack){
	                		ItemStack stack1 = (ItemStack) obj1;
	    	                if (ItemStack.areItemsEqual(stack1, input)) {
	    	                    flg2 = true;
	    	                    break;
	    	                }
	                    }else if(obj1 instanceof String){
	                    	NonNullList<ItemStack> ore = OreDictionary.getOres((String) obj1);
	                    	if (!ore.isEmpty()&&RecipesUtil.containsMatch(false, ore, input)) {
	                            flg2 = true;
	    	                    break;
	                        }
	                    }
	                }
	                if (!flg2) {
	                    flg1 = false;
	                    break;
	                }
	            }

	            if (flg1) {
	                return entry2.getValue();
	            }
	        }
	}

	return null;
}
 
Example 15
Source File: ItemMetalHoe.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean getIsRepairable(final ItemStack intputItem, final ItemStack repairMaterial) {
	List<ItemStack> acceptableItems = OreDictionary.getOres(repairOreDictName);
	for(ItemStack i : acceptableItems ){
		if(ItemStack.areItemsEqual(i, repairMaterial)) return true;
	}
	return false;
}
 
Example 16
Source File: TileFirepit.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/***********************************************************************************
 * 1. Content
 ***********************************************************************************/
@Override
public void update() 
{
	if(world.isRemote)
		return;
	Timekeeper time = Timekeeper.getInstance();

	if(this.hasCookingTool())
	{
		ItemStack output = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, world);
		if(output == ItemStack.EMPTY)
		{
			cookingMaxTimer = -1;
			cookingTimer = cookingMaxTimer;
			this.setInventorySlotContents(OUTPUT_SLOT, output);
		}
		else if(!ItemStack.areItemsEqual(getStackInSlot(OUTPUT_SLOT), output))
		{
			this.setInventorySlotContents(OUTPUT_SLOT, output);
			cookingMaxTimer = 300;//For now we'll use a generic cooking time for all foods
			cookingTimer = cookingMaxTimer;
		}
	}
	else
	{
		//Handle non-cooking item heating
		if(fuelTimer > 0)
		{
			if(this.getStackInSlot(TOOL_SLOT) != ItemStack.EMPTY)
			{
				if(ItemHeat.Get(getStackInSlot(TOOL_SLOT)) < MAXHEAT)
					ItemHeat.Increase(getStackInSlot(TOOL_SLOT), 1.0f);
			}
		}
	}

	//If the fire is lit
	if(fuelTimer > 0)
	{
		fuelTimer--;

		if(cookingTimer > 0 && !this.getStackInSlot(OUTPUT_SLOT).isItemEqual(ItemStack.EMPTY))
		{
			cookingTimer--;
		}
	}
	else
	{
		if(fuelTimer <= 0 && isValidFuel(getStackInSlot(FUEL_SLOT)) && world.getBlockState(getPos()).getValue(BlockFirepit.LIT) == true)
		{
			fuelMaxTimer = Global.GetFirepitFuel(getStackInSlot(FUEL_SLOT));
			fuelTimer = fuelMaxTimer;
			getStackInSlot(FUEL_SLOT).shrink(1);
			world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(BlockFirepit.LIT, true), 3);
		}
		else if(world.getBlockState(getPos()).getValue(BlockFirepit.LIT) == true)
		{
			world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(BlockFirepit.LIT, false), 3);
		}

		if(fuelTimer <= 0 && cookingTimer > 0)
		{
			cookingTimer = cookingMaxTimer;//reset the cooking timer if the fuel runs out
		}
	}
}
 
Example 17
Source File: PlayerInventoryHolder.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ItemStack getCurrentItem() {
    ItemStack itemStack = player.getHeldItem(hand);
    if (!ItemStack.areItemsEqual(sampleItem, itemStack))
        return null;
    return itemStack;
}
 
Example 18
Source File: AbstractRecipeLogic.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static boolean areItemStacksEqual(ItemStack stackA, ItemStack stackB) {
    return (stackA.isEmpty() && stackB.isEmpty()) ||
        (ItemStack.areItemsEqual(stackA, stackB) &&
            ItemStack.areItemStackTagsEqual(stackA, stackB));
}
 
Example 19
Source File: StackHelper.java    From AgriCraft with MIT License 2 votes vote down vote up
/**
 * Determines if the given ItemStacks consist of the same Item, as per the vanilla definition of
 * Item equality. Two ItemStacks have the same Item if and only if they reference the same item
 * instance, and have the same meta values.
 *
 * @param a the stack to compare equality against.
 * @param b the stack to check for equality.
 * @return {@literal true} if and only if the item from stack a is considered to equivalent to
 * the item from stack b, {@literal false} otherwise.
 */
public static final boolean areItemsEqual(@Nullable ItemStack a, @Nullable ItemStack b) {
    return ItemStack.areItemsEqual(a, b);
}