Skip to content

Commit

Permalink
feat(mixin): LivingEatEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 17, 2022
1 parent 34d46fe commit d036de8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
@@ -0,0 +1,36 @@
package org.auioc.mcmod.arnicalib.mixin.common;

import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.common.event.CommonEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

@Mixin(value = FoodData.class)
public abstract class MixinFoodData {


/**
* @author WakelessSloth56
* @reason {@link org.auioc.mcmod.arnicalib.common.event.impl.LivingEatEvent}
*/
@Overwrite(remap = false)
public void eat(Item p_38713_, ItemStack p_38714_, @Nullable LivingEntity entity) {
var event = CommonEventFactory.onLivingEat(entity, ((FoodData) (Object) this), p_38714_);
if (!event.isCanceled()) {
int nutrition = event.getNutrition();
float saturationModifier = event.getSaturationModifier();
if (nutrition != 0 || saturationModifier != 0.0F) {
this.eat(nutrition, saturationModifier);
}
}
}

@Shadow
protected abstract void eat(int p_38708_, float p_38709_);

}
1 change: 1 addition & 0 deletions src/main/resources/arnicalib.mixin.json
Expand Up @@ -10,6 +10,7 @@
"common.MixinItemStack",
"common.MixinProjectile",
"common.MixinArrow",
"common.MixinFoodData",
"server.MixinServerLifecycleHooks",
"server.MixinLootContext",
"server.MixinPiglinAi",
Expand Down

0 comments on commit d036de8

Please sign in to comment.