Jump to content

Recommended Posts

Posted

So I've spent hours on looking for a way to get certain vanilla mobs to drop custom items and I want to use the LivingDeathEvent to achieve this. I've been looking at countless different forums and pages; however, most of them rely on using the LivingDropsEvent and the ones that don't, end up not working for me. I want the item to only drop only when the certain mobs are killed by a player who is holding a specific weapon. No errors show up from what I know and I'm able to load into the game fine. I also believe I have the if statements right; but I'm honestly not sure because regardless of whether I have them or not, the item doesn't drop from the mobs. I went with this event because I thought I could have more control over it; although, I have little knowledge on what you can do with LootPools other than if the player killed the mob and what mob should drop this loot.

If it helps, the Forge version I'm using is: 14.23.3.2655

 

Here is my current code:

@EventBusSubscriber
public class SFEventHandler {
	
	@SubscribeEvent
	public void onEvent(LivingDeathEvent event) {
		
		if (event.getEntity() instanceof EntityZombie) {
			
			if (event.getSource().getTrueSource() instanceof EntityPlayer) {
				event.getEntity().dropItem(ModItems.TAINTED_SOUL, 1);
			}
		}
	}
}

Any help is very appreciated.

Posted

I'm well aware of that; but I'm also using getSource  in this part of my code to get the killer and the code says there's nothing wrong with that:

2 hours ago, Distinct Soul said:

if (event.getSource().getTrueSource() instanceof EntityPlayer) {

Also, I still don't understand what I'm doing wrong that prevents the item from being dropped by the mob. Like, what code would I need to have in my LivingDeathEvent for the item to actually drop from the Zombie?

Posted (edited)

Now thinking about it, I'm not really sure. I guess I've just spent so much time invested in doing it this way, I don't want it to be that I've been doing it the wrong way this entire time.

Sorry for wasting your time. Now I'm using the right event.

Omg, I've actually found the solution. It wasn't because I was using LivingDeathEvent. It was because I didn't have it registered in my Preinit. I thought the @EventBusSubscriber already did that; but I must've been mistaken.

Thanks for helping anyways.

Edited by Distinct Soul
Found the solution
  • 10 months later...
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.