Java Code Examples for net.minecraftforge.oredict.OreDictionary#getOres()

The following examples show how to use net.minecraftforge.oredict.OreDictionary#getOres() . 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: CrucibleRecipe.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public CrucibleRecipe(String researchKey, ItemStack result, Object cat, AspectList tags) {
	recipeOutput = result;
	this.aspects = tags;
	this.key = researchKey;
	this.catalyst = cat;
	if (cat instanceof String) {
		this.catalyst = OreDictionary.getOres((String) cat);
	}
	String hc = researchKey + result.toString();
	for (Aspect tag:tags.getAspects()) {
		hc += tag.getTag()+tags.getAmount(tag);
	}
	if (cat instanceof ItemStack) {
		hc += ((ItemStack)cat).toString();
	} else
	if (cat instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size()>0) {
		for (ItemStack is :(ArrayList<ItemStack>)catalyst) {
			hc += is.toString();
		}
	}
	
	hash = hc.hashCode();
}
 
Example 2
Source File: ShapedBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();
	width = recipe.recipeWidth;
	height = recipe.recipeHeight;

	input = new Object[recipe.recipeItems.length];

	for (int i = 0; i < input.length; i++) {
		ItemStack ingred = recipe.recipeItems[i];

		if (ingred == null)
			continue;

		input[i] = recipe.recipeItems[i];

		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) {
				input[i] = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
	}
}
 
Example 3
Source File: InventoryUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Checks if the ItemStack <b>stackTarget</b> is valid to be used as a substitution
 * for <b>stackReference</b> via the OreDictionary keys.
 * @param stackTarget
 * @param stackReference
 * @return
 */
public static boolean areItemStacksOreDictMatch(@Nonnull ItemStack stackTarget, @Nonnull ItemStack stackReference)
{
    int[] ids = OreDictionary.getOreIDs(stackReference);

    for (int id : ids)
    {
        List<ItemStack> oreStacks = OreDictionary.getOres(OreDictionary.getOreName(id), false);

        for (ItemStack oreStack : oreStacks)
        {
            if (OreDictionary.itemMatches(stackTarget, oreStack, false))
            {
                return true;
            }
        }
    }

    return false;
}
 
Example 4
Source File: OreDictHandler.java    From bartworks with MIT License 6 votes vote down vote up
public static void adaptCacheForWorld(){
    Set<String> used = new HashSet<>(OreDictHandler.cache.keySet());
    OreDictHandler.cache.clear();
    OreDictHandler.cacheNonBW.clear();
    for (String s : used) {
        if (!OreDictionary.getOres(s).isEmpty()) {
            ItemStack tmpstack = OreDictionary.getOres(s).get(0).copy();
            Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(tmpstack.getItem()), (short) tmpstack.getItemDamage());
            OreDictHandler.cache.put(s, p);
            for (ItemStack tmp : OreDictionary.getOres(s)) {
                Pair<Integer, Short> p2 = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
                GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
                if (UI == null)
                    UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
                if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")) {
                    OreDictHandler.cacheNonBW.add(p2);
                }
            }
        }
    }
}
 
Example 5
Source File: RecipeManaInfusion.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
public boolean matches(ItemStack stack) {
	if(input instanceof ItemStack) {
		ItemStack inputCopy = ((ItemStack) input).copy();
		if(inputCopy.getItemDamage() == Short.MAX_VALUE)
			inputCopy.setItemDamage(stack.getItemDamage());

		return stack.isItemEqual(inputCopy);
	}

	if(input instanceof String) {
		List<ItemStack> validStacks = OreDictionary.getOres((String) input);

		for(ItemStack ostack : validStacks) {
			ItemStack cstack = ostack.copy();
			if(cstack.getItemDamage() == Short.MAX_VALUE)
				cstack.setItemDamage(stack.getItemDamage());

			if(stack.isItemEqual(cstack))
				return true;
		}
	}

	return false;
}
 
Example 6
Source File: RecipePureDaisy.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
public boolean isOreDict(ItemStack stack, String entry) {
	if(stack == null || stack.getItem() == null)
		return false;

	List<ItemStack> ores;
	if(oreMap.containsKey(entry))
		ores = oreMap.get(entry);
	else {
		ores = OreDictionary.getOres(entry);
		oreMap.put(entry, ores);
	}

	for(ItemStack ostack : ores) {
		ItemStack cstack = ostack.copy();
		if(cstack.getItemDamage() == Short.MAX_VALUE)
			cstack.setItemDamage(stack.getItemDamage());

		if(stack.isItemEqual(cstack))
			return true;
	}

	return false;
}
 
