Jump to content

[1.7.2]Doing things when a player kills an entity?


dude22072

Recommended Posts

I want to give the player an achievement when they kill a specific mob, but I don't know how to do things when a mob dies.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

Events are your friend.

 

I've tried LivingDeathEvent

@SubscribeEvent
public void onEntityDeath(LivingDeathEvent event) {
	System.out.println("Entity Death");
	Entity e = event.entityLiving;
	DamageSource source = event.source;

	if(source.getSourceOfDamage() instanceof EntityPlayer) {
		System.out.println("Player Kill!");
		if(e instanceof EntityZombie ) {
			System.out.println("Zombie Killed!");
			mobZombieKill = true;
		}
	}

}

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
	if (mobZombieKill == true) {
		System.out.println("Achievement");
		event.player.addStat(ExtraAchievements.mobKillZombie, 1);
		mobZombieKill = false;
	}
}

and none of the "System.out.println"s get triggered.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

Have you registered the event?

MinecraftForge.EVENT_BUS.register(new YourClass());

I use

FMLCommonHandler.instance().bus().register(new AchievementEvent());

Unsure if it makes a diffrence

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

As mentioned there are different event buses.  In my tutorial on events I explain which events are on which busses, so it might be interesting to you (either this time or in the future next time you are considering using events): http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

Announcements



×
×
  • Create New...

Important Information

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