Hello! I have an empty class, and in it I want to test for when a player kills a zombie. When the player kills a zombie, I want to send a message to the player saying "You killed a zombie!". Does anyone know how to do that?
In the EntityPlayer class the method addToPlayerScore is used to track mob kills; while the type of mob is not tracked beyond players and other mobs you can test for whether the passed-in entity is the type you want, as it does for players.
For example, this is the method in my mod, which tracks how many of most Overworld mobs you've killed in the current play session; obviously, this is not a Forge mod but Forge should have some method of accessing this, if you are using it (BlocksMined is a class I made which tracks the information, along with ores and other blocks mined, which is then displayed in the default inventory GUI):
public void addToPlayerScore(Entity par1Entity, int par2)
{
this.addScore(par2);
Collection var3 = this.getWorldScoreboard().func_96520_a(ScoreObjectiveCriteria.totalKillCount);
if (par1Entity instanceof EntityPlayer)
{
this.addStat(StatList.playerKillsStat, 1);
var3.addAll(this.getWorldScoreboard().func_96520_a(ScoreObjectiveCriteria.playerKillCount));
}
else
{
this.addStat(StatList.mobKillsStat, 1);
// Tracks individual mobs for inventory display
if (par1Entity instanceof EntityCaveSpider)
{
BlocksMined.addMobKills(1);
}
else if (par1Entity instanceof EntityCreeper)
{
BlocksMined.addMobKills(2);
}
else if (par1Entity instanceof EntityEnderman)
{
BlocksMined.addMobKills(3);
}
else if (par1Entity instanceof EntitySkeleton)
{
BlocksMined.addMobKills(4);
}
else if (par1Entity instanceof EntitySlime)
{
BlocksMined.addMobKills(5);
}
else if (par1Entity instanceof EntitySpider)
{
BlocksMined.addMobKills(6);
}
else if (par1Entity instanceof EntityWitch)
{
BlocksMined.addMobKills(7);
}
else if (par1Entity instanceof EntityZombie)
{
BlocksMined.addMobKills(8);
}
}
Iterator var4 = var3.iterator();
while (var4.hasNext())
{
ScoreObjective var5 = (ScoreObjective)var4.next();
Score var6 = this.getWorldScoreboard().func_96529_a(this.getEntityName(), var5);
var6.func_96648_a();
}
}
Note that a few mobs have a common base class, such as spiders and cave spiders; if spiders were first it would not count cave spiders since they are an instance of spider. If you want to separate zombies by type (baby, villager) you'd have to perform further checking (methods isChild() and isVillager() in EntityZombie).
Hello! I have an empty class, and in it I want to test for when a player kills a zombie. When the player kills a zombie, I want to send a message to the player saying "You killed a zombie!". Does anyone know how to do that?
In the EntityPlayer class the method addToPlayerScore is used to track mob kills; while the type of mob is not tracked beyond players and other mobs you can test for whether the passed-in entity is the type you want, as it does for players.
For example, this is the method in my mod, which tracks how many of most Overworld mobs you've killed in the current play session; obviously, this is not a Forge mod but Forge should have some method of accessing this, if you are using it (BlocksMined is a class I made which tracks the information, along with ores and other blocks mined, which is then displayed in the default inventory GUI):
Note that a few mobs have a common base class, such as spiders and cave spiders; if spiders were first it would not count cave spiders since they are an instance of spider. If you want to separate zombies by type (baby, villager) you'd have to perform further checking (methods isChild() and isVillager() in EntityZombie).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?