public static ChunkCoordinates[] getBlocksToPlace(ItemStack stack, EntityPlayer player) {
List<ChunkCoordinates> coords = new ArrayList();
MovingObjectPosition pos = ToolHandler.raytraceFromEntity(player.worldObj, player, true, 5);
if (pos != null) {
Block block = player.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ);
if (block != null && block.isReplaceable(player.worldObj, pos.blockX, pos.blockY, pos.blockZ))
pos.blockY--;
ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit);
int rotation = MathHelper.floor_double(player.rotationYaw * 4F / 360F + 0.5D) & 3;
int range = (getSize(stack) ^ 1) / 2;
boolean topOrBottom = dir == ForgeDirection.UP || dir == ForgeDirection.DOWN;
int xOff = !(dir == ForgeDirection.WEST || dir == ForgeDirection.EAST) ? topOrBottom ? player.rotationPitch > 75 || (rotation & 1) == 0 ? range : 0 : range : 0;
int yOff = topOrBottom ? player.rotationPitch > 75 ? 0 : range : range;
int zOff = !(dir == ForgeDirection.SOUTH || dir == ForgeDirection.NORTH) ? topOrBottom ? player.rotationPitch > 75 || (rotation & 1) == 1 ? range : 0 : range : 0;
for (int x = -xOff; x < xOff + 1; x++)
for (int y = 0; y < yOff * 2 + 1; y++) {
for (int z = -zOff; z < zOff + 1; z++) {
int xp = pos.blockX + x + dir.offsetX;
int yp = pos.blockY + y + dir.offsetY;
int zp = pos.blockZ + z + dir.offsetZ;
Block block1 = player.worldObj.getBlock(xp, yp, zp);
if (block1 == null || block1.isAir(player.worldObj, xp, yp, zp) || block1.isReplaceable(player.worldObj, xp, yp, zp))
coords.add(new ChunkCoordinates(xp, yp, zp));
}
}
}