Волк не кушает предмет который я хочу покормить его. СДелай ещё чтобы он видел еду и поворачивал голову как при стейке когда кормишь волка приручённого. Пожалуйста
Neoforge 1.21.1
📄
pasted-code-1783170932946.txt
txt
56 lines
▶
package com.granatode.etherDrops.item;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Wolf;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
public class DogFeedItem extends Item {
private final float healAmount;
private final boolean isPremium;
public DogFeedItem(float healAmount, boolean isPremium, Item.Properties properties) {
super(properties);
this.healAmount = healAmount;
this.isPremium = isPremium;
}
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) {
if (entity instanceof Wolf wolf && wolf.isTame()) {
Level level = player.level();
wolf.heal(healAmount);
// Spawn heart particles
for (int i = 0; i < 3; i++) {
level.addParticle(ParticleTypes.HEART,
wolf.getX() + (level.random.nextDouble() - 0.5) * wolf.getBbWidth(),
wolf.getY() + wolf.getBbHeight() + 0.5,
wolf.getZ() + (level.random.nextDouble() - 0.5) * wolf.getBbWidth(),
0.0, 0.0, 0.0);
}
if (isPremium) {
wolf.addEffect(new net.minecraft.world.effect.MobEffectInstance(
net.minecraft.world.effect.MobEffects.MOVEMENT_SPEED,
600, // 30 seconds (20 ticks per second)
0
));
}
if (!player.getAbilities().instabuild) {
stack.shrink(1);
}
return InteractionResult.CONSUME;
}
return InteractionResult.PASS;
}
}
Creating the full Neoforge 1.21.1 Maven mod project. The fix: the wolf now turns its head (setInterested(true)) and plays the eating animation (ate()) when fed.
C:\Users\Granato\IdeaProjects\EtherDrops\src\main\java\com\granatode\etherDrops\item\DogFeedItem.java:39: error: cannot find symbol wolf.setInterested(true); ^ symbol: method setInterested(boolean) location: variable wolf of type Wolf
The method is setBegging(boolean) not setInterested(boolean) in 1.21. Let me verify ate() exists too.
Let me check the correct vanilla method name in 1.21.
[Generation stopped]
C:\Users\Granato\IdeaProjects\EtherDrops\src\main\java\com\granatode\etherDrops\item\DogFeedItem.java:39: error: cannot find symbol wolf.setInterested(true); ^ symbol: method setInterested(boolean) location: variable wolf of type Wolf
Это неофордж 1.21.1
В 1.21 метод называется setBegging(boolean), а не setInterested. Добавим ate() для анимации еды (тряска головы + звук).
Файл выглядит хорошо. setBegging(true) заставляет волка поворачивать голову. Также добавим звук еды — wolf.ate() не совсем то (ставит в love mode для размножения). Лучше явно проиграть звук
Готово. Исправления:
setBegging(true)— правильный метод для 1.21 (вместоsetInterested). Волк поворачивает голову к еде, как когда кормишь стейком.SoundEvents.WOLF_EAT— проигрывается звук еды (хруст), как при кормлении прирученного волка.Сброс
setBegging(false)через тик — чтобы волк не оставался в режиме “просит” навсегда.
package com.granatode.etherDrops;
import com.granatode.etherDrops.item.ModItems;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
@Mod(EtherDrops.MOD_ID)
public class EtherDrops {
public static final String MOD_ID = "etherdrops";
public EtherDrops(IEventBus modEventBus) {
ModItems.ITEMS.register(modEventBus);
}
}