Example 7
Source File: ShapedRecipe.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets recipe input without the chars for the shape.
 */
Object[] getRecipeInput()
{
    Object[] result = new Object[getRecipeWidth() * getRecipeHeight()];

    for (int row = 0; row < shape.length; row++)
    {
        for (int col = 0; col < shape[0].length(); col++)
        {
            RecipeInput input = items.get(shape[row].charAt(col));

            int index = col + row * shape[0].length();

            if (input != null)
            {
                result[index] = input.isOreClass() ? OreDictionary.getOres(input.getOreClass().getOreName()) : input.getStack().getItemStack();
            } else
            {
                result[index] = ItemStack.EMPTY;
            }
        }
    }

    return result;
}
 
Example 8
Source File: CrucibleRecipe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
public CrucibleRecipe(String researchKey, ItemStack result, Object cat, AspectList tags) {
	recipeOutput = result;
	this.aspects = tags;
	this.key = researchKey;
	this.catalyst = cat;
	if (cat instanceof String) {
		this.catalyst = OreDictionary.getOres((String) cat);
	}
	String hc = researchKey + result.toString();
	for (Aspect tag:tags.getAspects()) {
		hc += tag.getTag()+tags.getAmount(tag);
	}
	if (cat instanceof ItemStack) {
		hc += ((ItemStack)cat).toString();
	} else
	if (cat instanceof ArrayList && ((ArrayList<ItemStack>)catalyst).size()>0) {
		for (ItemStack is :(ArrayList<ItemStack>)catalyst) {
			hc += is.toString();
		}
	}
	
	hash = hc.hashCode();
}
 
Example 9
Source File: PotRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public ItemStack getResultItemStack(FluidStack fluid, List<ItemStack> inputs) {
	for (Entry<FluidStack, Map<Object[], ItemStack>> entry : RecipesList.entrySet()) {
		if(entry.getKey().isFluidEqual(fluid))
	        for(Entry<Object[], ItemStack> entry2 : entry.getValue().entrySet()){
	            boolean flg1 = true;
	            if ((inputs.size() != entry2.getKey().length)) 
	                continue;
            	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 ItemStack.EMPTY;
}
 
Example 10
Source File: ShapelessBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();

	for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems)) {
		Object finalObj = ingred;
		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) {
				finalObj = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
		input.add(finalObj);
	}
}
 
Example 11
Source File: ShapedBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements)
{
    output = recipe.getRecipeOutput();
    width = recipe.recipeWidth;
    height = recipe.recipeHeight;

    input = new Object[recipe.recipeItems.length];

    for (int i = 0; i < input.length; i++)
    {
        ItemStack ingred = recipe.recipeItems[i];

        if (ingred == null)
            continue;

        input[i] = recipe.recipeItems[i];

        for (Entry<ItemStack, String> replace : replacements.entrySet())
        {
            if (OreDictionary.itemMatches(replace.getKey(), ingred, true))
            {
                input[i] = OreDictionary.getOres(replace.getValue());
                break;
            }
        }
    }
}
 
Example 12
Source File: TileAdvSolar.java    From Production-Line with MIT License 5 votes vote down vote up
public void updateLensStatus() {
    this.hasLens = false;
    if (this.getStackInSlot(0) != null) {
        for (ItemStack stack : OreDictionary.getOres("advSolarLens")) {
            if (stack.isItemEqual(this.getStackInSlot(0))) {
                this.hasLens = true;
                break;
            }
        }
    }
}
 
Example 13
Source File: RecipeInputOreDict.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> getInputs() {
    List<ItemStack> ores = OreDictionary.getOres(input);
    List<ItemStack> ret = new ArrayList<ItemStack>(ores.size());

    for (ItemStack stack : ores) {
        if (stack.getItem() != null) ret.add(stack); // ignore invalid
    }

    return ret;
}
 
Example 14
Source File: OreDict.java    From Ex-Aliquo with MIT License 5 votes vote down vote up
public static ItemStack getFirstOre(String string, boolean warning)
{
	ArrayList<ItemStack> ores = OreDictionary.getOres(string);
	if (!ores.isEmpty())
	{
		return ores.get(0);
	}
	if (warning) exaliquo.logger.warning("ExAliquo could not find the oreDict item called by " + string);
	return new ItemStack(Block.redstoneWire, 1, 0);
}
 
