Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by Mufark
Problem solved thanka to help.

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.

  • 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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.