<commit_before>package tv.mapper.roadstuff.item;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import tv.mapper.roadstuff.block.BlockFourAxis;
import tv.mapper.roadstuff.block.BlockPaintable;
import tv.mapper.roadstuff.block.BlockTwoAxis;
import tv.mapper.roadstuff.init.ModBlocks;
import tv.mapper.roadstuff.state.properties.EnumPaintColor;

public class ItemBrush extends Item
{
    public static final int MAX_PAINT = 16;

    public ItemBrush(Properties properties)
    {
        super(properties);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
    {
        ItemStack stack = player.getHeldItem(hand);

        NBTTagCompound nbt = checkNBT(stack);
        stack.setTag(nbt);

        if(world.isRemote && player.isSneaking())
        {
            ItemBrushClient.displayBrushGui(stack.getTag().getInt("pattern"), stack.getTag().getInt("paint"), EnumPaintColor.getColorByID(stack.getTag().getInt("color")).getName());
        }

        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }

    public EnumActionResult onItemUse(ItemUseContext context)
    {
        World world = context.getWorld();
        BlockPos pos = context.getPos();
        EntityPlayer player = context.getPlayer();
        ItemStack stack = context.getItem();
        IBlockState state = world.getBlockState(pos);
        NBTTagCompound nbt = checkNBT(stack);

        int pattern = nbt.getInt("pattern");

        Block newBlock = null;
        boolean playSound = true;

        if(state != null && nbt.hasKey("paint"))
        {
            if(context.getFace() == EnumFacing.UP && state.getBlock() instanceof BlockPaintable)
            {
                switch(pattern)
                {
                    case 0:
                        newBlock = ModBlocks.ASPHALT_BLOCK;
                        break;
                    case 1:
                        newBlock = ModBlocks.ASPHALT_SIMPLE_WHITE_LINE_BLOCK;
                        break;
                    case 2:
                        newBlock = ModBlocks.ASPHALT_DOUBLE_WHITE_LINE_BLOCK;
                        break;
                    case 3:
                        newBlock = ModBlocks.ASPHALT_DASHED_WHITE_LINE_BLOCK;
                        break;
                    case 4:
                        newBlock = ModBlocks.ASPHALT_LARGE_WHITE_LINE_BLOCK;
                        break;
                    case 5:
                        newBlock = ModBlocks.ASPHALT_X_WHITE_LINE_BLOCK;
                        break;
                    case 6:
                        newBlock = ModBlocks.ASPHALT_T_WHITE_LINE_BLOCK;
                        break;
                    case 7:
                        newBlock = ModBlocks.ASPHALT_CORNER_WHITE_LINE_BLOCK;
                        break;
                    case 8:
                        newBlock = ModBlocks.ASPHALT_END_DOUBLE_WHITE_LINE_BLOCK;
                        break;
                    case 9:
                        newBlock = ModBlocks.ASPHALT_DIAGONAL_WHITE_LINE_BLOCK;
                        break;
                    case 10:
                        newBlock = ModBlocks.ASPHALT_LARGE_DIAGONAL_WHITE_LINE_BLOCK;
                        break;
                    default:
                        newBlock = ModBlocks.ASPHALT_BLOCK;
                        break;
                }

                if(pattern == 0)
                {
                    if(!world.isRemote)
                        world.setBlockState(pos, newBlock.getDefaultState());
                    playSound = false;
                }
                else if(state.getBlock() == newBlock)
                {

                    if(newBlock instanceof BlockTwoAxis && !world.isRemote)
                    {
                        if(state.get(BlockTwoAxis.ROTATION))
                            world.setBlockState(pos, newBlock.getDefaultState().with(BlockTwoAxis.ROTATION, Boolean.valueOf(false)));
                        else
                            world.setBlockState(pos, newBlock.getDefaultState().with(BlockTwoAxis.ROTATION, Boolean.valueOf(true)));
                    }
                    else if(newBlock instanceof BlockFourAxis && !world.isRemote)
                    {
                        switch(state.get(BlockFourAxis.DIRECTION))
                        {
                            case NORTH:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                break;
                            case EAST:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.SOUTH));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.NORTH));
                                break;
                            case SOUTH:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                break;
                            case WEST:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.NORTH));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.SOUTH));
                                break;
                            default:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                break;
                        }
                    }
                    else
                    {
                        playSound = false;
                    }
                }
                else
                {
                    if(nbt.getInt("paint") > 0 && !world.isRemote)
                    {
                        world.setBlockState(pos, newBlock.getDefaultState());
                        nbt.setInt("paint", nbt.getInt("paint") - 1);
                    }
                }

                if(!world.isRemote && nbt.getInt("paint") == 0)
                    nbt.setInt("color", 0);

                if(playSound && nbt.getInt("paint") > 0)
                    world.playSound(player, pos, SoundEvents.BLOCK_SLIME_BLOCK_FALL, SoundCategory.BLOCKS, .8F, 1.0F);
            }

            stack.setTag(nbt);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }

    @Override
    public void addInformation(ItemStack stack, World player, List<ITextComponent> list, ITooltipFlag flag)
    {
        super.addInformation(stack, player, list, flag);
        if(stack.hasTag())
        {
            list.add(new TextComponentString("Pattern: " + stack.getTag().getInt("pattern") + ", paint: " + stack.getTag().getInt("paint") + ", color: " + stack.getTag().getInt("color")));
        }
    }

    public static NBTTagCompound checkNBT(ItemStack stack)
    {
        NBTTagCompound nbt;

        if(stack.hasTag())
        {
            nbt = stack.getTag();
        }
        else
        {
            nbt = new NBTTagCompound();
            nbt.setInt("paint", 0);
            nbt.setInt("pattern", 0);
            nbt.setInt("color", EnumPaintColor.NONE.getId());
        }
        return nbt;
    }
}
<commit_msg>Fix last paint usage not producing sound<commit_after>package tv.mapper.roadstuff.item;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import tv.mapper.roadstuff.block.BlockFourAxis;
import tv.mapper.roadstuff.block.BlockPaintable;
import tv.mapper.roadstuff.block.BlockTwoAxis;
import tv.mapper.roadstuff.init.ModBlocks;
import tv.mapper.roadstuff.state.properties.EnumPaintColor;

