mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-12-17 23:48:00 +01:00
Change the stored attacker to a Caster<?>
This commit is contained in:
parent
4110c66493
commit
8629cba3e9
5 changed files with 22 additions and 19 deletions
|
@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.EntityConvertable;
|
import com.minelittlepony.unicopia.EntityConvertable;
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
|
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
import com.minelittlepony.unicopia.util.Tickable;
|
import com.minelittlepony.unicopia.util.Tickable;
|
||||||
|
@ -24,7 +25,8 @@ public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, Pro
|
||||||
/**
|
/**
|
||||||
* Gets the last magical entity to attack us.
|
* Gets the last magical entity to attack us.
|
||||||
*/
|
*/
|
||||||
Entity getAttacker();
|
@Nullable
|
||||||
|
Caster<?> getAttacker();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this player is fully invisible.
|
* Returns true if this player is fully invisible.
|
||||||
|
|
|
@ -2,7 +2,10 @@ package com.minelittlepony.unicopia.entity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.*;
|
import com.minelittlepony.unicopia.*;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||||
import com.minelittlepony.unicopia.util.VecHelper;
|
import com.minelittlepony.unicopia.util.VecHelper;
|
||||||
|
|
||||||
|
@ -39,8 +42,9 @@ public class ItemImpl implements Equine<ItemEntity> {
|
||||||
owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString());
|
owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Entity getAttacker() {
|
public Caster<?> getAttacker() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
private Runnable landEvent;
|
private Runnable landEvent;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Entity attacker;
|
private Caster<?> attacker;
|
||||||
|
|
||||||
private int invinsibilityTicks;
|
private int invinsibilityTicks;
|
||||||
|
|
||||||
|
@ -175,21 +175,19 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public final Entity getAttacker() {
|
public final Caster<?> getAttacker() {
|
||||||
return attacker;
|
return attacker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
||||||
|
|
||||||
if (source == DamageSource.LIGHTNING_BOLT) {
|
if (source == DamageSource.LIGHTNING_BOLT && (invinsibilityTicks > 0 || tryCaptureLightning())) {
|
||||||
if (invinsibilityTicks > 0 || tryCaptureLightning()) {
|
return Optional.of(false);
|
||||||
return Optional.of(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof MagicalDamageSource magical) {
|
if (source instanceof MagicalDamageSource magical) {
|
||||||
Entity attacker = ((MagicalDamageSource)source).getSpell();
|
Caster<?> attacker = ((MagicalDamageSource)source).getSpell();
|
||||||
if (attacker != null) {
|
if (attacker != null) {
|
||||||
this.attacker = attacker;
|
this.attacker = attacker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Owned;
|
|
||||||
import com.minelittlepony.unicopia.entity.Equine;
|
import com.minelittlepony.unicopia.entity.Equine;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
@ -14,19 +13,18 @@ import net.minecraft.text.Text;
|
||||||
|
|
||||||
@Mixin(DamageSource.class)
|
@Mixin(DamageSource.class)
|
||||||
abstract class MixinDamageSource {
|
abstract class MixinDamageSource {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true)
|
@Inject(method = "getDeathMessage", at = @At("RETURN"), cancellable = true)
|
||||||
private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) {
|
private void onGetDeathMessage(LivingEntity entity, CallbackInfoReturnable<Text> info) {
|
||||||
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> {
|
Equine.of(entity).map(Equine::getAttacker).ifPresent(attacker -> {
|
||||||
DamageSource self = (DamageSource)(Object)this;
|
DamageSource self = (DamageSource)(Object)this;
|
||||||
|
|
||||||
Entity prime = entity.getPrimeAdversary();
|
Entity prime = entity.getPrimeAdversary();
|
||||||
if (prime != null && !(attacker instanceof Owned<?> && ((Owned<Entity>)attacker).isOwnedBy(prime))) {
|
if (prime != null && !attacker.isOwnedBy(prime)) {
|
||||||
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.getDisplayName()));
|
info.setReturnValue(Text.translatable("death.attack.generic.and_also", info.getReturnValue(), attacker.asEntity().getDisplayName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.setReturnValue(Text.translatable("death.attack." + self.getName() + ".player", entity.getDisplayName(), attacker.getDisplayName()));
|
info.setReturnValue(Text.translatable("death.attack." + self.getName() + ".player", entity.getDisplayName(), attacker.asEntity().getDisplayName()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,18 +36,19 @@ public class MagicalDamageSource extends EntityDamageSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MagicalDamageSource create(String type, Caster<?> caster) {
|
public static MagicalDamageSource create(String type, Caster<?> caster) {
|
||||||
return new MagicalDamageSource(type, caster.getMaster(), caster.asEntity(), false, false);
|
return new MagicalDamageSource(type, caster.getMaster(), caster, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entity spell;
|
@Nullable
|
||||||
|
private Caster<?> spell;
|
||||||
|
|
||||||
private boolean breakSunglasses;
|
private boolean breakSunglasses;
|
||||||
|
|
||||||
protected MagicalDamageSource(String type, @Nullable Entity spell, boolean direct, boolean unblockable) {
|
protected MagicalDamageSource(String type, @Nullable Caster<?> spell, boolean direct, boolean unblockable) {
|
||||||
this(type, null, spell, direct, unblockable);
|
this(type, null, spell, direct, unblockable);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MagicalDamageSource(String type, @Nullable Entity source, @Nullable Entity spell, boolean direct, boolean unblockable) {
|
protected MagicalDamageSource(String type, @Nullable Entity source, @Nullable Caster<?> spell, boolean direct, boolean unblockable) {
|
||||||
super(type, source);
|
super(type, source);
|
||||||
this.spell = spell;
|
this.spell = spell;
|
||||||
setUsesMagic();
|
setUsesMagic();
|
||||||
|
@ -69,7 +70,7 @@ public class MagicalDamageSource extends EntityDamageSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Entity getSpell() {
|
public Caster<?> getSpell() {
|
||||||
return spell;
|
return spell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue