package openblocks.common.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import openmods.infobook.BookDocumentation;
import openmods.utils.BlockNotifyFlags;
import openmods.utils.render.RenderUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@BookDocumentation(customName = "sky.normal")
public class BlockSky extends OpenBlock {

	public BlockSky() {
		super(Material.iron);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister registry) {
		blockIcon = registry.registerIcon("openblocks:sky_inactive");
	}

	@Override
	public int damageDropped(int meta) {
		return meta;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public int getBlockColor() {
		// randomness more or less intended
		return RenderUtils.getFogColor().getColor();
	}

	@Override
	public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
		if (!world.isRemote) {
			int meta = world.getBlockMetadata(x, y, z);
			int isPowered = world.isBlockIndirectlyGettingPowered(x, y, z)? 2 : 0;
			int isInverted = meta & 1;
			world.setBlockMetadataWithNotify(x, y, z, isPowered | isInverted, BlockNotifyFlags.ALL);
		}
	}

	public static boolean isActive(int meta) {
		boolean isPowered = (meta & 2) != 0;
		boolean isInverted = (meta & 1) != 0;
		return isPowered ^ isInverted;
	}

	@Override
	public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
		int meta = world.getBlockMetadata(x, y, z);
		return isActive(meta)? AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0) : super.getSelectedBoundingBoxFromPool(world, x, y, z);
	}

}

@@ -27,16 +27,42 @@
 block;%0A%0A
+import java.util.Random;%0A%0A
 import n
@@ -1117,24 +1117,114 @@
 e) %7B%0A%09%09%09
-int meta
+final int isPowered = world.isBlockIndirectlyGettingPowered(x, y, z)? 2 : 0;%0A%09%09%09final int isActive
  = world
@@ -1249,21 +1249,200 @@
 x, y, z)
+ & 2
 ;%0A
+%0A
 %09%09%09
+if (isPowered != isActive) world.scheduleBlockUpdate(x, y, z, this, 1);%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void updateTick(World world, int x, int y, int z, Random random) %7B%0A%09%09final 
 int isPo
@@ -1506,17 +1506,22 @@
  : 0;%0A%09%09
-%09
+final 
 int isIn
@@ -1533,19 +1533,46 @@
 d = 
-meta
+world.getBlockMetadata(x, y, z)
  & 1;%0A
-%09
+%0A
 %09%09wo
@@ -1658,20 +1658,16 @@
 s.ALL);%0A
-%09%09%7D%0A
 %09%7D%0A%0A%09pub

Fix #630