public class ItemBrush extends Item
{
    public static final int MAX_PAINT = 16;

    public ItemBrush(Properties properties)
    {
        super(properties);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
    {
        ItemStack stack = player.getHeldItem(hand);

        NBTTagCompound nbt = checkNBT(stack);
        stack.setTag(nbt);

        if(world.isRemote && player.isSneaking())
        {
            ItemBrushClient.displayBrushGui(stack.getTag().getInt("pattern"), stack.getTag().getInt("paint"), EnumPaintColor.getColorByID(stack.getTag().getInt("color")).getName());
        }

        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }

    public EnumActionResult onItemUse(ItemUseContext context)
    {
        World world = context.getWorld();
        BlockPos pos = context.getPos();
        EntityPlayer player = context.getPlayer();
        ItemStack stack = context.getItem();
        IBlockState state = world.getBlockState(pos);
        NBTTagCompound nbt = checkNBT(stack);

        int pattern = nbt.getInt("pattern");

        Block newBlock = null;
        boolean playSound = false;

        if(state != null && nbt.hasKey("paint"))
        {
            if(context.getFace() == EnumFacing.UP && state.getBlock() instanceof BlockPaintable)
            {
                switch(pattern)
                {
                    case 0:
                        newBlock = ModBlocks.ASPHALT_BLOCK;
                        break;
                    case 1:
                        newBlock = ModBlocks.ASPHALT_SIMPLE_WHITE_LINE_BLOCK;
                        break;
                    case 2:
                        newBlock = ModBlocks.ASPHALT_DOUBLE_WHITE_LINE_BLOCK;
                        break;
                    case 3:
                        newBlock = ModBlocks.ASPHALT_DASHED_WHITE_LINE_BLOCK;
                        break;
                    case 4:
                        newBlock = ModBlocks.ASPHALT_LARGE_WHITE_LINE_BLOCK;
                        break;
                    case 5:
                        newBlock = ModBlocks.ASPHALT_X_WHITE_LINE_BLOCK;
                        break;
                    case 6:
                        newBlock = ModBlocks.ASPHALT_T_WHITE_LINE_BLOCK;
                        break;
                    case 7:
                        newBlock = ModBlocks.ASPHALT_CORNER_WHITE_LINE_BLOCK;
                        break;
                    case 8:
                        newBlock = ModBlocks.ASPHALT_END_DOUBLE_WHITE_LINE_BLOCK;
                        break;
                    case 9:
                        newBlock = ModBlocks.ASPHALT_DIAGONAL_WHITE_LINE_BLOCK;
                        break;
                    case 10:
                        newBlock = ModBlocks.ASPHALT_LARGE_DIAGONAL_WHITE_LINE_BLOCK;
                        break;
                    default:
                        newBlock = ModBlocks.ASPHALT_BLOCK;
                        break;
                }

                if(pattern == 0 && !world.isRemote)
                {
                    world.setBlockState(pos, newBlock.getDefaultState());
                }
                else if(state.getBlock() == newBlock)
                {
                    if(newBlock instanceof BlockTwoAxis && !world.isRemote)
                    {
                        if(state.get(BlockTwoAxis.ROTATION))
                            world.setBlockState(pos, newBlock.getDefaultState().with(BlockTwoAxis.ROTATION, Boolean.valueOf(false)));
                        else
                            world.setBlockState(pos, newBlock.getDefaultState().with(BlockTwoAxis.ROTATION, Boolean.valueOf(true)));
                    }
                    else if(newBlock instanceof BlockFourAxis && !world.isRemote)
                    {
                        switch(state.get(BlockFourAxis.DIRECTION))
                        {
                            case NORTH:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                break;
                            case EAST:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.SOUTH));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.NORTH));
                                break;
                            case SOUTH:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                break;
                            case WEST:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.NORTH));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.SOUTH));
                                break;
                            default:
                                if(player.getHeldItemMainhand() == stack)
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.EAST));
                                else
                                    world.setBlockState(pos, newBlock.getDefaultState().with(BlockFourAxis.DIRECTION, EnumFacing.WEST));
                                break;
                        }
                    }
                }
                else
                {
                    if(nbt.getInt("paint") > 0)
                    {
                        if(!world.isRemote)
                        {
                            world.setBlockState(pos, newBlock.getDefaultState());
                            nbt.setInt("paint", nbt.getInt("paint") - 1);
                        }
                        playSound = true;
                    }
                }

                if(!world.isRemote && nbt.getInt("paint") == 0)
                    nbt.setInt("color", 0);

                if(playSound)
                    world.playSound(player, pos, SoundEvents.BLOCK_SLIME_BLOCK_FALL, SoundCategory.BLOCKS, .8F, 1.0F);
            }

            stack.setTag(nbt);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }

    @Override
    public void addInformation(ItemStack stack, World player, List<ITextComponent> list, ITooltipFlag flag)
    {
        super.addInformation(stack, player, list, flag);
        if(stack.hasTag())
        {
            list.add(new TextComponentString("Pattern: " + stack.getTag().getInt("pattern") + ", paint: " + stack.getTag().getInt("paint") + ", color: " + stack.getTag().getInt("color")));
        }
    }

    public static NBTTagCompound checkNBT(ItemStack stack)
    {
        NBTTagCompound nbt;

        if(stack.hasTag())
        {
            nbt = stack.getTag();
        }
        else
        {
            nbt = new NBTTagCompound();
            nbt.setInt("paint", 0);
            nbt.setInt("pattern", 0);
            nbt.setInt("color", EnumPaintColor.NONE.getId());
        }
        return nbt;
    }
}

{'fraction_non_alphanumeric': 0.08926720139684619, 'fraction_numerical': 0.002673650897582801, 'mean_word_length': 1.421455938697318, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5212768', 'n_tokens_mistral': 4894, 'n_tokens_neox': 4634, 'n_words': 705}