mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Fix errors in entity ai
This commit is contained in:
parent
9789b0f738
commit
de548235ca
2 changed files with 15 additions and 6 deletions
|
@ -1,8 +1,12 @@
|
|||
package com.minelittlepony.unicopia.entity.ai;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.projectile.PhysicsBodyProjectileEntity;
|
||||
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.FoodComponent;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.passive.AnimalEntity;
|
||||
|
@ -44,8 +48,9 @@ public class EatMuffinGoal extends BreakHeartGoal {
|
|||
@Override
|
||||
protected boolean canTarget(Entity e) {
|
||||
return !e.isRemoved()
|
||||
&& e instanceof PhysicsBodyProjectileEntity
|
||||
&& ((PhysicsBodyProjectileEntity)e).getStack().getItem() == UItems.MUFFIN
|
||||
&& e instanceof PhysicsBodyProjectileEntity p
|
||||
&& p.getStack().getItem() == UItems.MUFFIN
|
||||
&& p.getStack().get(DataComponentTypes.FOOD) != null
|
||||
&& mob.getVisibilityCache().canSee(e);
|
||||
}
|
||||
|
||||
|
@ -66,7 +71,11 @@ public class EatMuffinGoal extends BreakHeartGoal {
|
|||
eatingStarted = true;
|
||||
|
||||
if (target instanceof PhysicsBodyProjectileEntity projectile) {
|
||||
mob.eatFood(mob.getWorld(), projectile.getStack());
|
||||
@Nullable
|
||||
FoodComponent food = projectile.getStack().get(DataComponentTypes.FOOD);
|
||||
if (food != null) {
|
||||
mob.eatFood(mob.getWorld(), projectile.getStack(), food);
|
||||
}
|
||||
projectile.discard();
|
||||
|
||||
if (mob instanceof AnimalEntity animal) {
|
||||
|
|
|
@ -68,7 +68,7 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
|||
creature.setSmitten(true);
|
||||
|
||||
if (distance <= reach) {
|
||||
if (target instanceof LivingEntity) {
|
||||
if (target instanceof LivingEntity living) {
|
||||
if (cooldown <= 0) {
|
||||
cooldown = 20;
|
||||
mob.tryAttack(target);
|
||||
|
@ -76,10 +76,10 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
|||
|
||||
if (mob.getWorld().random.nextInt(20) == 0) {
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack stack = ((LivingEntity)target).getEquippedStack(slot);
|
||||
ItemStack stack = living.getEquippedStack(slot);
|
||||
if (EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, stack) > 0) {
|
||||
AwaitTickQueue.scheduleTask(mob.getWorld(), w -> {
|
||||
target.equipStack(slot, ItemStack.EMPTY);
|
||||
living.equipStack(slot, ItemStack.EMPTY);
|
||||
mob.tryEquip(stack);
|
||||
});
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue