2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.util;
|
|
|
|
|
2019-02-19 10:48:00 +01:00
|
|
|
import com.minelittlepony.util.lang.ServerLocale;
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraft.util.EntityDamageSource;
|
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
|
|
|
|
|
|
|
public class MagicalDamageSource extends EntityDamageSource {
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
public static DamageSource create(String type) {
|
|
|
|
return new MagicalDamageSource(type);
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
public static DamageSource causePlayerDamage(String type, EntityPlayer player) {
|
|
|
|
return new MagicalDamageSource(type, player);
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
public static DamageSource causeMobDamage(String type, EntityLivingBase source) {
|
|
|
|
return new MagicalDamageSource(type, source);
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
protected MagicalDamageSource(String type) {
|
|
|
|
this(type, null);
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
protected MagicalDamageSource(String type, Entity source) {
|
|
|
|
super(type, source);
|
|
|
|
setMagicDamage();
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
public ITextComponent getDeathMessage(EntityLivingBase target) {
|
2018-09-12 01:29:49 +02:00
|
|
|
Entity attacker = damageSourceEntity instanceof EntityLivingBase ? (EntityLivingBase)damageSourceEntity : target.getRidingEntity();
|
|
|
|
String basic = "death.attack." + this.damageType;
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
if (attacker != null && attacker instanceof EntityLivingBase) {
|
2019-02-08 22:39:02 +01:00
|
|
|
String withAttecker = basic + ".player";
|
|
|
|
ItemStack held = attacker instanceof EntityLivingBase ? ((EntityLivingBase)attacker).getHeldItemMainhand() : ItemStack.EMPTY;
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
String withItem = withAttecker + ".item";
|
2019-02-19 10:48:00 +01:00
|
|
|
if (held != null && held.hasDisplayName() && ServerLocale.hasKey(withItem)) {
|
2019-02-08 22:39:02 +01:00
|
|
|
return new TextComponentTranslation(withItem, target.getDisplayName(), attacker.getDisplayName(), held.getTextComponent());
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-19 10:48:00 +01:00
|
|
|
if (ServerLocale.hasKey(withAttecker)) {
|
2019-02-08 22:39:02 +01:00
|
|
|
return new TextComponentTranslation(withAttecker, target.getDisplayName(), attacker.getDisplayName());
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 09:09:43 +02:00
|
|
|
|
2019-02-08 22:39:02 +01:00
|
|
|
return new TextComponentTranslation(basic, target.getDisplayName());
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|