package common.block.tech;

import common.block.Block;
import common.block.Material;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.init.SoundEvent;
import common.item.CheatTab;
import common.model.ParticleType;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;

public class BlockNote extends Block {
	public BlockNote() {
		super(Material.WOOD);
		this.setTab(CheatTab.TECHNOLOGY);
	}

	public void onNeighborBlockChange(World worldIn, BlockPos pos, State state, Block neighborBlock) {
		if(worldIn.isBlockPowered(pos))
			worldIn.addBlockEvent(pos, Blocks.noteblock, 0, 0);
	}

	public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) {
		if(!worldIn.client)
			worldIn.addBlockEvent(pos, Blocks.noteblock, 0, 0);
		return true;
	}

	public void onBlockClicked(World worldIn, BlockPos pos, EntityNPC playerIn) {
		if(!worldIn.client)
			worldIn.addBlockEvent(pos, Blocks.noteblock, 0, 0);
	}

	public boolean onBlockEventReceived(World worldIn, BlockPos pos, State state, int eventID, int eventParam) {
		worldIn.playSound(SoundEvent.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 3.0F);
		worldIn.spawnParticle(ParticleType.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.2D, (double)pos.getZ() + 0.5D,
				(double)eventParam / 24.0D, 0.0D, 0.0D);
		return true;
	}

	public boolean isMagnetic() {
		return true;
	}
}
