Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

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

}

 

Is it possible?

Edited by Focamacho

  • Author

 

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

 

  • Author

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

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.