Posted February 21, 20169 yr I am trying to set spruce logs to drop a custom item when I harvest them with a modded tool, but since spruce logs come from metadata in the BlockOldLog class, I cannot figure out how to adjust them. I have looked at the event.state.getBlock().getSubBlocks(itemIn, tab, list) section, but I'm stumped. Here is the code that I used for mining gravel with a modded tool. @SubscribeEvent public void addBlockDrop(HarvestDropsEvent event) { if(event.state.getBlock() == Blocks.gravel) { Random rand = new Random(); ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem); if(holding!=null && holding.getItem() instanceof NGShaleMattock) { event.drops.clear(); event.drops.add(new ItemStack(NGItems.viscinousGel, rand.nextInt(4))); } } } Any suggestions?
February 21, 20169 yr You need to check that the state's Block ( IBlockState#getBlock ) is Blocks.log , then use IBlockState#getValue to get the value of the BlockOldLog.VARIANT property. If it's BlockPlanks.EnumType.SPRUCE , the log is a Spruce log. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
February 21, 20169 yr Author That did it! I got all mixed up on which side to put it! Here's my code for anymore interested: if(event.state.getBlock() == Blocks.log) { if (event.state.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.SPRUCE) { Random rand = new Random(); ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem); if(holding!=null && holding.getItem() instanceof NGPitchHarvester) { event.drops.clear(); //only if you don't want spruce to drop as well as tree pitch event.drops.add(new ItemStack(NGItems.treePitch, rand.nextInt(4))); } } }
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.