Search in sources :

Example 1 with TileEntityToaster

use of com.mrcrayfish.furniture.tileentity.TileEntityToaster in project MrCrayfishFurnitureMod by MrCrayfish.

the class BlockToaster method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = playerIn.getHeldItem(hand);
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity instanceof TileEntityToaster) {
        TileEntityToaster tileEntityToaster = (TileEntityToaster) tileEntity;
        if (!heldItem.isEmpty() && !tileEntityToaster.isToasting()) {
            RecipeData data = RecipeAPI.getToasterRecipeFromInput(heldItem);
            if (data != null) {
                if (tileEntityToaster.addSlice(new ItemStack(heldItem.getItem(), 1))) {
                    TileEntityUtil.markBlockForUpdate(worldIn, pos);
                    heldItem.shrink(1);
                }
            } else {
                tileEntityToaster.removeSlice();
            }
        } else {
            if (playerIn.isSneaking()) {
                if (!tileEntityToaster.isToasting()) {
                    tileEntityToaster.startToasting();
                    worldIn.updateComparatorOutputLevel(pos, this);
                    if (!worldIn.isRemote) {
                        worldIn.playSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, FurnitureSounds.toaster_down, SoundCategory.BLOCKS, 0.75F, 1.0F, false);
                    }
                }
            } else if (!tileEntityToaster.isToasting()) {
                tileEntityToaster.removeSlice();
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityToaster(com.mrcrayfish.furniture.tileentity.TileEntityToaster) ItemStack(net.minecraft.item.ItemStack) RecipeData(com.mrcrayfish.furniture.api.RecipeData)

Aggregations

RecipeData (com.mrcrayfish.furniture.api.RecipeData)1 TileEntityToaster (com.mrcrayfish.furniture.tileentity.TileEntityToaster)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1