Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Feb 15, 2024
1 parent c0cff59 commit ae8068c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/minelittlepony/unicopia/entity/Living.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ public final Caster<?> getAttacker() {

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) :
type.matchesKey(DamageTypes.PLAYER_EXPLOSION) ? entity.getDamageSources().create(DamageTypes.EXPLOSION) :
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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void tick() {
}
}

if (!Guest.hasHost(this)) {
if (!Guest.of(this).hasHost()) {
if (isDead() || isInvalid(getWorld(), getBlockPos(), getAttachmentFace())) {
kill();
ParticleUtils.spawnParticles(ParticleTypes.CLOUD, this, 10);
Expand Down

0 comments on commit ae8068c

Please sign in to comment.