Fix build

This commit is contained in:
Sollace 2024-02-15 14:17:02 +00:00
parent c0cff59963
commit ae8068ccb4
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 29 additions and 7 deletions

View file

@ -483,8 +483,8 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
public Optional<Boolean> onDamage(DamageSource source, float amount) {
if ((source.getAttacker() instanceof Guest guest && guest.getHost() instanceof Living l && l == this)
|| (source.getSource() instanceof Guest guest && guest.getHost() instanceof Living l && l == this)) {
if (Guest.of(source.getAttacker()).hostIs(this)
|| Guest.of(source.getSource()).hostIs(this)) {
var type = source.getTypeRegistryEntry();
return Optional.of(entity.damage(
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));
}
if (entity instanceof Guest guest && guest.getHost() instanceof Living l) {
if (Guest.of(entity).getHost() instanceof Living l) {
l.asEntity().damage(source, amount);
}

View file

@ -1,15 +1,37 @@
package com.minelittlepony.unicopia.entity.behaviour;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.magic.Caster;
import net.minecraft.entity.Entity;
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();
static boolean hasHost(Entity entity) {
return ((Guest)entity).getHost() != null;
static Guest of(@Nullable Entity entity) {
return entity == null ? NULL : (Guest)entity;
}
default boolean hasHost() {
return getHost() != null;
}
default boolean hostIs(Caster<?> self) {
return getHost() == self;
}
}

View file

@ -173,7 +173,7 @@ public class CrystalShardsEntity extends StationaryObjectEntity {
}
}
if (!Guest.hasHost(this)) {
if (!Guest.of(this).hasHost()) {
if (isDead() || isInvalid(getWorld(), getBlockPos(), getAttachmentFace())) {
kill();
ParticleUtils.spawnParticles(ParticleTypes.CLOUD, this, 10);