Java Code Examples for ic2.api.recipe.IRecipeInput#matches()

The following examples show how to use ic2.api.recipe.IRecipeInput#matches() . 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: GTTileBaseFuelMachine.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean checkRecipe(GTRecipeMultiInputList.MultiRecipe entry, List<ItemStack> inputs) {
	List<IRecipeInput> recipeKeys = new LinkedList<IRecipeInput>(entry.getInputs());
	for (Iterator<IRecipeInput> keyIter = recipeKeys.iterator(); keyIter.hasNext();) {
		IRecipeInput key = keyIter.next();
		int toFind = key.getAmount();
		for (Iterator<ItemStack> inputIter = inputs.iterator(); inputIter.hasNext();) {
			ItemStack input = inputIter.next();
			if (key.matches(input)) {
				if (input.getCount() >= toFind) {
					input.shrink(toFind);
					keyIter.remove();
					if (input.isEmpty()) {
						inputIter.remove();
					}
					break;
				}
				toFind -= input.getCount();
				input.setCount(0);
				inputIter.remove();
			}
		}
	}
	return recipeKeys.isEmpty();
}
 
Example 2
Source File: GTTileBaseMachine.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean checkRecipe(MultiRecipe entry, List<ItemStack> inputs) {
	List<IRecipeInput> recipeKeys = new LinkedList<IRecipeInput>(entry.getInputs());
	for (Iterator<IRecipeInput> keyIter = recipeKeys.iterator(); keyIter.hasNext();) {
		IRecipeInput key = keyIter.next();
		int toFind = key.getAmount();
		for (Iterator<ItemStack> inputIter = inputs.iterator(); inputIter.hasNext();) {
			ItemStack input = inputIter.next();
			if (key.matches(input)) {
				if (input.getCount() >= toFind) {
					input.shrink(toFind);
					keyIter.remove();
					if (input.isEmpty()) {
						inputIter.remove();
					}
					break;
				}
				toFind -= input.getCount();
				input.setCount(0);
				inputIter.remove();
			}
		}
	}
	return recipeKeys.isEmpty();
}
 
Example 3
Source File: GTRecipeMultiInputList.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean isValidRecipeInput(ItemStack stack) {
	List<IRecipeInput> inputs = validInputs.get(new ItemWithMeta(stack));
	if (inputs == null) {
		return false;
	}
	for (IRecipeInput input : inputs) {
		if (input.matches(stack)) {
			return true;
		}
	}
	return false;
}
 
Example 4
Source File: GTTileMagicEnergyConverter.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Checks for compatible ItemStacks **/
public int getMagicFuelValue(ItemStack stack) {
	if (RECIPE_LIST.getRecipeList().isEmpty()) {
		return 0;
	}
	for (MultiRecipe map : RECIPE_LIST.getRecipeList()) {
		IRecipeInput input = map.getInput(0);
		if (!(input instanceof RecipeInputFluid) && input.matches(stack)) {
			return map.getOutputs().getMetadata().getInteger("RecipeTime");
		}
	}
	return 0;
}
 
Example 5
Source File: GTTileCentrifuge.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean checkRecipe(MultiRecipe entry, FluidStack inputFluid, List<ItemStack> inputs) {
	boolean hasCheckedFluid = false;
	List<IRecipeInput> recipeKeys = new LinkedList<IRecipeInput>(entry.getInputs());
	for (Iterator<IRecipeInput> keyIter = recipeKeys.iterator(); keyIter.hasNext();) {
		IRecipeInput key = keyIter.next();
		if (key instanceof RecipeInputFluid) {
			if (!hasCheckedFluid) {
				hasCheckedFluid = true;
				if (inputFluid != null && inputFluid.containsFluid(((RecipeInputFluid) key).fluid)) {
					keyIter.remove();
				}
			}
		}
		int toFind = key.getAmount();
		for (Iterator<ItemStack> inputIter = inputs.iterator(); inputIter.hasNext();) {
			ItemStack input = inputIter.next();
			if (key.matches(input)) {
				if (input.getCount() >= toFind) {
					input.shrink(toFind);
					keyIter.remove();
					if (input.isEmpty()) {
						inputIter.remove();
					}
					break;
				}
				toFind -= input.getCount();
				input.setCount(0);
				inputIter.remove();
			}
		}
	}
	return recipeKeys.isEmpty();
}
 
Example 6
Source File: GTBlockMortar.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand h,
		EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack playerStack = player.getHeldItemMainhand();
	if (playerStack.isEmpty()) {
		return false;
	}
	int matches = 0;
	for (IRecipeInput inputMatcher : INPUT_LIST) {
		if (inputMatcher.matches(playerStack)) {
			matches++;
		}
	}
	if (matches == 0) {
		return false;
	}
	if (IC2.platform.isSimulating()) {
		int chance = this == GTBlocks.ironMortar ? 2 : 15;
		if (worldIn.rand.nextInt(chance) != 0) {
			return true;
		}
		for (MultiRecipe recipe : RECIPE_LIST.getRecipeList()) {
			IRecipeInput inputStack = recipe.getInputs().get(0);
			ItemStack outputStack = recipe.getOutputs().getAllOutputs().get(0);
			if (inputStack.matches(playerStack)) {
				playerStack.shrink(inputStack.getAmount());
				ItemHandlerHelper.giveItemToPlayer(player, outputStack.copy());
			}
		}
	}
	worldIn.playSound(player, pos, SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.BLOCKS, 1.0F, 1.0F);
	return true;
}
 
Example 7
Source File: GTRecipeMultiInputList.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean matches(int slot, ItemStack stack) {
	if (inputs.size() <= slot || stack.isEmpty())
		return false;
	IRecipeInput input = inputs.get(slot);
	return input.matches(stack) && input.getAmount() <= stack.getCount();
}
 
Example 8
Source File: GTRecipeMultiInputList.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean matchesIgnoringSize(int slot, ItemStack stack) {
	if (inputs.size() <= slot || stack.isEmpty())
		return false;
	IRecipeInput input = inputs.get(slot);
	return input.matches(stack);
}