Posted June 1, 201411 yr Hi to pretty much complete the first version of my mod, I require a way to make it so the when the player breaks a leaf block it drops a stick. Everywhere I have looked previously has supplied me with very contrasting information and so I thought I would try here as all the topics I have previously read have been very useful. Any help at all would great, thanks.
June 1, 201411 yr You can use the HarvestDropsEvent and check if the block is leaves and then add sticks to the drops list in the event. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
June 1, 201411 yr Author Hrmmm, I believe I have done it correctly but so far, no sticks have been dropped. if(event.block == Blocks.leaves || event.block == Blocks.leaves2) { event.drops.add(new ItemStack(Items.stick, 1)); }
June 1, 201411 yr Author Thanks, the top section is just for what blocks can be broken by hand. package com.willr27survivalplus.handler; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class WSPEventHandler { @SubscribeEvent public void setBreakableBlocks(PlayerEvent.BreakSpeed event) { ItemStack item = event.entityPlayer.getCurrentEquippedItem(); if(item == null && event.block == Blocks.bed || item == null && event.block == Blocks.brown_mushroom_block || item == null && event.block == Blocks.cactus || item == null && event.block == Blocks.cake || item == null && event.block == Blocks.carpet || item == null && event.block == Blocks.carrots || item == null && event.block == Blocks.clay || item == null && event.block == Blocks.cocoa || item == null && event.block == Blocks.dirt || item == null && event.block == Blocks.flower_pot || item == null && event.block == Blocks.grass || item == null && event.block == Blocks.gravel || item == null && event.block == Blocks.nether_wart || item == null && event.block == Blocks.potatoes || item == null && event.block == Blocks.red_mushroom_block || item == null && event.block == Blocks.redstone_torch || item == null && event.block == Blocks.reeds || item == null && event.block == Blocks.sand || item == null && event.block == Blocks.sapling || item == null && event.block == Blocks.skull || item == null && event.block == Blocks.snow || item == null && event.block == Blocks.snow_layer || item == null && event.block == Blocks.standing_sign || item == null && event.block == Blocks.tnt || item == null && event.block == Blocks.torch || item == null && event.block == Blocks.tripwire || item == null && event.block == Blocks.unlit_redstone_torch || item == null && event.block == Blocks.vine || item == null && event.block == Blocks.wall_sign || item == null && event.block == Blocks.waterlily || item == null && event.block == Blocks.web || item == null && event.block == Blocks.wheat || item == null && event.block == Blocks.wool || item == null && event.block == Blocks.brown_mushroom || item == null && event.block == Blocks.deadbush || item == null && event.block == Blocks.double_plant || item == null && event.block == Blocks.fire || item == null && event.block == Blocks.grass || item == null && event.block == Blocks.leaves || item == null && event.block == Blocks.leaves2 || item == null && event.block == Blocks.mycelium || item == null && event.block == Blocks.red_flower || item == null && event.block == Blocks.red_mushroom || item == null && event.block == Blocks.redstone_wire || item == null && event.block == Blocks.tallgrass || item == null && event.block == Blocks.tripwire_hook || item == null && event.block == Blocks.yellow_flower || item != null && event.block == Blocks.bed || item != null && event.block == Blocks.brown_mushroom_block || item != null && event.block == Blocks.cactus || item != null && event.block == Blocks.cake || item != null && event.block == Blocks.carpet || item != null && event.block == Blocks.carrots || item != null && event.block == Blocks.clay || item != null && event.block == Blocks.cocoa || item != null && event.block == Blocks.dirt || item != null && event.block == Blocks.flower_pot || item != null && event.block == Blocks.grass || item != null && event.block == Blocks.gravel || item != null && event.block == Blocks.nether_wart || item != null && event.block == Blocks.potatoes || item != null && event.block == Blocks.red_mushroom_block || item != null && event.block == Blocks.redstone_torch || item != null && event.block == Blocks.reeds || item != null && event.block == Blocks.sand || item != null && event.block == Blocks.sapling || item != null && event.block == Blocks.skull || item != null && event.block == Blocks.snow || item != null && event.block == Blocks.snow_layer || item != null && event.block == Blocks.standing_sign || item != null && event.block == Blocks.tnt || item != null && event.block == Blocks.torch || item != null && event.block == Blocks.tripwire || item != null && event.block == Blocks.unlit_redstone_torch || item != null && event.block == Blocks.vine || item != null && event.block == Blocks.wall_sign || item != null && event.block == Blocks.waterlily || item != null && event.block == Blocks.web || item != null && event.block == Blocks.wheat || item != null && event.block == Blocks.wool || item != null && event.block == Blocks.brown_mushroom || item != null && event.block == Blocks.deadbush || item != null && event.block == Blocks.double_plant || item != null && event.block == Blocks.fire || item != null && event.block == Blocks.grass || item != null && event.block == Blocks.leaves || item != null && event.block == Blocks.leaves2 || item != null && event.block == Blocks.mycelium || item != null && event.block == Blocks.red_flower || item != null && event.block == Blocks.red_mushroom || item != null && event.block == Blocks.redstone_wire || item != null && event.block == Blocks.tallgrass || item != null && event.block == Blocks.tripwire_hook || item != null && event.block == Blocks.yellow_flower) { event.setCanceled(false); } else if(item == null || !ForgeHooks.isToolEffective(item, event.block, event.metadata)){ event.setCanceled(true); } } @SubscribeEvent public void checkDrops(HarvestDropsEvent event) { if(event.block == Blocks.leaves || event.block == Blocks.leaves2) { event.drops.add(new ItemStack(Items.stick, 1)); } } } I registered it like so: @EventHandler public void Init(FMLInitializationEvent Event) { FMLCommonHandler.instance().bus().register(new CraftingHandler()); MinecraftForge.EVENT_BUS.register(new WSPEventHandler()); WSPRecipeCreator.createRecipes(); }
June 1, 201411 yr Don't know the cause, but I usually put my events in PreInit (see if that makes a difference - in fact, I never use Init, only PreInit for everything). Another thing: - Try adding System.out.println methods around that event and see if it's actually being called. It could be side issues. EDIT: I think I may have found your issue. HarvestDropsEvent is only called when an item is "dropped" from your block (in this case: saplings or apples). Since leaves only drop those items in a low chance, it will only drop your item (which is a stick) if it drops a sapling or apple of itself. To fix this issue you should not use HarvestDropsEvent and use BreakEvent, I think you can figure which "BreakEvent" to use. (lazy: BlockEvent.BreakEvent)
June 1, 201411 yr Author I changed it to this: @SubscribeEvent public void checkDrops(BlockEvent.BreakEvent event) { if(event.block == Blocks.leaves || event.block == Blocks.leaves2) { //Drops } } However, now I am unsure on setting the drop as it has changed, sorry if I am overlooking something simple.
June 1, 201411 yr Spawn an EntityItem in the world (simple as that). event.world.spawnEntityInWorld(new EntityItem(event.world, event.x, event.y, event.z, new ItemStack(YOUR_ITEM)));
June 1, 201411 yr for the top section i would recommend making an arraylist of blocks you can still break as a field, something like: ArrayList<Block> blocklist = new ArrayList<Block>(Arrays.asList(new Block[]{Blocks.bed, Blocks.brown_mushroom_block, etc...})); this way you can use blocklist.contains(event.block) your code would then look something like this: ArrayList<Block> blocklist = new ArrayList<Block>(Arrays.asList(new Block[]{Blocks.bed, Blocks.brown_mushroom_block, etc...})); @SubscribeEvent public void setBreakableBlocks(PlayerEvent.BreakSpeed event) { ItemStack item = event.entityPlayer.getCurrentEquippedItem(); if(blocklist.contains(event.block) { event.setCanceled(false); } else if(item == null || !ForgeHooks.isToolEffective(item, event.block, event.metadata)){ event.setCanceled(true); } } but it's up to you if you use it or not I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/
June 1, 201411 yr Author Thanks I needed someone to explain to me how to do this, I will be implementing this very soon.
June 1, 201411 yr Can't you still use the HarvestDropsEvent and set the dropChance to 1.0f? By lokking at this line: public float dropChance; // Change to e.g. 1.0f, if you manipulate the list and want to guarantee it always drops it should actually work. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
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.