<commit_before>package exnihilocreatio.util;

import exnihilocreatio.blocks.BlockInfestingLeaves;
import exnihilocreatio.texturing.Color;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.BiPredicate;

import static java.lang.Math.round;

public class Util {

    public static final Color whiteColor = new Color(1f, 1f, 1f, 1f);
    public static final Color blackColor = new Color(0f, 0f, 0f, 1f);
    public static final Color greenColor = new Color(0f, 1f, 0f, 1f);

    public static void dropItemInWorld(TileEntity source, EntityPlayer player, ItemStack stack, double speedFactor) {
        if (stack == null || stack.isEmpty())
            return;

        int hitOrientation = player == null ? 0 : MathHelper.floor(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
        double stackCoordX = 0.0D, stackCoordY = 0.0D, stackCoordZ = 0.0D;

        switch (hitOrientation) {
            case 0:
                stackCoordX = source.getPos().getX() + 0.5D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() - 0.25D;
                break;
            case 1:
                stackCoordX = source.getPos().getX() + 1.25D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 0.5D;
                break;
            case 2:
                stackCoordX = source.getPos().getX() + 0.5D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 1.25D;
                break;
            case 3:
                stackCoordX = source.getPos().getX() - 0.25D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 0.5D;
                break;
            default:
                break;
        }

        EntityItem droppedEntity = new EntityItem(source.getWorld(), stackCoordX, stackCoordY, stackCoordZ, stack);

        if (player != null) {
            Vec3d motion = new Vec3d(player.posX - stackCoordX, player.posY - stackCoordY, player.posZ - stackCoordZ);
            motion.normalize();
            droppedEntity.motionX = motion.x;
            droppedEntity.motionY = motion.y;
            droppedEntity.motionZ = motion.z;
            double offset = 0.25D;
            droppedEntity.move(MoverType.SELF, motion.x * offset, motion.y * offset, motion.z * offset);
        }

        droppedEntity.motionX *= speedFactor;
        droppedEntity.motionY *= speedFactor;
        droppedEntity.motionZ *= speedFactor;

        source.getWorld().spawnEntity(droppedEntity);
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromBlockState(@Nonnull IBlockState state) {
        return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromFluidStack(FluidStack stack) {
        if (stack != null && stack.getFluid() != null) {
            Fluid fluid = stack.getFluid();

            if (fluid.getStill(stack) != null) {
                return Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(fluid.getStill().toString());
            }
        }

        return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromFluid(@Nonnull Fluid fluid) {
        if (fluid.getStill() != null)
            return Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(fluid.getStill().toString());
        return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
    }

    public static boolean isSurroundingBlocksAtLeastOneOf(BlockInfo[] blocks, BlockPos pos, World world, int radius) {
        ArrayList<BlockInfo> blockList = new ArrayList<>(Arrays.asList(blocks));
        for (int xShift = -1 * radius; xShift <= radius; xShift++) {
            for (int zShift = -1 * radius; zShift <= radius; zShift++) {
                BlockPos checkPos = pos.add(xShift, 0, zShift);
                BlockInfo checkBlock = new BlockInfo(world.getBlockState(checkPos));
                if (blockList.contains(checkBlock))
                    return true;
            }<commit_msg>Issue #193<commit_after>package exnihilocreatio.util;

import exnihilocreatio.blocks.BlockInfestingLeaves;
import exnihilocreatio.texturing.Color;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.BiPredicate;

import static java.lang.Math.round;

public class Util {

    public static final Color whiteColor = new Color(1f, 1f, 1f, 1f);
    public static final Color blackColor = new Color(0f, 0f, 0f, 1f);
    public static final Color greenColor = new Color(0f, 1f, 0f, 1f);

    public static void dropItemInWorld(TileEntity source, EntityPlayer player, ItemStack stack, double speedFactor) {
        if (stack == null || stack.isEmpty())
            return;

        int hitOrientation = player == null ? 0 : MathHelper.floor(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
        double stackCoordX = 0.0D, stackCoordY = 0.0D, stackCoordZ = 0.0D;

        switch (hitOrientation) {
            case 0:
                stackCoordX = source.getPos().getX() + 0.5D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() - 0.25D;
                break;
            case 1:
                stackCoordX = source.getPos().getX() + 1.25D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 0.5D;
                break;
            case 2:
                stackCoordX = source.getPos().getX() + 0.5D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 1.25D;
                break;
            case 3:
                stackCoordX = source.getPos().getX() - 0.25D;
                stackCoordY = source.getPos().getY() + 0.5D + 1;
                stackCoordZ = source.getPos().getZ() + 0.5D;
                break;
            default:
                break;
        }

        EntityItem droppedEntity = new EntityItem(source.getWorld(), stackCoordX, stackCoordY, stackCoordZ, stack);

        if (player != null) {
            Vec3d motion = new Vec3d(player.posX - stackCoordX, player.posY - stackCoordY, player.posZ - stackCoordZ);
            motion.normalize();
            droppedEntity.motionX = motion.x;
            droppedEntity.motionY = motion.y;
            droppedEntity.motionZ = motion.z;
            double offset = 0.25D;
            droppedEntity.move(MoverType.SELF, motion.x * offset, motion.y * offset, motion.z * offset);
        }

        droppedEntity.motionX *= speedFactor;
        droppedEntity.motionY *= speedFactor;
        droppedEntity.motionZ *= speedFactor;

        source.getWorld().spawnEntity(droppedEntity);
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromBlockState(@Nonnull IBlockState state) {
        return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromFluidStack(FluidStack stack) {
        TextureAtlasSprite tex;
        if (stack != null && stack.getFluid() != null)
            return getTextureFromFluid(stack.getFluid());

        return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTextureFromFluid(@Nonnull Fluid fluid) {
        TextureAtlasSprite tex = null;
        // Try still
        if (fluid.getStill() != null)
            tex = getTexture(fluid.getStill());
        if(tex != null)
            return tex;
        // Try flowing
        if (fluid.getFlowing() != null)
            tex = getTexture(fluid.getFlowing());
        if(tex != null)
            return tex;
        // Give up
        return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
    }

    @SideOnly(Side.CLIENT)
    public static TextureAtlasSprite getTexture(ResourceLocation location) {
        return Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(location.toString());
    }

    public static boolean isSurroundingBlocksAtLeastOneOf(BlockInfo[] blocks, BlockPos pos, World world, int radius) {
        ArrayList<BlockInfo> blockList = new ArrayList<>(Arrays.asList(blocks));
        for (int xShift = -1 * radius; xShift <= radius; xShift++) {
            for (int zShift = -1 * radius; zShift <= radius; zShift++) {
                BlockPos checkPos = pos.add(xShift, 0, zShift);
                BlockInfo checkBlock = new BlockInfo(world.getBlockState(checkPos));
                if (blockList.contains(checkBlock))
                    return true;
            }
{'fraction_non_alphanumeric': 0.11129568106312292, 'fraction_numerical': 0.013750461424880029, 'mean_word_length': 2.6673434856175975, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '6531064', 'n_tokens_mistral': 3353, 'n_tokens_neox': 3218, 'n_words': 651}