Posted November 1, 20186 yr Hey Guys, I Have created a custom loot drop table and its working for entities but when I try and add drops to vanilla blocks it doesn't seem to be working. Keep in mind that I am a complete Java noob. I usually program in C and C++. Similar but different. Anyways. My code I am using is below. I know the top part is right. But I cant work out a way to ID the block I want the drop to be added to. @SubscribeEvent public void onHarvestEvent(HarvestDropsEvent event) { if (event.getHarvester() != null) //Checks to make sure player is harvesting. { if(event.equals(Blocks.STONE)) //Is meant to confirm which block is being broken. { //This will add my item to the block as it drops with 100% drop rate while I am testing. event.setDropChance((float) 1.0F); event.getDrops().add(new ItemStack(ModItems.DOLLAR_BILL,1)); } } } Not sure if the second half works yet but I am 100% certain that the if(event.equals(Blocks.STONE) is incorrect. Someone with some knowledge on working with Forge 1.12.2 would be much appreciated. Edited November 1, 20186 yr by Mufark Problem solved thanka to help.
November 1, 20186 yr 16 minutes ago, Mufark said: if(event.equals(Blocks.STONE)) Well obviously this won't work. An Event can't be equal to a Block, this is basic OOP. The event has a getter that will get you the IBlockState of the block being broken and you can then get the block with IBlockState#getBlock and compare that. 16 minutes ago, Mufark said: //This will add my item to the block as it drops with 100% drop rate while I am testing. event.setDropChance((float) 1.0F); The drop chance applies to all the items at the same time, not to the one you've added. If you want a chance for your item to drop then only add the item to the list if the random check succeeds.
November 1, 20186 yr Author Thanks Heaps. That is really helpful. Good to know that the second part would have an overall effect on the item drop for the block too. I'll change it and see how I go. EDIT: I'll just add an if statement that will create a random number that will give me a chance to drop. Edited November 1, 20186 yr by Mufark New Info
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.