mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Fixed crash when dying
This commit is contained in:
parent
ece5f378dc
commit
0af0cb2182
2 changed files with 47 additions and 52 deletions
|
@ -1,5 +1,8 @@
|
||||||
package com.minelittlepony.unicopia.util;
|
package com.minelittlepony.unicopia.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
@ -12,18 +15,21 @@ import net.minecraft.entity.projectile.ArrowEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Language;
|
|
||||||
|
|
||||||
public class MagicalDamageSource extends EntityDamageSource {
|
public class MagicalDamageSource extends EntityDamageSource {
|
||||||
|
|
||||||
public static final DamageSource FOOD_POISONING = new MundaneDamageSource("food_poisoning").setBypassesArmor();
|
public static final DamageSource FOOD_POISONING = mundane("food_poisoning");
|
||||||
public static final DamageSource ACID = new MundaneDamageSource("acid");
|
public static final DamageSource ACID = mundane("acid");
|
||||||
public static final DamageSource ALICORN_AMULET = new MagicalDamageSource("alicorn_amulet").setUnblockable().setBypassesArmor();
|
public static final DamageSource ALICORN_AMULET = new MagicalDamageSource("alicorn_amulet", true, true);
|
||||||
public static final DamageSource DARKNESS = new MagicalDamageSource("darkness");
|
public static final DamageSource DARKNESS = create("darkness");
|
||||||
public static final DamageSource ZAP_APPLE = new MagicalDamageSource("zap");
|
public static final DamageSource ZAP_APPLE = create("zap");
|
||||||
|
|
||||||
|
public static DamageSource mundane(String type) {
|
||||||
|
return new DamageSource(type) {};
|
||||||
|
}
|
||||||
|
|
||||||
public static DamageSource create(String type) {
|
public static DamageSource create(String type) {
|
||||||
return new MagicalDamageSource(type);
|
return new MagicalDamageSource(type, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DamageSource causePlayerDamage(String type, PlayerEntity player) {
|
public static DamageSource causePlayerDamage(String type, PlayerEntity player) {
|
||||||
|
@ -31,65 +37,54 @@ public class MagicalDamageSource extends EntityDamageSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DamageSource causeMobDamage(String type, LivingEntity source) {
|
public static DamageSource causeMobDamage(String type, LivingEntity source) {
|
||||||
return new MagicalDamageSource(type, source);
|
return new MagicalDamageSource(type, source, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DamageSource causeIndirect(String type, ArrowEntity source, @Nullable Entity instigator) {
|
public static DamageSource causeIndirect(String type, ArrowEntity source, @Nullable Entity instigator) {
|
||||||
return new ProjectileDamageSource(type, source, instigator).setProjectile();
|
return new ProjectileDamageSource(type, source, instigator).setProjectile();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MagicalDamageSource(String type) {
|
protected MagicalDamageSource(String type, boolean direct, boolean unblockable) {
|
||||||
this(type, null);
|
this(type, null, direct, unblockable);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MagicalDamageSource(String type, Entity source) {
|
protected MagicalDamageSource(String type, Entity source, boolean direct, boolean unblockable) {
|
||||||
super(type, source);
|
super(type, source);
|
||||||
setUsesMagic();
|
setUsesMagic();
|
||||||
|
if (direct) {
|
||||||
|
setBypassesArmor();
|
||||||
|
}
|
||||||
|
if (unblockable) {
|
||||||
|
setUnblockable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDeathMessage(LivingEntity target) {
|
public Text getDeathMessage(LivingEntity target) {
|
||||||
Entity attacker = source instanceof LivingEntity ? (LivingEntity)source : target.getVehicle();
|
|
||||||
String basic = "death.attack." + name;
|
String basic = "death.attack." + name;
|
||||||
|
|
||||||
if (attacker != null && attacker instanceof LivingEntity) {
|
List<Text> params = new ArrayList<>();
|
||||||
String withAttecker = basic + ".player";
|
params.add(target.getDisplayName());
|
||||||
ItemStack held = ((LivingEntity)attacker).getMainHandStack();
|
|
||||||
|
|
||||||
if (!held.isEmpty() && held.hasCustomName()) {
|
@Nullable
|
||||||
return new TranslatableText(withAttecker + ".item", target.getDisplayName(), attacker.getDisplayName(), held.toHoverableText());
|
Entity attacker = source instanceof LivingEntity ? source : target.getPrimeAdversary();
|
||||||
|
|
||||||
|
if (attacker instanceof LivingEntity) {
|
||||||
|
if (attacker == target) {
|
||||||
|
basic += ".self";
|
||||||
|
} else {
|
||||||
|
basic += ".attacker";
|
||||||
|
params.add(((LivingEntity)attacker).getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Language.getInstance().hasTranslation(withAttecker)) {
|
ItemStack item = ((LivingEntity)attacker).getMainHandStack();
|
||||||
return new TranslatableText(withAttecker, target.getDisplayName(), attacker.getDisplayName());
|
if (!item.isEmpty() && item.hasCustomName()) {
|
||||||
|
basic += ".item";
|
||||||
|
params.add(item.toHoverableText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TranslatableText(basic, target.getDisplayName(), source.getDisplayName());
|
return new TranslatableText(basic, params.toArray());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MagicalDamageSource setUnblockable() {
|
|
||||||
super.setUnblockable();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MagicalDamageSource setBypassesArmor() {
|
|
||||||
super.setBypassesArmor();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MundaneDamageSource extends DamageSource {
|
|
||||||
|
|
||||||
public MundaneDamageSource(String key) {
|
|
||||||
super(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DamageSource setBypassesArmor() {
|
|
||||||
return super.setBypassesArmor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,20 +280,20 @@
|
||||||
"death.attack.alicorn_amulet": "%1$s was driven insane",
|
"death.attack.alicorn_amulet": "%1$s was driven insane",
|
||||||
"death.attack.darkness": "%1$s went missing",
|
"death.attack.darkness": "%1$s went missing",
|
||||||
"death.attack.feed": "%1$s was drained of all life",
|
"death.attack.feed": "%1$s was drained of all life",
|
||||||
"death.attack.feed.player": "%1$s died to feed %2$s",
|
"death.attack.feed.attacker": "%1$s died to feed %2$s",
|
||||||
"death.attack.cold": "%1$s died of frost bite",
|
"death.attack.cold": "%1$s died of frost bite",
|
||||||
"death.attack.cold.player": "%1$s was frozen to death by %2$s",
|
"death.attack.cold.attacker": "%1$s was frozen to death by %2$s",
|
||||||
"death.attack.cold.player.item": "%1$s was frozen to death by %2$s using %3$s",
|
"death.attack.cold.attacker.item": "%1$s was frozen to death by %2$s using %3$s",
|
||||||
"death.attack.smash": "%1$s was crushed under hoof",
|
"death.attack.smash": "%1$s was crushed under hoof",
|
||||||
"death.attack.smash.player": "%1$s was crushed by %2$s",
|
"death.attack.smash.attacker": "%1$s was crushed by %2$s",
|
||||||
"death.attack.fire": "%1$s was burnt to a crisp by magic",
|
"death.attack.fire": "%1$s was burnt to a crisp by magic",
|
||||||
"death.attack.fire.player": "%1$s was burnt to a crisp by %2$s",
|
"death.attack.fire.attacker": "%1$s was burnt to a crisp by %2$s",
|
||||||
"death.attack.fire.own": "%1$s was burnt to a crisp by their own spell",
|
"death.attack.fire.self": "%1$s was burnt to a crisp by their own spell",
|
||||||
"death.attack.zap": "%1$s ate a Zap Apple",
|
"death.attack.zap": "%1$s ate a Zap Apple",
|
||||||
"death.attack.paradox": "%1$s imploded",
|
"death.attack.paradox": "%1$s imploded",
|
||||||
"death.attack.acid": "%1$s drowned in acid",
|
"death.attack.acid": "%1$s drowned in acid",
|
||||||
"death.attack.food_poisoning": "%1$s died of food poisoning",
|
"death.attack.food_poisoning": "%1$s died of food poisoning",
|
||||||
"death.attack.food_poisoning.player": "%1$s poisoned %1$s' to death",
|
"death.attack.food_poisoning.attacker": "%2$s poisoned %1$s to death",
|
||||||
|
|
||||||
"advancements.adventure.bag_of_holding.title": "Read the Manual",
|
"advancements.adventure.bag_of_holding.title": "Read the Manual",
|
||||||
"advancements.adventure.bag_of_holding.description": "Successfully die using the Bag of Holding",
|
"advancements.adventure.bag_of_holding.description": "Successfully die using the Bag of Holding",
|
||||||
|
|
Loading…
Reference in a new issue