Search in sources :

Example 1 with BlockCake

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());
        }
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Nutrient(ca.wescook.nutrition.nutrients.Nutrient) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockCake(net.minecraft.block.BlockCake) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with BlockCake

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);
}
Also used : ItemStack(net.minecraft.item.ItemStack) BlockCake(net.minecraft.block.BlockCake) Nonnull(javax.annotation.Nonnull)

Example 3 with BlockCake

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);
}
Also used : ItemStack(net.minecraft.item.ItemStack) BlockCake(net.minecraft.block.BlockCake) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockCake (net.minecraft.block.BlockCake)3 ItemStack (net.minecraft.item.ItemStack)3 Nonnull (javax.annotation.Nonnull)2 Nutrient (ca.wescook.nutrition.nutrients.Nutrient)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1