mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed passive entities not attacking the player when holding items with want it need it
This commit is contained in:
parent
7187ad61ee
commit
159a870599
4 changed files with 31 additions and 13 deletions
|
@ -5,9 +5,8 @@ import java.util.function.Predicate;
|
|||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
import com.minelittlepony.unicopia.entity.MagicImmune;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.decoration.AbstractDecorationEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -34,12 +33,7 @@ public interface EquinePredicates {
|
|||
Predicate<Entity> EXCEPT_MAGIC_IMMUNE = IS_MAGIC_IMMUNE.negate();
|
||||
Predicate<Entity> VALID_LIVING_AND_NOT_MAGIC_IMMUNE = EntityPredicates.VALID_LIVING_ENTITY.and(EXCEPT_MAGIC_IMMUNE);
|
||||
|
||||
Predicate<LivingEntity> HAS_WANT_IT_NEED_IT = e -> {
|
||||
return EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, e) > 0
|
||||
|| EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, e.getOffHandStack()) > 0
|
||||
|| EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, e.getMainHandStack()) > 0;
|
||||
};
|
||||
|
||||
Predicate<LivingEntity> LIVING_HAS_WANT_IT_NEED_IT = e -> WantItNeedItEnchantment.getLevel(e) > 0;
|
||||
Predicate<Entity> VALID_FOR_DISGUISE = EntityPredicates.EXCEPT_SPECTATOR.and(e -> !(e instanceof LightningEntity || e instanceof AbstractDecorationEntity));
|
||||
|
||||
static Predicate<Entity> ofRace(Race race) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity.ai;
|
|||
import com.minelittlepony.unicopia.AwaitTickQueue;
|
||||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
|
||||
import com.minelittlepony.unicopia.particle.FollowingParticleEffect;
|
||||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
|
@ -14,13 +15,14 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.ai.TargetPredicate;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public class WantItTakeItGoal extends BreakHeartGoal {
|
||||
|
||||
private final TargetPredicate predicate = TargetPredicate.createAttackable()
|
||||
private final TargetPredicate predicate = TargetPredicate.createNonAttackable()
|
||||
.setBaseMaxDistance(64)
|
||||
.setPredicate(EquinePredicates.HAS_WANT_IT_NEED_IT);
|
||||
.setPredicate(EquinePredicates.LIVING_HAS_WANT_IT_NEED_IT.and(LivingEntity::canTakeDamage).and(EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR));
|
||||
|
||||
protected int cooldown;
|
||||
|
||||
|
@ -30,8 +32,11 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
|||
|
||||
@Override
|
||||
protected boolean canTarget(Entity e) {
|
||||
return (!e.isRemoved() && e instanceof ItemEntity && EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, ((ItemEntity)e).getStack()) > 0)
|
||||
|| (e instanceof LivingEntity && predicate.test(mob, (LivingEntity)e));
|
||||
return e != null && !e.isRemoved() && (
|
||||
(e instanceof LivingEntity l && predicate.test(mob, l)
|
||||
|| (e instanceof ItemEntity i && WantItNeedItEnchantment.getLevel(i) > 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -65,7 +65,7 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
|
|||
if (player instanceof ServerPlayerEntity recipient
|
||||
&& player.currentScreenHandler instanceof SpellbookScreenHandler book
|
||||
&& getUuid().equals(book.entityId)) {
|
||||
Channel.SERVER_SPELLBOOK_UPDATE.sendToPlayer(new MsgSpellbookStateChanged<>(book.syncId, state), recipient);
|
||||
Channel.SERVER_SPELLBOOK_UPDATE.sendToPlayer(MsgSpellbookStateChanged.create(book, state), recipient);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,6 +7,9 @@ import com.minelittlepony.unicopia.particle.ParticleUtils;
|
|||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class WantItNeedItEnchantment extends SimpleEnchantment {
|
||||
|
@ -27,4 +30,20 @@ public class WantItNeedItEnchantment extends SimpleEnchantment {
|
|||
int oldLevel = EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, oldStack);
|
||||
return newLevel > oldLevel;
|
||||
}
|
||||
|
||||
public static int getLevel(Entity entity) {
|
||||
return entity instanceof LivingEntity l ? getLevel(l)
|
||||
: entity instanceof ItemEntity i ? getLevel(i)
|
||||
: 0;
|
||||
}
|
||||
|
||||
public static int getLevel(ItemEntity entity) {
|
||||
return EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getStack());
|
||||
}
|
||||
|
||||
public static int getLevel(LivingEntity entity) {
|
||||
return EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, entity)
|
||||
+ EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getOffHandStack())
|
||||
+ EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, entity.getMainHandStack());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue