package game.block; import game.entity.npc.EntityNPC; import game.init.SoundEvent; import game.item.CheatTab; import game.material.Material; import game.renderer.particle.ParticleType; import game.tileentity.TileEntity; import game.tileentity.TileEntityNote; import game.world.BlockPos; import game.world.Facing; import game.world.State; import game.world.World; public class BlockNote extends BlockContainer { // private static final List INSTRUMENTS = Lists.newArrayList("harp", "bd", "snare", "hat", "bassattack"); public BlockNote() { super(Material.wood); this.setTab(CheatTab.tabTech); } /** * Called when a neighboring block changes. */ public void onNeighborBlockChange(World worldIn, BlockPos pos, State state, Block neighborBlock) { boolean flag = worldIn.isBlockPowered(pos); TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityNote) { TileEntityNote tileentitynote = (TileEntityNote)tileentity; if (tileentitynote.previousRedstoneState != flag) { if (flag) { tileentitynote.triggerNote(worldIn, pos); } tileentitynote.previousRedstoneState = flag; } } } public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { if (worldIn.client) { return true; } else { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityNote) { TileEntityNote tileentitynote = (TileEntityNote)tileentity; tileentitynote.changePitch(); tileentitynote.triggerNote(worldIn, pos); // playerIn.triggerAchievement(StatRegistry.noteblockTuneStat); } return true; } } public void onBlockClicked(World worldIn, BlockPos pos, EntityNPC playerIn) { if (!worldIn.client) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityNote) { ((TileEntityNote)tileentity).triggerNote(worldIn, pos); // playerIn.triggerAchievement(StatRegistry.noteblockPlayStat); } } } /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityNote(); } // private String getInstrument(int id) // { // if (id < 0 || id >= INSTRUMENTS.size()) // { // id = 0; // } // // return (String)INSTRUMENTS.get(id); // } /** * Called on both Client and Server when World#addBlockEvent is called */ public boolean onBlockEventReceived(World worldIn, BlockPos pos, State state, int eventID, int eventParam) { float f = (float)Math.pow(2.0D, (double)(eventParam - 12) / 12.0D); 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; } /** * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render */ public int getRenderType() { return 3; } public boolean isMagnetic() { return true; } }