Skip to content

Commit

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

import org.auioc.mcmod.arnicalib.common.event.impl.ItemInventoryTickEvent;
import org.auioc.mcmod.arnicalib.common.event.impl.LivingEatEvent;
import org.auioc.mcmod.arnicalib.common.event.impl.PistonCheckPushableEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -13,19 +16,25 @@

public final class CommonEventFactory {

private static final IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
private static final IEventBus BUS = MinecraftForge.EVENT_BUS;

@Deprecated(since = "3.1.1")
public static boolean postPistonAddBlockLineEvent(BlockState blockState, Level level, BlockPos blockPos, Direction direction) {
return forgeEventBus.post(new org.auioc.mcmod.arnicalib.common.event.impl.PistonAddBlockLineEvent(blockState, level, blockPos, direction));
return BUS.post(new org.auioc.mcmod.arnicalib.common.event.impl.PistonAddBlockLineEvent(blockState, level, blockPos, direction));
}

public static boolean firePistonCheckPushableEvent(BlockState blockState, Level level, BlockPos blockPos, Direction pushDirection, boolean p_60209_, Direction p_60210_) {
return forgeEventBus.post(new PistonCheckPushableEvent(blockState, level, blockPos, pushDirection, p_60209_, p_60210_));
return BUS.post(new PistonCheckPushableEvent(blockState, level, blockPos, pushDirection, p_60209_, p_60210_));
}

public static boolean onSelectedItemItemInventoryTick(Player player, Level level, ItemStack itemStack, int index) {
return forgeEventBus.post(new ItemInventoryTickEvent.Selected(player, level, itemStack, index));
return BUS.post(new ItemInventoryTickEvent.Selected(player, level, itemStack, index));
}

public static LivingEatEvent onLivingEat(LivingEntity living, FoodData foodData, ItemStack foodItemStack) {
var event = new LivingEatEvent(living, foodData, foodItemStack);
BUS.post(event);
return event;
}

}
@@ -0,0 +1,46 @@
package org.auioc.mcmod.arnicalib.common.event.impl;

import org.auioc.mcmod.arnicalib.api.game.event.FoodDataEvent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.eventbus.api.Cancelable;

@Cancelable
public class LivingEatEvent extends FoodDataEvent {

private final ItemStack foodItemStack;
private int nutrition = 0;
private float saturationModifier = 0.0F;

public LivingEatEvent(LivingEntity living, FoodData foodData, ItemStack foodItemStack) {
super(living, foodData);
this.foodItemStack = foodItemStack;
if (foodItemStack.isEdible()) {
var foodProperties = foodItemStack.getFoodProperties(living);
this.nutrition = foodProperties.getNutrition();
this.saturationModifier = foodProperties.getSaturationModifier();
}
}

public ItemStack getFoodItemStack() {
return this.foodItemStack;
}

public int getNutrition() {
return this.nutrition;
}

public float getSaturationModifier() {
return this.saturationModifier;
}

public void setNutrition(int nutrition) {
this.nutrition = nutrition;
}

public void setSaturationModifier(float saturationModifier) {
this.saturationModifier = saturationModifier;
}

}

0 comments on commit 34d46fe

Please sign in to comment.