<commit_before>package mcjty.aquamunda.blocks.cooker;

import mcjty.aquamunda.blocks.generic.GenericBlockWithTE;
import mcjty.aquamunda.fluid.FluidSetup;
import mcjty.aquamunda.items.ItemDish;
import mcjty.aquamunda.items.ModItems;
import mcjty.aquamunda.sound.ISoundProducer;
import mcjty.immcraft.api.handles.HandleSelector;
import mcjty.immcraft.api.handles.IInterfaceHandle;
import mcjty.lib.tools.ChatTools;
import mcjty.lib.tools.FluidTools;
import mcjty.lib.tools.ItemStackTools;
import mcjty.lib.tools.WorldTools;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.text.DecimalFormat;

public class CookerBlock extends GenericBlockWithTE<CookerTE> implements ISoundProducer {

    public static final PropertyEnum<EnumContents> CONTENTS = PropertyEnum.create("contents", EnumContents.class, EnumContents.values());
    public static final PropertyEnum<EnumLiquid> LIQUID = PropertyEnum.create("liquid", EnumLiquid.class, EnumLiquid.values());

    public static final AxisAlignedBB COOKER_AABB = new AxisAlignedBB(0.05D, 0.0D, 0.05D, 0.95D, 0.62D, 0.95D);

    public CookerBlock() {
        super(Material.IRON, "cooker", CookerTE.class);
        setHardness(2.0f);
        setSoundType(SoundType.METAL);
        setHarvestLevel("pickaxe", 0);
        addSelector(new HandleSelector("slot", new AxisAlignedBB(.33, .4, .33, .66, 1, .66)));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void initModel() {
        super.initModel();
        ClientRegistry.bindTileEntitySpecialRenderer(CookerTE.class, new CookerTESR());
    }


    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return COOKER_AABB;
    }

    @Override
    public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
        super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
        TileEntity te = world.getTileEntity(data.getPos());
        if (te instanceof CookerTE) {
            CookerTE cookerTE = (CookerTE) te;

            IInterfaceHandle selectedHandle = cookerTE.getHandle(player);
            if (selectedHandle != null) {
                ItemStack currentStack = selectedHandle.getCurrentStack(te);
                if (ItemStackTools.isValid(currentStack)) {
                    probeInfo.text(TextFormatting.GREEN + currentStack.getDisplayName() + " (" + ItemStackTools.getStackSize(currentStack) + ")");
                }
            }
            DecimalFormat decimalFormat = new DecimalFormat("#.#");

            probeInfo.text(TextFormatting.GREEN + "Filled: " + cookerTE.getFilledPercentage() + "%");
            probeInfo.text(TextFormatting.GREEN + "Temperature: " + decimalFormat.format(cookerTE.getTemperature()));
            int cookTime = cookerTE.getCookTime();
            int maxCookTime = cookerTE.getMaxCookTime();
            if (cookTime >= 0) {
                probeInfo.progress(cookTime, maxCookTime);
            }
        }
    }

    @Override
    protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
        if (!world.isRemote) {
            CookerTE cookerTE = getTE(world, pos);

            ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);

            if (!cookerTE.getSoup().isEmpty()) {
                if (ItemStackTools.isValid(heldItem) && heldItem.getItem() == Items.BOWL) {
                    heldItem.splitStack(1);
                    ItemStack dish = new ItemStack(ModItems.dish, 1, ItemDish.getDishMeta(cookerTE.getSoup()));
                    if (ItemStackTools.isEmpty(player.getHeldItem(EnumHand.MAIN_HAND))) {
                        player.setHeldItem(EnumHand.MAIN_HAND, dish);
                    } else {
                        // @todo generalize
                        if (!player.inventory.addItemStackToInventory(dish)) {
                            EntityItem entityItem = new EntityItem(player.getEntityWorld(), player.posX, player.posY, player.posZ, dish);
                            WorldTools.spawnEntity(player.getEntityWorld(), entityItem);
                        }
                    }
                    cookerTE.setSoup("");
                    cookerTE.setAmount(0);
                    player.openContainer.detectAndSendChanges();
                } else {
                    ChatTools.addChatMessage(player, new TextComponentString(TextFormatting.YELLOW + "You need a bowl to get the soup out"));
                }
                return true;
            }

            if (ItemStackTools.isValid(heldItem)) {
                if (FluidTools.isEmptyContainer(heldItem)) {
                    ItemStack container = heldItem.splitStack(1);
                    extractIntoContainer(player, container, cookerTE);
                    return true;<commit_msg>Fixed bucket being consumed too much when trying to extract from a cooker<commit_after>package mcjty.aquamunda.blocks.cooker;

import mcjty.aquamunda.blocks.generic.GenericBlockWithTE;
import mcjty.aquamunda.fluid.FluidSetup;
import mcjty.aquamunda.items.ItemDish;
import mcjty.aquamunda.items.ModItems;
import mcjty.aquamunda.sound.ISoundProducer;
import mcjty.immcraft.api.handles.HandleSelector;
import mcjty.immcraft.api.handles.IInterfaceHandle;
import mcjty.lib.tools.ChatTools;
import mcjty.lib.tools.FluidTools;
import mcjty.lib.tools.ItemStackTools;
import mcjty.lib.tools.WorldTools;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.text.DecimalFormat;

public class CookerBlock extends GenericBlockWithTE<CookerTE> implements ISoundProducer {

    public static final PropertyEnum<EnumContents> CONTENTS = PropertyEnum.create("contents", EnumContents.class, EnumContents.values());
    public static final PropertyEnum<EnumLiquid> LIQUID = PropertyEnum.create("liquid", EnumLiquid.class, EnumLiquid.values());

    public static final AxisAlignedBB COOKER_AABB = new AxisAlignedBB(0.05D, 0.0D, 0.05D, 0.95D, 0.62D, 0.95D);

    public CookerBlock() {
        super(Material.IRON, "cooker", CookerTE.class);
        setHardness(2.0f);
        setSoundType(SoundType.METAL);
        setHarvestLevel("pickaxe", 0);
        addSelector(new HandleSelector("slot", new AxisAlignedBB(.33, .4, .33, .66, 1, .66)));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void initModel() {
        super.initModel();
        ClientRegistry.bindTileEntitySpecialRenderer(CookerTE.class, new CookerTESR());
    }


    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return COOKER_AABB;
    }

    @Override
    public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
        super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
        TileEntity te = world.getTileEntity(data.getPos());
        if (te instanceof CookerTE) {
            CookerTE cookerTE = (CookerTE) te;

            IInterfaceHandle selectedHandle = cookerTE.getHandle(player);
            if (selectedHandle != null) {
                ItemStack currentStack = selectedHandle.getCurrentStack(te);
                if (ItemStackTools.isValid(currentStack)) {
                    probeInfo.text(TextFormatting.GREEN + currentStack.getDisplayName() + " (" + ItemStackTools.getStackSize(currentStack) + ")");
                }
            }
            DecimalFormat decimalFormat = new DecimalFormat("#.#");

            probeInfo.text(TextFormatting.GREEN + "Filled: " + cookerTE.getFilledPercentage() + "%");
            probeInfo.text(TextFormatting.GREEN + "Temperature: " + decimalFormat.format(cookerTE.getTemperature()));
            int cookTime = cookerTE.getCookTime();
            int maxCookTime = cookerTE.getMaxCookTime();
            if (cookTime >= 0) {
                probeInfo.progress(cookTime, maxCookTime);
            }
        }
    }

    @Override
    protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
        if (!world.isRemote) {
            CookerTE cookerTE = getTE(world, pos);

            ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);

            if (!cookerTE.getSoup().isEmpty()) {
                if (ItemStackTools.isValid(heldItem) && heldItem.getItem() == Items.BOWL) {
                    heldItem.splitStack(1);
                    ItemStack dish = new ItemStack(ModItems.dish, 1, ItemDish.getDishMeta(cookerTE.getSoup()));
                    if (ItemStackTools.isEmpty(player.getHeldItem(EnumHand.MAIN_HAND))) {
                        player.setHeldItem(EnumHand.MAIN_HAND, dish);
                    } else {
                        // @todo generalize
                        if (!player.inventory.addItemStackToInventory(dish)) {
                            EntityItem entityItem = new EntityItem(player.getEntityWorld(), player.posX, player.posY, player.posZ, dish);
                            WorldTools.spawnEntity(player.getEntityWorld(), entityItem);
                        }
                    }
                    cookerTE.setSoup("");
                    cookerTE.setAmount(0);
                    player.openContainer.detectAndSendChanges();
                } else {
                    ChatTools.addChatMessage(player, new TextComponentString(TextFormatting.YELLOW + "You need a bowl to get the soup out"));
                }
                return true;
            }

            if (ItemStackTools.isValid(heldItem)) {
                if (FluidTools.isEmptyContainer(heldItem)) {
                    ItemStack container = heldItem.copy().splitStack(1);    // Don't modify what the player is holding
                    extractIntoContainer(player, container, cookerTE);
                    return true;
{'fraction_non_alphanumeric': 0.10157473823068679, 'fraction_numerical': 0.005771291944925386, 'mean_word_length': 2.9447154471544716, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010449', 'n_tokens_mistral': 3649, 'n_tokens_neox': 3495, 'n_words': 634}