public static NotePlayEvent callNotePlayEvent( World world, int x, int y, int z, byte instrument, byte note) { NotePlayEvent event = new NotePlayEvent( new BukkitBlock(new BukkitChunk(world.getChunkFromBlockCoords(x, z)), x, y, z), org.bukkit.Instrument.getByType(instrument), new org.bukkit.Note(note)); Bukkit.getServer().getPluginManager().callEvent(event); return event; }
/** * Drawbacks: - The instrument doesn't work - forge sets it itself on function run. * * @throws IllegalArgumentException - if the instrument is invalid */ public boolean play(Instrument instrument, Note note) throws IllegalArgumentException { Block block = getBlock(); synchronized (block) { if (block.getType() == Material.NOTE_BLOCK) { // BlockNote nb = (BlockNote) block; TileEntityNote t = (TileEntityNote) ((BukkitWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ()); byte oldNote = t.note; t.note = note.getId(); net.minecraft.src.Block targ; switch (instrument.getType()) { case 1: targ = net.minecraft.src.Block.stone; break; case 2: targ = net.minecraft.src.Block.sand; break; case 4: targ = net.minecraft.src.Block.wood; break; case 3: targ = net.minecraft.src.Block.glass; break; default: throw new IllegalArgumentException("Invalid instrument: " + instrument.getType()); } ((BukkitWorld) block.getWorld()) .getHandle() .setBlock(getX(), getY() - 1, getZ(), targ.blockID); t.triggerNote(((BukkitWorld) block.getWorld()).getHandle(), getX(), getY(), getZ()); t.note = oldNote; // world.getHandle().playNote(getX(), getY(), getZ(), block.getTypeId(), // instrument.getType(), note.getId()); return true; } else { return false; } } }
// FIXME public boolean play(byte instrument, byte note) { Block block = getBlock(); synchronized (block) { if (block.getType() == Material.NOTE_BLOCK) { this.play(Instrument.getByType(instrument), Note.natural(0, Note.Tone.getById(note))); return true; } else { return false; } } }
public void playNote(Location loc, Instrument instrument, Note note) { if (getHandle().playerNetServerHandler == null) return; int id = getHandle().worldObj.getBlockId(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); getHandle() .playerNetServerHandler .sendPacketToPlayer( new Packet54PlayNoteBlock( loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), id, instrument.getType(), note.getId())); }
public void playNote(Location loc, Instrument instrument, Note note) { if (getHandle().field_71135_a == null) return; int id = getHandle().field_70170_p.func_72798_a(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); getHandle() .field_71135_a .func_72567_b( new net.minecraft.network.packet.Packet54PlayNoteBlock( loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), id, instrument.getType(), note.getId())); }
/** * Set the instrument type. * * @param value - new instrument type. */ @SuppressWarnings("deprecation") public void setInstrument(Instrument value) { setByte1(value.getType()); }
/** * Get the instrument type. * * @return Instrument type. */ @SuppressWarnings("deprecation") public Instrument getInstrument() { return Instrument.getByType(getByte1()); }
@Override public boolean play(Instrument instrument, Note note) { return play(instrument.getType(), note.getId()); }