package dangerzone.blocks;

import dangerzone.World;
import dangerzone.entities.EntityBlock;

public class BlockFalling extends Block {

	public BlockFalling(String n, String txt) {
		super(n, txt);
	}
	
	//One of your neighbors has changed. (YOU are at d, x, y, z)
	public void notifyNeighborChanged(World w, int d, int x, int y, int z){
		if(w.getblock(d, x, y, z) != 0){ //loop protection
			int bid = w.getblock(d, x, y-1, z);
			if(!Blocks.isSolid(bid)){
				int meta = w.getblockmeta(d, x, y, z);
				EntityBlock eb = (EntityBlock) w.createEntityByName("DangerZone:EntityBlock", d, 
						(double)x+0.5f+((w.rand.nextFloat()-w.rand.nextFloat())*0.01f), 
						(double)y,
						(double)z+0.5f+((w.rand.nextFloat()-w.rand.nextFloat())*0.01f));
				if(eb != null){
					eb.init();
					w.setblock(d, x, y, z, 0);
					eb.rotation_pitch = eb.rotation_yaw = eb.rotation_roll = 0;
					eb.rotation_pitch_motion = eb.rotation_yaw_motion = eb.rotation_roll_motion = 0;
					eb.setBID(blockID);
					eb.setIID(meta);
					w.spawnEntityInWorld(eb);
				}
			}
		}
	}
}
