Jump to content

Mobs dropping custom item with chance based on config file


darthvader45

Recommended Posts

Ok, I noticed the Cray Tokens mod by MrCrayfish has not been updated from 1.6.4 to 1.7.10, so I decided to see if I could get an update working(then sending the update to him to upload on his site, of course).  However, the class in his mod called LivingDropEvent has been giving me fits, as the vanilla hostile mobs(i.e. Creeper, Zombie, Skeleton, Spider, etc.) aren't dropping Cray Tokens like they're supposed to.

 

LivingDropEvent.java:

/*  1:   */ package com.mrcrayfish.craytokens;
/*  2:   */ 
/*  3:   */ /*  5:   */ import java.util.Random;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
/*  4:   */ 
/*  8:   */ 
/*  9:   */ 
/* 10:   */ 
/* 11:   */ 
/* 12:   */ 
/* 13:   */ public class LivingDropEvent
/* 14:   */ {
/* 15:   */   @SubscribeEvent
/* 16:   */   public void onDeath(LivingDropsEvent e)
/* 17:   */   {
/* 18:16 */     Random rand = new Random();
/* 19:17 */     if ((e.entityLiving.isCreatureType(EnumCreatureType.monster, true)) && (!e.entityLiving.captureDrops))
/* 20:   */     {
/* 21:18 */       World world = e.entityLiving.worldObj;
/* 22:19 */       EntityLiving living = (EntityLiving) e.entityLiving;
/* 23:25 */       if (CrayTokens.platinumRarity == 0)
/* 24:   */       {
/* 25:26 */         EntityItem platinumCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 26:27 */         platinumCoin.dropItem(CrayTokens.platinumToken, 1);
/* 27:28 */         e.drops.add(platinumCoin);
/* 28:   */       }
/* 29:29 */       else if (rand.nextInt(CrayTokens.platinumRarity) == 0)
/* 30:   */       {
/* 31:30 */         EntityItem platinumCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 32:31 */         platinumCoin.dropItem(CrayTokens.platinumToken, 1);
/* 33:32 */         e.drops.add(platinumCoin);
/* 34:   */       }
/* 35:35 */       if (CrayTokens.goldRarity == 0)
/* 36:   */       {
/* 37:36 */         EntityItem goldCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 38:37 */         goldCoin.dropItem(CrayTokens.goldToken, 1);
/* 39:38 */         e.drops.add(goldCoin);
/* 40:   */       }
/* 41:39 */       else if (rand.nextInt(CrayTokens.goldRarity) == 0)
/* 42:   */       {
/* 43:40 */         EntityItem goldCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 44:41 */         goldCoin.dropItem(CrayTokens.goldToken, 1);
/* 45:42 */         e.drops.add(goldCoin);
/* 46:   */       }
/* 47:45 */       if (CrayTokens.silverRarity == 0)
/* 48:   */       {
/* 49:46 */         EntityItem silverCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 50:47 */         silverCoin.dropItem(CrayTokens.silverToken, 1);
/* 51:48 */         e.drops.add(silverCoin);
/* 52:   */       }
/* 53:49 */       else if (rand.nextInt(CrayTokens.silverRarity) == 0)
/* 54:   */       {
/* 55:50 */         EntityItem silverCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 56:51 */         silverCoin.dropItem(CrayTokens.silverToken, 1);
/* 57:52 */         e.drops.add(silverCoin);
/* 58:   */       }
/* 59:55 */       if (CrayTokens.copperRarity == 0)
/* 60:   */       {
/* 61:56 */         EntityItem copperCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 62:57 */         int chance = rand.nextInt(4);
/* 63:58 */         copperCoin.dropItem(CrayTokens.copperToken, chance);
/* 64:59 */         e.drops.add(copperCoin);
/* 65:   */       }
/* 66:60 */       else if (rand.nextInt(CrayTokens.copperRarity) == 0)
/* 67:   */       {
/* 68:61 */         EntityItem copperCoin = new EntityItem(world, living.chunkCoordX, living.chunkCoordY, living.chunkCoordZ);
/* 69:62 */         int chance = rand.nextInt(4);
/* 71:64 */         e.drops.add(copperCoin);
/* 72:   */       }
/* 73:   */     }
/* 74:   */   }
/* 75:   */ }



/* Location:           C:\Users\joshl\Downloads\[Forge]CrayTokensv1.0(1.6.4).zip

* Qualified Name:     com.mrcrayfish.craytokens.LivingDropEvent

* JD-Core Version:    0.7.0.1

*/

Link to comment
Share on other sites

here is a part of my working eventhandler.

this may help you.

 

 @SubscribeEvent
    public void onEntityDrop(LivingDropsEvent event) {
  	  if(event.entityLiving instanceof EntityCow) {
  		event.entityLiving.dropItem(EnderpowerItems.blood, r.nextInt(3));
  		 
  	  }

 

I should change EntityCow to EntityMob.

Link to comment
Share on other sites

I'll test.  Thanks for the example code.

 

Edit: Ok, now MrCrayfish sets it so that if the rarity is set to 0 in the config file, they always drop, but if it's not equal to zero, then the chance of coins dropping is one out of whatever the rarity is set to(i.e. rarity for copperToken is 8, it will be 1/8 chance of copperToken dropping).

Link to comment
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.
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.



×
×
  • Create New...

Important Information

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