use of net.minecraft.block.BlockCake in project Nutrition by WesCook.
the class EventEatFood method rightClickBlock.
// Detect eating cake
@SubscribeEvent
public void rightClickBlock(PlayerInteractEvent.RightClickBlock event) {
// Only run on server
EntityPlayer player = (EntityPlayer) event.getEntity();
if (player.getEntityWorld().isRemote)
return;
// Get info
World world = event.getWorld();
IBlockState blockState = world.getBlockState(event.getPos());
// Get out if not cake
if (!(blockState.getBlock() instanceof BlockCake)) {
return;
}
// Should we let them eat cake?
if (player.canEat(false) || Config.allowOverEating) {
// Calculate nutrition
// Get cake Item from registry name
Item item = Item.getByNameOrId(blockState.getBlock().getRegistryName().toString());
ItemStack itemStack = new ItemStack(item);
List<Nutrient> foundNutrients = NutrientUtils.getFoodNutrients(itemStack);
float nutritionValue = NutrientUtils.calculateNutrition(itemStack, foundNutrients);
// Add to each nutrient
player.getCapability(CapProvider.NUTRITION_CAPABILITY, null).add(foundNutrients, nutritionValue, true);
// If full but over-eating, simulate cake eating
if (!player.canEat(false) && Config.allowOverEating) {
int cakeBites = blockState.getValue(BlockCake.BITES);
if (cakeBites < 6)
world.setBlockState(event.getPos(), blockState.withProperty(BlockCake.BITES, cakeBites + 1), 3);
else
world.setBlockToAir(event.getPos());
}
}
}
use of net.minecraft.block.BlockCake in project FoodCraft-Reloaded by LasmGratel.
the class ItemVegetableJuice method onItemUse.
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.getBlockState(pos).getBlock() instanceof BlockCake) {
worldIn.setBlockState(pos, FoodCraftReloadedMod.getLoader(VegetableEnumLoader.class).get().getInstanceMap(BlockVegetableCake.class).get(vegetableType).getDefaultState().withProperty(BlockCake.BITES, worldIn.getBlockState(pos).getValue(BlockCake.BITES)));
player.getHeldItem(hand).splitStack(1);
player.addItemStackToInventory(new ItemStack(FCRItems.GLASS_BOTTLE));
return EnumActionResult.SUCCESS;
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
use of net.minecraft.block.BlockCake in project FoodCraft-Reloaded by LasmGratel.
the class ItemFruitJuice method onItemUse.
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.getBlockState(pos).getBlock() instanceof BlockCake) {
worldIn.setBlockState(pos, FoodCraftReloadedMod.getLoader(FruitEnumLoader.class).get().getInstanceMap(BlockFruitCake.class).get(fruitType).getDefaultState().withProperty(BlockCake.BITES, worldIn.getBlockState(pos).getValue(BlockCake.BITES)));
player.getHeldItem(hand).splitStack(1);
player.addItemStackToInventory(new ItemStack(FCRItems.GLASS_BOTTLE));
return EnumActionResult.SUCCESS;
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Aggregations