TastyCake Posted November 11, 2017 Posted November 11, 2017 (edited) I have an event that when a specific block gets crafted it gives the player an achievement. My problem is that "ModBlocks.obsidian_compressed" has metadata giving it 2 types and I don't know how to tell it which one. public class CompressedObsidianSingleCraftEvent { @SubscribeEvent public void onEvent(PlayerEvent.ItemCraftedEvent event) { if (event.crafting.getItem() == Item.getItemFromBlock(ModBlocks.obsidian_compressed)) { event.player.addStat(AchievementHandler.achievementCompressedObsidianSingle, 1); } } } Edited November 11, 2017 by TastyCake Quote My username elsewhere is Fluoride
Draco18s Posted November 11, 2017 Posted November 11, 2017 Assuming that getItem() returns the Item and not an ItemStack... if(event.crafting.getMetadata() == whatever) { } Quote 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.
TastyCake Posted November 11, 2017 Author Posted November 11, 2017 4 hours ago, Draco18s said: Assuming that getItem() returns the Item and not an ItemStack... if(event.crafting.getMetadata() == whatever) { } Sorry. I don't quite understand. What should I put for "whatever" I need metadata for a block. Quote My username elsewhere is Fluoride
TastyCake Posted November 11, 2017 Author Posted November 11, 2017 Really sorry but I'm still confused. Could you show me what I need to change in my code? ModBlocks.obsidian_compressed needs a damage value of 1 public class CompressedObsidianSingleCraftEvent { @SubscribeEvent public void onEvent(PlayerEvent.ItemCraftedEvent event) { if (event.crafting.getItem() == Item.getItemFromBlock(ModBlocks.obsidian_compressed)) { event.player.addStat(AchievementHandler.achievementCompressedObsidianSingle, 1); } } } Quote My username elsewhere is Fluoride
loordgek Posted November 11, 2017 Posted November 11, 2017 event.crafting.getItem() == someitem && event.crafting.getMetadata() == whatever 1 Quote
loordgek Posted November 11, 2017 Posted November 11, 2017 11 minutes ago, diesieben07 said: Not helpful... and the better way is ... Quote
TastyCake Posted November 11, 2017 Author Posted November 11, 2017 Fixed! Thanks everyone! Quote My username elsewhere is Fluoride
Recommended Posts
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.