mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-18 19:04:23 +01:00
Fix build
This commit is contained in:
parent
c0cff59963
commit
ae8068ccb4
3 changed files with 29 additions and 7 deletions
|
@ -483,8 +483,8 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
|
|
||||||
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
||||||
|
|
||||||
if ((source.getAttacker() instanceof Guest guest && guest.getHost() instanceof Living l && l == this)
|
if (Guest.of(source.getAttacker()).hostIs(this)
|
||||||
|| (source.getSource() instanceof Guest guest && guest.getHost() instanceof Living l && l == this)) {
|
|| Guest.of(source.getSource()).hostIs(this)) {
|
||||||
var type = source.getTypeRegistryEntry();
|
var type = source.getTypeRegistryEntry();
|
||||||
return Optional.of(entity.damage(
|
return Optional.of(entity.damage(
|
||||||
type.matchesKey(DamageTypes.FIREBALL) ? entity.getDamageSources().create(DamageTypes.UNATTRIBUTED_FIREBALL) :
|
type.matchesKey(DamageTypes.FIREBALL) ? entity.getDamageSources().create(DamageTypes.UNATTRIBUTED_FIREBALL) :
|
||||||
|
@ -492,7 +492,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
new DamageSource(type, entity, entity), amount));
|
new DamageSource(type, entity, entity), amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Guest guest && guest.getHost() instanceof Living l) {
|
if (Guest.of(entity).getHost() instanceof Living l) {
|
||||||
l.asEntity().damage(source, amount);
|
l.asEntity().damage(source, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,37 @@
|
||||||
package com.minelittlepony.unicopia.entity.behaviour;
|
package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
public interface Guest {
|
public interface Guest {
|
||||||
void setHost(Caster<?> host);
|
Guest NULL = new Guest() {
|
||||||
|
@Override
|
||||||
|
public void setHost(@Nullable Caster<?> host) { }
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Caster<?> getHost() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setHost(@Nullable Caster<?> host);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
Caster<?> getHost();
|
Caster<?> getHost();
|
||||||
|
|
||||||
static boolean hasHost(Entity entity) {
|
static Guest of(@Nullable Entity entity) {
|
||||||
return ((Guest)entity).getHost() != null;
|
return entity == null ? NULL : (Guest)entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean hasHost() {
|
||||||
|
return getHost() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean hostIs(Caster<?> self) {
|
||||||
|
return getHost() == self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class CrystalShardsEntity extends StationaryObjectEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Guest.hasHost(this)) {
|
if (!Guest.of(this).hasHost()) {
|
||||||
if (isDead() || isInvalid(getWorld(), getBlockPos(), getAttachmentFace())) {
|
if (isDead() || isInvalid(getWorld(), getBlockPos(), getAttachmentFace())) {
|
||||||
kill();
|
kill();
|
||||||
ParticleUtils.spawnParticles(ParticleTypes.CLOUD, this, 10);
|
ParticleUtils.spawnParticles(ParticleTypes.CLOUD, this, 10);
|
||||||
|
|
Loading…
Reference in a new issue