Ejemplo n.º 1
0
  public boolean play() {
    Block block = getBlock();

    synchronized (block) {
      if (block.getType() == Material.NOTE_BLOCK) {
        note.triggerNote(world.getHandle(), getX(), getY(), getZ());
        return true;
      } else {
        return false;
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * 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;
      }
    }
  }