Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Making Vanilla Mobs drop Custom Items [1.5.2]
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
SilasOtoko

Making Vanilla Mobs drop Custom Items [1.5.2]

By SilasOtoko, October 6, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

SilasOtoko    2

SilasOtoko

SilasOtoko    2

  • Stone Miner
  • SilasOtoko
  • Members
  • 2
  • 92 posts
Posted October 6, 2013

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!

  • Quote

Share this post


Link to post
Share on other sites

f1rSt1kChannel    5

f1rSt1kChannel

f1rSt1kChannel    5

  • Creeper Killer
  • f1rSt1kChannel
  • Members
  • 5
  • 138 posts
Posted October 6, 2013

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

			}
		}
	}

  • Quote

Share this post


Link to post
Share on other sites

SilasOtoko    2

SilasOtoko

SilasOtoko    2

  • Stone Miner
  • SilasOtoko
  • Members
  • 2
  • 92 posts
Posted October 8, 2013

That is really useful. I'll probably try to use that at some point. Thank you!

  • Quote

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted October 8, 2013

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

  • Quote

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

Share this post


Link to post
Share on other sites

SilasOtoko    2

SilasOtoko

SilasOtoko    2

  • Stone Miner
  • SilasOtoko
  • Members
  • 2
  • 92 posts
Posted October 12, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Jack Richard
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard · Posted 1 hour ago

      Thanks so much for your help! I removed the log4j dependency, I honesty don't remember when I put that there. Once I fixed the jar.finalizedBy line, everything worked! (One small issue where I was relocating all of "com.google" when I just should've relocated "com.google.common," too)   Thanks again!
    • Teedledee
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee · Posted 1 hour ago

      Fixed the issue, one config didnt match, downloaded randompatches to solve badly compressed packet afterwards.
    • DaemonUmbra
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By DaemonUmbra · Posted 1 hour ago

      First of all, why are you shadowing log4j? Minecraft already provides log4j2. Second if build is running shadowjar instead of jar then you might need to tweak the line where it says jar.finalizedBy('reobfJar') to finalize shadowJar instead
    • DaemonUmbra
      "The game crashed whilst rendering overlay"

      By DaemonUmbra · Posted 1 hour ago

      What do you think you should do about this?
    • DaemonUmbra
      IntelliJ doesn't include resources folder while debugging

      By DaemonUmbra · Posted 2 hours ago

      What version of Minecraft are you using?
  • Topics

    • Jack Richard
      2
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard
      Started 2 hours ago

    • Teedledee
      2
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee
      Started January 18

    • GuyWithTVHead
      1
      "The game crashed whilst rendering overlay"

      By GuyWithTVHead
      Started 2 hours ago

    • GermanBucket
      2
      IntelliJ doesn't include resources folder while debugging

      By GermanBucket
      Started 4 hours ago

    • Arthurmeade12
      8
      Error Conecting to My Minecraft Server

      By Arthurmeade12
      Started Saturday at 11:05 PM

  • Who's Online (See full list)

    • DaemonUmbra
    • DynamicSiren
    • forgotendeath09
    • Inforno
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Making Vanilla Mobs drop Custom Items [1.5.2]
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community