Jump to content

Recommended Posts

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!

Posted

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); 

			}
		}
	}

Posted

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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