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

I've just recently figured out how to make this work, after many hours of searching the internet and help forums. So if any of you have had the same problem and faced the same frustration as I have, let me help you out by giving you an example of working code.

 

 

public class CustomDrops {

public static double rand;

 

@ForgeSubscribe

public void onEntityDrop(LivingDropsEvent event) {

if (event.entityLiving instanceof EntityCreeper){

                            rand = Math.random();

if (rand < 0.1D) {

event.entityLiving.dropItem(TutorialMod.CreeperHeart.itemID, 1);

}

}

}

}

 

 

The number in (rand < 0.1D) is how often you want the item to drop. 1D = 100% so .5D is 50% and so on.

The number after your item is how many of that Item you want the mob to drop.

 

You have to make a new class to put this in and then register this event in your main class like this:

 

 

MinecraftForge.EVENT_BUS.register(new CustomDrops());

 

 

You have to put this in your "public void load" constructor.

 

Hope this helps someone!

check damage type:

 

if(event.source == event.source.inFire || event.source == event.source.onFire || event.source == event.source.lava){

		if (event.entityLiving instanceof EntityZombie || event.entityLiving instanceof EntityPigZombie) {

			if (RandomUtil.randomPercent() < 0.25D) { 

				event.entityLiving.dropItem(Foods.foodCookedFlesh.itemID, RandomUtil.getRandom().nextInt(2) + 1); 

			}
		}
	}

Also, with your example, you are working with a null pointer, i.e. rand. You never give rand a value, you might want to change that ;)

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

  • Author

Can you give me a good example of what you mean with the null pointer? I work best with visual examples.

 

Are you talking about this?

 

rand = Math.random();

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.