Prevent registering custom AI to our own entities. Closes #185

This commit is contained in:
Sollace 2023-09-13 13:55:06 +01:00
parent 94d7ff1419
commit b7487e9901
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 13 additions and 17 deletions

View file

@ -17,7 +17,6 @@ import com.minelittlepony.unicopia.entity.ai.BreakHeartGoal;
import com.minelittlepony.unicopia.entity.ai.DynamicTargetGoal;
import com.minelittlepony.unicopia.entity.ai.EatMuffinGoal;
import com.minelittlepony.unicopia.entity.ai.WantItTakeItGoal;
import com.minelittlepony.unicopia.entity.mob.SombraEntity;
import com.minelittlepony.unicopia.entity.mob.UEntityAttributes;
import net.minecraft.entity.EntityType;
@ -122,14 +121,13 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
}
public void initAi(GoalSelector goals, GoalSelector targets) {
if (entity instanceof SombraEntity) {
return;
}
this.goals = Optional.of(goals);
this.targets = Optional.of(targets);
if (entity instanceof MagicImmune) {
return;
}
DynamicTargetGoal targetter = new DynamicTargetGoal((MobEntity)entity);
targets.add(1, targetter);
if (!Unicopia.getConfig().wantItNeedItEntityExcludelist.get().contains(EntityType.getId(entity.getType()).toString())) {
@ -143,13 +141,8 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
goals.add(3, eatMuffinGoal);
}
if (getMasterReference().isSet()) {
initMinionAi(targets);
}
if (isDiscorded()) {
initDiscordedAi();
}
initMinionAi(targets);
initDiscordedAi();
if (entity instanceof CreeperEntity mob) {
goals.add(1, new FleeEntityGoal<>(mob, LivingEntity.class, 10, 1.5, 1.9, AmuletSelectors.ALICORN_AMULET));
@ -160,6 +153,10 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
}
private void initMinionAi(GoalSelector targets) {
if (entity instanceof MagicImmune || !getMasterReference().isSet()) {
return;
}
clearGoals(targets);
targets.add(2, new ActiveEnemyGoal<>(PlayerEntity.class));
targets.add(2, new ActiveEnemyGoal<>(HostileEntity.class));
@ -167,7 +164,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
}
private void initDiscordedAi() {
if (getMasterReference().isSet()) {
if (entity instanceof MagicImmune || getMasterReference().isSet() || !isDiscorded()) {
return;
}
targets.ifPresent(this::clearGoals);
@ -197,7 +194,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned.Mutabl
@Override
public boolean beforeUpdate() {
if (isDiscorded() && discordedChanged) {
if (discordedChanged) {
discordedChanged = false;
initDiscordedAi();
}

View file

@ -6,7 +6,6 @@ import java.util.stream.StreamSupport;
import org.jetbrains.annotations.Nullable;
import com.google.common.base.Preconditions;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.Unicopia;
@ -113,7 +112,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
}
public <Q extends Tickable> Q addTicker(Q tickable) {
tickers.add(Preconditions.checkNotNull(tickable, "tickable"));
tickers.add(Objects.requireNonNull(tickable, "tickable cannot be null"));
return tickable;
}