Posted July 15, 201510 yr Hello, I'm new to modding, and I am trying to get an item (baked potato) to drop from leaves occasionally. I registered the eventbus: MinecraftForge.EVENT_BUS.register(new YeastEventHandler()); in my init method, and have this code in my YeastEventHandler: package com.yeast.yeastmod; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class YeastEventHandler { @SubscribeEvent public void checkLeave(BlockEvent.HarvestDropsEvent event) { System.out.println("Some event called"); //Check the block state to find out if the Block is Leaves if(event.state == Blocks.leaves) { //Add the new drop, we can't set event.drops because it is final. This will add it to the list of possible drops for leaves System.out.println("This is a leaf."); event.drops.add(new ItemStack(Items.baked_potato)); } } } When I break any block, my console says "Some event called", confirming that it knows I broke the block. However, when I break a leaf block, I do not get the output "This is a leaf." I have tried using "Blocks.leaves" and "Blocks.leaves2", and both ways my code cannot detect if the block I broke is a leaf. What am I doing wrong? Any help is appreciated, -TheGlobefish
July 15, 201510 yr event.state is an IBlockState instance, which you are comparing to a Block instance, so of course it is always false. You need to use event.state.getBlock() to compare. http://i.imgur.com/NdrFdld.png[/img]
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.