Posted May 2, 201510 yr I am trying to make it so that my raw latex drops from oak logs but i can't get it to work cause of the meta data... Here is my code: ItemRawLatex class: package com.hardwareplus.mod; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.event.world.BlockEvent; public class ItemRawLatex extends Item{ @SubscribeEvent public void onDrops(BlockEvent.HarvestDropsEvent event) { if (event.block == Blocks.log); event.drops.add(new ItemStack(HardwarePlus.itemRawLatex)); } } and yes i have MinecraftForge.EVENT_BUS.register(new YourEventHandler()); in my main class in my event handler i have it like this: MinecraftForge.EVENT_BUS.register(new HardwarePlus());
May 2, 201510 yr Author i mean when anyone has picked up the log once with the raw latex, they cannot just place it back down and get more raw latex! My event handler: package com.hardwareplus.mod; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent.BreakEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class YourEventHandler { @SubscribeEvent public void blockBreak(BreakEvent event) { Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; if (block == Blocks.log) { if(event.blockMetadata == 0) { world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(HardwarePlus.itemRawLatex))); } } } }
May 2, 201510 yr Author yes i dont want it to drop the log that was used to drop the latex and changed the code which still works New code: package com.hardwareplus.mod; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent.BreakEvent; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class YourEventHandler { @SubscribeEvent public void onBlockHarvest(HarvestDropsEvent event) { Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; if (block == Blocks.log) { if(event.blockMetadata == 0) { world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(HardwarePlus.itemRawLatex))); } } } }
May 2, 201510 yr Alternatively, if you are not comfortable with iterators / you just want one thing to drop, an easier solution is to clear the drops list completely and then add your stack to it. event.drops.clear(); event.drops.add(new ItemStack(yourItem)); Done. However, if you don't know how to use iterators, you could use this as an excuse to learn about them, because they are very useful. http://i.imgur.com/NdrFdld.png[/img]
May 2, 201510 yr Author Well coolAlias's code worked and was able to make 2 drops....so if this can break a mod then how do i do it the other option
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.