Unicopia/src/main/java/com/minelittlepony/util/MagicalDamageSource.java

58 lines
2.2 KiB
Java
Raw Normal View History

2018-09-12 01:29:49 +02:00
package com.minelittlepony.util;
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
public static DamageSource create(String type) {
return new MagicalDamageSource(type);
}
2018-09-19 09:09:43 +02:00
public static DamageSource causePlayerDamage(String type, EntityPlayer player) {
return new MagicalDamageSource(type, player);
}
2018-09-19 09:09:43 +02:00
public static DamageSource causeMobDamage(String type, EntityLivingBase source) {
return new MagicalDamageSource(type, source);
}
2018-09-19 09:09:43 +02:00
protected MagicalDamageSource(String type) {
this(type, null);
}
2018-09-19 09:09:43 +02: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
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) {
String withAttecker = basic + ".player";
ItemStack held = attacker instanceof EntityLivingBase ? ((EntityLivingBase)attacker).getHeldItemMainhand() : ItemStack.EMPTY;
2018-09-19 09:09:43 +02:00
String withItem = withAttecker + ".item";
if (held != null && held.hasDisplayName() && ServerLocale.hasKey(withItem)) {
return new TextComponentTranslation(withItem, target.getDisplayName(), attacker.getDisplayName(), held.getTextComponent());
}
2018-09-19 09:09:43 +02:00
if (ServerLocale.hasKey(withAttecker)) {
return new TextComponentTranslation(withAttecker, target.getDisplayName(), attacker.getDisplayName());
}
}
2018-09-19 09:09:43 +02:00
return new TextComponentTranslation(basic, target.getDisplayName());
2018-09-12 01:29:49 +02:00
}
}