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;
|
package com.minelittlepony.unicopia.entity.ai;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
import com.minelittlepony.unicopia.projectile.PhysicsBodyProjectileEntity;
|
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.Entity;
|
||||||
import net.minecraft.entity.mob.MobEntity;
|
import net.minecraft.entity.mob.MobEntity;
|
||||||
import net.minecraft.entity.passive.AnimalEntity;
|
import net.minecraft.entity.passive.AnimalEntity;
|
||||||
|
@ -44,8 +48,9 @@ public class EatMuffinGoal extends BreakHeartGoal {
|
||||||
@Override
|
@Override
|
||||||
protected boolean canTarget(Entity e) {
|
protected boolean canTarget(Entity e) {
|
||||||
return !e.isRemoved()
|
return !e.isRemoved()
|
||||||
&& e instanceof PhysicsBodyProjectileEntity
|
&& e instanceof PhysicsBodyProjectileEntity p
|
||||||
&& ((PhysicsBodyProjectileEntity)e).getStack().getItem() == UItems.MUFFIN
|
&& p.getStack().getItem() == UItems.MUFFIN
|
||||||
|
&& p.getStack().get(DataComponentTypes.FOOD) != null
|
||||||
&& mob.getVisibilityCache().canSee(e);
|
&& mob.getVisibilityCache().canSee(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +71,11 @@ public class EatMuffinGoal extends BreakHeartGoal {
|
||||||
eatingStarted = true;
|
eatingStarted = true;
|
||||||
|
|
||||||
if (target instanceof PhysicsBodyProjectileEntity projectile) {
|
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();
|
projectile.discard();
|
||||||
|
|
||||||
if (mob instanceof AnimalEntity animal) {
|
if (mob instanceof AnimalEntity animal) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
||||||
creature.setSmitten(true);
|
creature.setSmitten(true);
|
||||||
|
|
||||||
if (distance <= reach) {
|
if (distance <= reach) {
|
||||||
if (target instanceof LivingEntity) {
|
if (target instanceof LivingEntity living) {
|
||||||
if (cooldown <= 0) {
|
if (cooldown <= 0) {
|
||||||
cooldown = 20;
|
cooldown = 20;
|
||||||
mob.tryAttack(target);
|
mob.tryAttack(target);
|
||||||
|
@ -76,10 +76,10 @@ public class WantItTakeItGoal extends BreakHeartGoal {
|
||||||
|
|
||||||
if (mob.getWorld().random.nextInt(20) == 0) {
|
if (mob.getWorld().random.nextInt(20) == 0) {
|
||||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
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) {
|
if (EnchantmentHelper.getLevel(UEnchantments.WANT_IT_NEED_IT, stack) > 0) {
|
||||||
AwaitTickQueue.scheduleTask(mob.getWorld(), w -> {
|
AwaitTickQueue.scheduleTask(mob.getWorld(), w -> {
|
||||||
target.equipStack(slot, ItemStack.EMPTY);
|
living.equipStack(slot, ItemStack.EMPTY);
|
||||||
mob.tryEquip(stack);
|
mob.tryEquip(stack);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue