Jump to content

Recommended Posts

Posted (edited)

I want to check if an item contains certain OreDictionary. Something like:

 

If(ThisItem.OreDictionary.contains("oreCopper"){

}

 

Is it possible?

Edited by Focamacho
Posted

 

I'm having trouble comparing one item and another.

 

get right-clicked block:

    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
        ItemStack itemstack = player.getHeldItem(hand);
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        ItemStack blockItem = new ItemStack(block); 

 

get oredictionary:

public static final List<ItemStack> logWood = OreDictionary.getOres("logWood");

 

comparing right-clicked block & oredictionary:

	public boolean checkBlockOreDict(ItemStack blockItem, List<ItemStack> oreDict) {
		System.out.println("OreDict: " + oreDict);
		System.out.println("Block right-clicked: " + blockItem);
		for(ItemStack item : oreDict) {
			if(blockItem.isItemEqualIgnoreDurability(item)) {
				System.out.println("Match: yes");
				return true;
			}
		}
		System.out.println("Match: no");
		return false;
	}

 

console output:

Screenshot_1.png.c24a7f0eb151764957ef1b0675961ca7.png

 

Posted (edited)

It's working fine now with vanilla logs, but for some reason it don't works with Biomes o plenty logs.

 

New code:

	public boolean checkBlockOreDict(ItemStack blockItem, NonNullList<ItemStack> oreDict) {
		System.out.println("OreDict: " + oreDict);
		System.out.println("Block right-clicked: " + blockItem);
		for(ItemStack item : oreDict) {
			System.out.println("Testing now: " + item);
			if(OreDictionary.itemMatches(item, blockItem, false)) {
				System.out.println("Match: yes");
				return true;
			}
		}
		System.out.println("Match: no");
		return false;
	}

 

Console Output:

Spoiler

Vanilla Wood:

[15:29:36] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:112]: OreDict: [1xtile.log@32767, 1xtile.log@32767, 1xtile.log_0@4, 1xtile.log_0@5, 1xtile.log_0@6, 1xtile.log_0@7, 1xtile.log_1@4, 1xtile.log_1@5, 1xtile.log_1@6, 1xtile.log_1@7, 1xtile.log_2@4, 1xtile.log_2@5, 1xtile.log_2@6, 1xtile.log_2@7, 1xtile.log_3@4, 1xtile.log_3@5, 1xtile.log_3@6, 1xtile.log_3@7, 1xtile.log_4@4, 1xtile.log_4@5]
[15:29:36] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:113]: Block right-clicked: 1xtile.log@0
[15:29:36] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log@32767
[15:29:36] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:117]: Match: yes

 

Biomes o Plenty Wood:

[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:112]: OreDict: [1xtile.log@32767, 1xtile.log@32767, 1xtile.log_0@4, 1xtile.log_0@5, 1xtile.log_0@6, 1xtile.log_0@7, 1xtile.log_1@4, 1xtile.log_1@5, 1xtile.log_1@6, 1xtile.log_1@7, 1xtile.log_2@4, 1xtile.log_2@5, 1xtile.log_2@6, 1xtile.log_2@7, 1xtile.log_3@4, 1xtile.log_3@5, 1xtile.log_3@6, 1xtile.log_3@7, 1xtile.log_4@4, 1xtile.log_4@5]
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:113]: Block right-clicked: 1xtile.log_2@0
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log@32767
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log@32767
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_0@4
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_0@5
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_0@6
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_0@7
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_1@4
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_1@5
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_1@6
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_1@7
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_2@4
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_2@5
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_2@6
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_2@7
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_3@4
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_3@5
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_3@6
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_3@7
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_4@4
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:115]: Testing now: 1xtile.log_4@5
[15:32:27] [Server thread/INFO] [STDOUT]: [com.focamacho.mysticaladaptations.items.SeedExtractor:checkBlockOreDict:121]: Match: no

 

Edited by Focamacho
Posted
Quote

Block right-clicked: 1xtile.log_2@0

Because of the way you wrote your code ("take the current block state, discard its metadata, create an item stack"), you created a block that doesn't exist. Notice how your oredict code loops over several metadata values for the same block:

Quote

1xtile.log_2@4

1xtile.log_2@5

1xtile.log_2@6

1xtile.log_2@7

But that none of those are the same as what you said you right clicked.

 

This is why PickBlock() exists.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.