Example #1
0
 @SuppressWarnings("deprecation")
 public static NotePitch of(Note note) {
   if (note == null) {
     return null;
   }
   return NOTES.get(note.getId());
 }
  // 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()));
  }
Example #4
0
  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()));
  }
  /**
   * 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;
      }
    }
  }
Example #6
0
 @Override
 public boolean play(Instrument instrument, Note note) {
   return play(instrument.getType(), note.getId());
 }
Example #7
0
 @Override
 public byte getRawNote() {
   return note.getId();
 }
Example #8
0
 public static double noteToPitch(Note note) {
   double semitones = note.getId() - BASE_NOTE;
   return Math.pow(2.0, semitones / 12.0);
 }
 public void setNote(Note n) {
   note.note = n.getId();
 }