package ovh.sad.animalrp.mixin; import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.component.type.FoodComponent; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.world.World; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.animals.Bee; @Mixin(value = Item.class) public class FoodEating { @Inject(method = "finishUsing", at = @At("HEAD")) public void finishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cfr) { if(world.isClient()) return; if (user.getType().equals(EntityType.PLAYER)) { ServerPlayerEntity player = (ServerPlayerEntity) user; Animal animal = AnimalRP.users.get(player.getUuid()); if (animal != null) { if (animal.name == "bee") { ((Bee) animal).onEat(player, stack); } if (animal.superfoods.contains(stack.getItem())) { player.getHungerManager().add(4, 9.4f); StatusEffectInstance effect = player.getStatusEffect(StatusEffects.SPEED); int duration = 20 * 4; if (effect != null) { duration += effect.getDuration(); } player.addStatusEffect( new StatusEffectInstance(StatusEffects.SPEED, duration, 1, true, true, true)); } } } } }