Example 15
Source File: ItemMetalShovel.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: RecipeHandlerOreDictionary.java    From NEI-Integration with MIT License 5 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingred) {
    if (Config.handlerOreDictionary) {
        for (int id : OreDictionary.getOreIDs(ingred)) {
            for (String oreName : this.getOreNames()) {
                if (OreDictionary.getOreName(id).equals(oreName)) {
                    CachedOreDictionaryRecipe crecipe = new CachedOreDictionaryRecipe(oreName, new ItemStack(ingred.getItem(), 1, ingred.getItemDamage()), OreDictionary.getOres(oreName));
                    crecipe.setIngredientPermutation(Collections.singletonList(crecipe.input), ingred);
                    this.arecipes.add(crecipe);
                }
            }
        }
    }
}
 
Example 17
Source File: TreeHandler.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static Set<Block> getBlocksMatching(String name) {
	Set<Block> set = new HashSet<>();
	for (ItemStack stack : OreDictionary.getOres(name)) {
		Block block = Block.getBlockFromItem(stack.getItem());
		if (block != Blocks.AIR) {
			set.add(block);
		}
	}
	return set;
}
 
Example 18
Source File: OreDictUnifier.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void init() {
    for (String registeredOreName : OreDictionary.getOreNames()) {
        NonNullList<ItemStack> theseOres = OreDictionary.getOres(registeredOreName);
        for (ItemStack itemStack : theseOres) {
            onItemRegistration(new OreRegisterEvent(registeredOreName, itemStack));
        }
    }
    MinecraftForge.EVENT_BUS.register(OreDictUnifier.class);
}
 
Example 19
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isSameOreDictStack(ItemStack stack1, ItemStack stack2){
    int[] oredictIds = OreDictionary.getOreIDs(stack1);
    for(int oredictId : oredictIds) {
        List<ItemStack> oreDictStacks = OreDictionary.getOres(OreDictionary.getOreName(oredictId));
        for(ItemStack oreDictStack : oreDictStacks) {
            if(OreDictionary.itemMatches(oreDictStack, stack2, false)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 20
Source File: SatelliteOreMapping.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
/**
 * Note: array returned will be [radius/blocksPerPixel][radius/blocksPerPixel]
 * @param world
 * @param offsetX
 * @param offsetY
 * @param radius in blocks
 * @param blocksPerPixel number of blocks squared (n*n) that take up one pixel
 * @return array of ore vs other block values
 */
public static int[][] scanChunk(World world, int offsetX, int offsetZ, int radius, int blocksPerPixel) {
	blocksPerPixel = Math.max(blocksPerPixel, 1);
	int[][] ret = new int[(radius*2)/blocksPerPixel][(radius*2)/blocksPerPixel];

	Chunk chunk = world.getChunkFromChunkCoords(offsetX << 4, offsetZ << 4);
	IChunkProvider provider = world.getChunkProvider();

	if(oreList.isEmpty()) {
		String[] strings = OreDictionary.getOreNames();
		for(String str : strings) {
			if(str.startsWith("ore") || str.startsWith("dust") || str.startsWith("gem"))
				oreList.add(OreDictionary.getOreID(str));
		}
	}

	for(int z = -radius; z < radius; z+=blocksPerPixel){
		for(int x = -radius; x < radius; x+=blocksPerPixel) {
			int oreCount = 0, otherCount = 0;


			for(int y = world.getHeight(); y > 0; y--) {
				for(int deltaY = 0; deltaY < blocksPerPixel; deltaY++) {
					for(int deltaZ = 0; deltaZ < blocksPerPixel; deltaZ++) {

						BlockPos pos = new BlockPos(x + offsetX, y, z + offsetZ);
						if(world.isAirBlock(pos))
							continue;
						boolean exists = false;
						out:
							for(int i : oreList) {
								List<ItemStack> itemlist = OreDictionary.getOres(OreDictionary.getOreName(i));

								for(ItemStack item : itemlist) {
									if(item.getItem() == Item.getItemFromBlock(world.getBlockState(pos).getBlock())) {
										exists = true;
										break out;
									}
								}
							}
						if(exists)
							oreCount++;
						else
							otherCount++;
					}
				}
			}
			oreCount /= Math.pow(blocksPerPixel,2);
			otherCount /= Math.pow(blocksPerPixel,2);

			if(Thread.interrupted())
				return null;


			ret[(x+radius)/blocksPerPixel][(z+radius)/blocksPerPixel] = (int)((oreCount/(float)Math.max(otherCount,1))*0xFFFF);
		}
	}

	return ret;
}