So i'm modding with 1.8.8 MCP meaning i can't use spigot or any methods like that and i need to get an entity's killer / cause of death. I can't even find any tutorials or such because everything i have found uses spigot or forge.
I can already kind of do it with mc.thePlayer.getLastAttacker() (which actually returns the last entity that the player has attacked) but it doesn't work on other entities or players. It would probably be easy to implement my self but i'm just starting out with java so please respond if you know a way to do it.
This may not be exactly the same in 1.8.9 (I mod in 1.6.4) but the method EntityLivingBase.onDeath is where entities handle their death event, which includes a DamageSource parameter which in turns stores the entity that dealt the damage (if applicable):
public void onDeath(DamageSource par1DamageSource)
{
Entity var2 = par1DamageSource.getEntity();
EntityLivingBase var3 = this.func_94060_bK();
if (this.scoreValue >= 0 && var3 != null) var3.addToPlayerScore(this, this.scoreValue);
if (var2 != null) var2.onKillEntity(this);
this.dead = true;
// Always includes hostile mobs so baby zombies and skeletons drop loot
if (!this.worldObj.isRemote && (this instanceof EntityMob || !this.isChild()) && this.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot"))
{
// Looting only works if the player directly dealt damage (not via bow/arrow or potions)
// to fix MC-3304
int looting = (var2 instanceof EntityPlayer && !(par1DamageSource instanceof EntityDamageSourceIndirect) ? EnchantmentHelper.getLootingModifier((EntityLivingBase)var2) : 0);
}
(this is my own modified code but the important part is DamageSource.getEntity)
Some entities override this to add in special drops, such as creepers shot by skeletons dropping music discs or players dropping their inventory, but they all call the super method (so modifying the one in EntityLivingBase will apply to all living entities, including players).
Note that XP drops are handled in a separate method, onDeathUpdate, and they use a counter which is set to 100 when a player or tamed wolf has attacked the entity and decremented once per tick, instead of checking for the entity that attacked it (you can get around this by adding a field which stores the entity that killed it, set in onDeath).
So i'm modding with 1.8.8 MCP meaning i can't use spigot or any methods like that and i need to get an entity's killer / cause of death. I can't even find any tutorials or such because everything i have found uses spigot or forge.
I can already kind of do it with mc.thePlayer.getLastAttacker() (which actually returns the last entity that the player has attacked) but it doesn't work on other entities or players. It would probably be easy to implement my self but i'm just starting out with java so please respond if you know a way to do it.
This may not be exactly the same in 1.8.9 (I mod in 1.6.4) but the method EntityLivingBase.onDeath is where entities handle their death event, which includes a DamageSource parameter which in turns stores the entity that dealt the damage (if applicable):
(this is my own modified code but the important part is DamageSource.getEntity)
Some entities override this to add in special drops, such as creepers shot by skeletons dropping music discs or players dropping their inventory, but they all call the super method (so modifying the one in EntityLivingBase will apply to all living entities, including players).
Note that XP drops are handled in a separate method, onDeathUpdate, and they use a counter which is set to 100 when a player or tamed wolf has attacked the entity and decremented once per tick, instead of checking for the entity that attacked it (you can get around this by adding a field which stores the entity that killed it, set in onDeath).
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?