@Override
  public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
    super.onNeighborBlockChange(world, x, y, z, blockId);
    if (updateEveryone) {
      TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);
      if (tile != null) {
        int maX = tile.size, maY = tile.size, maZ = tile.size;
        int startX = 0, startY = 0, startZ = 0;
        for (int side = 0; side < 6; side++) {
          switch (side) {
            case 0:
              maY = 1;
              break;

            case 1:
              startY = maY - 1;
              break;

            case 2:
              maZ = 1;
              break;

            case 3:
              startZ = maZ - 1;
              break;

            case 4:
              maX = 1;
              break;

            case 5:
              startX = maX - 1;
              break;
          }

          for (int xx = startX; xx < maX; xx++) {
            for (int yy = startY; yy < maY; yy++) {
              for (int zz = startZ; zz < maZ; zz++) {
                if (tile.getBlock(xx, yy, zz) != Blocks.air) {
                  Block littleBlock = tile.getBlock(xx, yy, zz);
                  if (littleBlock != null) {
                    littleBlock.onNeighborBlockChange(
                        (World) tile.getLittleWorld(),
                        (x << 3) + xx,
                        (y << 3) + yy,
                        (z << 3) + zz,
                        blockId);
                  }
                }
              }
            }
          }
        }
      } else {
        super.onNeighborBlockChange(world, x, y, z, blockId);
      }
    }
  }
 @Override
 public int getLightValue(IBlockAccess world, int x, int y, int z) {
   TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);
   try {
     if (tile != null) return tile.getLightlevel();
   } catch (ClassCastException e) {
     FMLCommonHandler.instance().getFMLLogger().warn(e.getLocalizedMessage());
     return super.getLightValue(world, x, y, z);
   }
   return super.getLightValue(world, x, y, z);
 }
  @Override
  public int isProvidingWeakPower(IBlockAccess iblockaccess, int x, int y, int z, int side) {
    int weakPower = super.isProvidingWeakPower(iblockaccess, x, y, z, side);
    if (weakPower > 0) {
      return weakPower;
    } else {
      TileEntityLittleChunk tile = (TileEntityLittleChunk) iblockaccess.getTileEntity(x, y, z);
      if (tile != null) {
        int maX = tile.size, maY = tile.size, maZ = tile.size;
        int startX = 0, startY = 0, startZ = 0;

        switch (side) {
          case 1:
            maY = 1;
            break;

          case 0:
            startY = maY - 1;
            break;

          case 3:
            maZ = 1;
            break;

          case 2:
            startZ = maZ - 1;
            break;

          case 5:
            maX = 1;
            break;

          case 4:
            startX = maX - 1;
            break;
        }

        for (int xx = startX; xx < maX; xx++) {
          for (int yy = startY; yy < maY; yy++) {
            for (int zz = startZ; zz < maZ; zz++) {
              if (tile.getBlock(xx, yy, zz) != Blocks.air) {
                Block littleBlock = tile.getBlock(xx, yy, zz);
                if (littleBlock != null) {
                  return littleBlock.isProvidingWeakPower(
                      tile.getLittleWorld(), (x << 3) + xx, (y << 3) + yy, (z << 3) + zz, side);
                }
              }
            }
          }
        }
      }
      return 0;
    }
  }
 @Override
 public Item getItem(World world, int x, int y, int z) {
   TileEntity tileentity = world.getTileEntity(x, y, z);
   if (tileentity != null && tileentity instanceof TileEntityLittleChunk) {
     TileEntityLittleChunk tilelb = (TileEntityLittleChunk) tileentity;
     Block pickedBlock = tilelb.getBlock(xSelected, ySelected, zSelected);
     if (pickedBlock != Blocks.air) {
       return Item.getItemFromBlock(pickedBlock);
     }
   }
   return ConfigurationLib.littleBlocksWand;
 }
  @SuppressWarnings("rawtypes")
  @Override
  public void addCollisionBoxesToList(
      World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List list, Entity entity) {
    TileEntity tileentity = world.getTileEntity(x, y, z);
    if (tileentity != null && tileentity instanceof TileEntityLittleChunk) {
      TileEntityLittleChunk tile = (TileEntityLittleChunk) tileentity;

      float m = ConfigurationLib.littleBlocksSize;

      AxisAlignedBB bb =
          AxisAlignedBB.getBoundingBox(
              axisalignedbb.minX * m,
              axisalignedbb.minY * m,
              axisalignedbb.minZ * m,
              axisalignedbb.maxX * m,
              axisalignedbb.maxY * m,
              axisalignedbb.maxZ * m);
      List<AxisAlignedBB> bbs = new ArrayList<AxisAlignedBB>();
      for (int xx = 0; xx < tile.size; xx++) {
        for (int yy = 0; yy < tile.size; yy++) {
          for (int zz = 0; zz < tile.size; zz++) {
            if (tile.getBlock(xx, yy, zz) != Blocks.air) {
              Block block = tile.getBlock(xx, yy, zz);
              if (block != null) {
                block.addCollisionBoxesToList(
                    (World) tile.getLittleWorld(),
                    (x << 3) + xx,
                    (y << 3) + yy,
                    (z << 3) + zz,
                    bb,
                    bbs,
                    entity);
              }
            }
          }
        }
      }
      for (AxisAlignedBB aabb : bbs) {
        aabb.setBounds(
            aabb.minX / m,
            aabb.minY / m,
            aabb.minZ / m,
            aabb.maxX / m,
            aabb.maxY / m,
            aabb.maxZ / m);
        list.add(aabb);
      }
    }
  }
 @Override
 public int getDamageValue(World world, int x, int y, int z) {
   TileEntity tileentity = world.getTileEntity(x, y, z);
   if (tileentity != null && tileentity instanceof TileEntityLittleChunk) {
     TileEntityLittleChunk tilelb = (TileEntityLittleChunk) tileentity;
     Block picked = tilelb.getBlock(xSelected, ySelected, zSelected);
     if (picked != null && picked != Blocks.air) {
       int xx = (x << 3) + xSelected;
       int yy = (y << 3) + ySelected;
       int zz = (z << 3) + zSelected;
       return picked.getDamageValue((World) tilelb.getLittleWorld(), xx, yy, zz);
     }
   }
   return 0;
 }
 public boolean rotateLittleChunk(World world, int x, int y, int z, ForgeDirection axis) {
   TileEntity tileentity = world.getTileEntity(x, y, z);
   if (tileentity != null && tileentity instanceof TileEntityLittleChunk) {
     ((TileEntityLittleChunk) tileentity).rotateContents(axis);
     tileentity.markDirty();
     world.markBlockForUpdate(x, y, z);
   }
   return false;
 }
 private void setBlockBoundsBasedOnSelection(World world, int x, int y, int z) {
   float m = ConfigurationLib.littleBlocksSize;
   if (xSelected == -10) {
     this.setBlockBounds(0f, 0f, 0f, 0f, 0f, 0f);
   } else {
     TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);
     Block block = tile.getBlock(xSelected, ySelected, zSelected);
     // System.out.println("Content: " + content);
     if (block == null) {
       this.setBlockBounds(
           xSelected / m,
           ySelected / m,
           zSelected / m,
           (xSelected + 1) / m,
           (ySelected + 1) / m,
           (zSelected + 1) / m);
     } else {
       if (block != null) {
         if (BlockStairs.func_150148_a /* isBlockStairsID */(block)) {
           block.setBlockBounds(0, 0, 0, 1, 1, 1);
         } else {
           block.setBlockBoundsBasedOnState(
               tile.getLittleWorld(),
               (x << 3) + xSelected,
               (y << 3) + ySelected,
               (z << 3) + zSelected);
         }
         this.setBlockBounds(
             (float) (xSelected + block.getBlockBoundsMinX()) / m,
             (float) (ySelected + block.getBlockBoundsMinY()) / m,
             (float) (zSelected + block.getBlockBoundsMinZ()) / m,
             (float) (xSelected + block.getBlockBoundsMaxX()) / m,
             (float) (ySelected + block.getBlockBoundsMaxY()) / m,
             (float) (zSelected + block.getBlockBoundsMaxZ()) / m);
       }
     }
   }
 }
  @Override
  public boolean removedByPlayer(World world, EntityPlayer entityplayer, int x, int y, int z) {
    Block id = world.getBlock(x, y, z);

    if (id == ConfigurationLib.littleChunk) {
      TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);
      EntityItemLittleBlocksCollection collection =
          new EntityItemLittleBlocksCollection(
              world, x, y, z, new ItemStack(ConfigurationLib.littleChunk));
      if (!tile.isEmpty()) {
        if (FMLCommonHandler.instance().getSide() == Side.CLIENT
            && FMLClientHandler.instance().getClient().playerController.isInCreativeMode()) {
          this.onBlockClicked(world, x, y, z, entityplayer);
          return false;
        } else if (entityplayer.capabilities.isCreativeMode) {
          this.onBlockClicked(world, x, y, z, entityplayer);
          return false;
        } else {
          if (collection != null) {
            for (int x1 = 0; x1 < tile.size; x1++) {
              for (int y1 = 0; y1 < tile.size; y1++) {
                for (int z1 = 0; z1 < tile.size; z1++) {
                  Block blockId = tile.getBlock(x1, y1, z1);
                  int contentMeta = tile.getBlockMetadata(x1, y1, z1);
                  if (blockId != Blocks.air) {
                    ItemStack itemToDrop =
                        this.dropLittleBlockAsNormalBlock(world, x, y, z, blockId, contentMeta);
                    if (itemToDrop != null) {
                      collection.addItemToDrop(itemToDrop);
                    }
                  }
                }
              }
            }
            tile.clearContents();
            tile.markDirty();
            world.markBlockForUpdate(x, y, z);
          }
        }
      }
      if (!world.isRemote) {
        if (!collection.isEmpty()) {
          world.spawnEntityInWorld(collection);
          PacketLittleBlocksCollection packet = new PacketLittleBlocksCollection(collection);
          PacketHelper.broadcastPacket(packet);
        }
      }
    }
    return super.removedByPlayer(world, entityplayer, x, y, z);
  }
  @SideOnly(Side.CLIENT)
  @Override
  public MovingObjectPosition collisionRayTrace(
      World world, int x, int y, int z, Vec3 player, Vec3 view) {
    TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);

    if (tile == null) {
      return null;
    }

    List<MovingObjectPosition> returns = new ArrayList<MovingObjectPosition>();

    returns =
        CollisionRayTrace.rayTraceLittleBlocks(this, player, view, x, y, z, returns, tile, isFluid);
    player = player.addVector(-x, -y, -z);
    view = view.addVector(-x, -y, -z);

    returns = CollisionRayTrace.collisionRayTracer(this, world, player, view, x, y, z, returns);
    if (!returns.isEmpty()) {
      MovingObjectPosition min = null;
      double distMin = 0;
      boolean isLiquid = false;
      for (MovingObjectPosition ret : returns) {
        double dist = (double) ret.hitVec.squareDistanceTo(player);

        Block retBlock = tile.getBlock(ret.blockX, ret.blockY, ret.blockZ);
        if (retBlock != Blocks.air) {
          isLiquid = retBlock instanceof IFluidBlock;
          if (isLiquid && isFluid) {
            isLiquid =
                !(retBlock instanceof BlockStaticLiquid
                    && tile.getBlockMetadata(ret.blockX, ret.blockY, ret.blockZ) == 0);
          }
        }

        if ((min == null || dist < distMin) && !isLiquid) {
          distMin = dist;
          min = ret;
        }
      }
      Block littleBlock = tile.getBlock(xSelected, ySelected, zSelected);

      if (min != null) {
        side = (byte) min.sideHit;
        xSelected = (int) min.blockX;
        ySelected = (int) min.blockY;
        zSelected = (int) min.blockZ;
        if (isFluid) {
          littleBlock = tile.getBlock(xSelected, ySelected, zSelected);
        }
        boolean rayTraced = false;
        if (littleBlock != Blocks.air) {
          if (littleBlock != null) {
            if (!(littleBlock.hasTileEntity(tile.getBlockMetadata(xSelected, ySelected, zSelected))
                && tile.getChunkTileEntity(xSelected, ySelected, zSelected) == null)) {

              try {
                littleBlock.collisionRayTrace(
                    (World) tile.getLittleWorld(),
                    (x << 3) + xSelected,
                    (y << 3) + ySelected,
                    (z << 3) + zSelected,
                    player,
                    view);
              } catch (ClassCastException e) {
                FMLCommonHandler.instance().getFMLLogger().warn(e.getLocalizedMessage());
              }
            }
          }
        }
        this.setBlockBoundsBasedOnSelection(world, x, y, z);
        return new MovingObjectPosition(
            x,
            y,
            z,
            (byte) min.sideHit,
            /** ((Vec3) min.hitVec).addVector(x, y, z) * */
            hitVec =
                Vec3.createVectorHelper(
                        (min.hitVec.xCoord * 8) % 1,
                        (min.hitVec.yCoord * 8) % 1,
                        (min.hitVec.zCoord * 8) % 1)
                    .addVector(x, y, z));
      }
    }
    xSelected = -10;
    ySelected = -10;
    zSelected = -10;
    side = -1;
    hitVec = null;
    this.setBlockBoundsBasedOnSelection(world, x, y, z);

    return null;
  }