Jump to content

[1.8.9] Custom Mob Drops Only With Specific Item?


Monstrous_Apple

Recommended Posts

What do I add to this exact code to make it so that the pig will only drop a "pig soul" when holding (a.k.a killing the pig with) a certain sword?

 

//Pig Soul
@SubscribeEvent
public void addEntityDrop5 (LivingDropsEvent event) {
	if (event.entity instanceof EntityPig) {
		ItemStack itemstack = new ItemStack(MASouls.PigSoul, 1);
		event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
	}
}

Link to comment
Share on other sites

What do I add to this exact code to make it so that the pig will only drop a "pig soul" when holding (a.k.a killing the pig with) a certain sword?

 

//Pig Soul
@SubscribeEvent
public void addEntityDrop5 (LivingDropsEvent event) {
	if (event.entity instanceof EntityPig) {
		ItemStack itemstack = new ItemStack(MASouls.PigSoul, 1);
		event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
	}
}

Link to comment
Share on other sites

  • Do not add to
    event.drops

    directly, simply use the

    Entity#entityDropItem

    method.

 

Unless I'm mistaken, that won't add to the event's drops list.

Entity#entityDropItem

only captures the drop when

Entity#captureDrops

is

true

, this is set to

true

before the entity's loot is dropped and then set back to

false

before

LivingDropsEvent

is fired.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

  • Do not add to
    event.drops

    directly, simply use the

    Entity#entityDropItem

    method.

 

Unless I'm mistaken, that won't add to the event's drops list.

Entity#entityDropItem

only captures the drop when

Entity#captureDrops

is

true

, this is set to

true

before the entity's loot is dropped and then set back to

false

before

LivingDropsEvent

is fired.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I have this code for a pickaxe where I mine the block and it removes the current drops and adds in another, and this only works if using the specific pickaxe, this is what I want to do for the sword against mobs but can't figure it out?

 

//Blaze Pickaxe Blocks
//Cobblestone Into Stone
@SubscribeEvent
public void addBlockDrop1 (HarvestDropsEvent event) {
	if (event.state.getBlock() == Blocks.cobblestone) {

		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {
			event.drops.clear();
			event.drops.add(new ItemStack(Blocks.stone));
		}
	}
}

Link to comment
Share on other sites

I have this code for a pickaxe where I mine the block and it removes the current drops and adds in another, and this only works if using the specific pickaxe, this is what I want to do for the sword against mobs but can't figure it out?

 

//Blaze Pickaxe Blocks
//Cobblestone Into Stone
@SubscribeEvent
public void addBlockDrop1 (HarvestDropsEvent event) {
	if (event.state.getBlock() == Blocks.cobblestone) {

		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {
			event.drops.clear();
			event.drops.add(new ItemStack(Blocks.stone));
		}
	}
}

Link to comment
Share on other sites

Your prior code should work. I don't see anything wrong with it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Your prior code should work. I don't see anything wrong with it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oh you didn't check what sword the player is holding.  This line equivalent:

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oh you didn't check what sword the player is holding.  This line equivalent:

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So is that all I have to do is add this in:

 

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

but change "MABlazePickaxeTool" to the swords class? And that's literally it? Because I can see this going towards me trying it like that then it not working asking a stupid question and people moan at me? xD

Link to comment
Share on other sites

So is that all I have to do is add this in:

 

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

but change "MABlazePickaxeTool" to the swords class? And that's literally it? Because I can see this going towards me trying it like that then it not working asking a stupid question and people moan at me? xD

Link to comment
Share on other sites

Yep

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yep

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Okay what about the "holding" variable? What would I set that to?

 

New current code:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			if (holding != null && holding.getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

Link to comment
Share on other sites

Okay what about the "holding" variable? What would I set that to?

 

New current code:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			if (holding != null && holding.getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

Link to comment
Share on other sites

Never mind I figured it outs, thanks a lot :D

 

Edit: Actually there's on more question, I'm now using this as my code for the specific sword:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			Object holding = new ItemStack(MAItems.SoulHarvester);
			if (holding  != null && ((ItemStack) holding).getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

 

What code do I add, and where do I add it for a drop chance? So like if I wanted the soul to only drop 10% of the time how would I do this?

Link to comment
Share on other sites

Never mind I figured it outs, thanks a lot :D

 

Edit: Actually there's on more question, I'm now using this as my code for the specific sword:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			Object holding = new ItemStack(MAItems.SoulHarvester);
			if (holding  != null && ((ItemStack) holding).getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

 

What code do I add, and where do I add it for a drop chance? So like if I wanted the soul to only drop 10% of the time how would I do this?

Link to comment
Share on other sites

Do you actually understand what your code is doing?

 

You're creating a new

ItemStack

of

MAItems.SoulHarvester

and then immediately checking if it's an

ItemStack

of

MAItems.SoulHarvester

. This will always be

true

, so it's completely pointless.

 

You need to get the entity that did the killing from the

DamageSource

and then check its held item (like diesieben07 told you in the first reply).

 

For random chances, use

Random#nextInt

to generate a random number, then check if it's in a specific range; e.g.

random.nextInt(100) < 10

will be

true

10% of the time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Do you actually understand what your code is doing?

 

You're creating a new

ItemStack

of

MAItems.SoulHarvester

and then immediately checking if it's an

ItemStack

of

MAItems.SoulHarvester

. This will always be

true

, so it's completely pointless.

 

You need to get the entity that did the killing from the

DamageSource

and then check its held item (like diesieben07 told you in the first reply).

 

For random chances, use

Random#nextInt

to generate a random number, then check if it's in a specific range; e.g.

random.nextInt(100) < 10

will be

true

10% of the time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements




×
×
  • Create New...

Important Information

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