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;
}
Aggregations