Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34d46fe
commit d036de8
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/org/auioc/mcmod/arnicalib/mixin/common/MixinFoodData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters