2011-01-23 08:36:26 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2011-01-23 08:36:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.blocks;
|
|
|
|
|
2011-03-10 07:10:59 +00:00
|
|
|
import com.sk89q.jnbt.*;
|
2011-01-23 08:36:26 +00:00
|
|
|
import com.sk89q.worldedit.data.*;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
|
|
|
/**
|
|
|
|
* Stores the pitch.
|
|
|
|
*/
|
|
|
|
private byte note;
|
|
|
|
|
|
|
|
/**
|
2011-01-23 10:03:49 +00:00
|
|
|
* Construct the note block.
|
|
|
|
*/
|
|
|
|
public NoteBlock() {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.NOTE_BLOCK);
|
2011-01-23 10:03:49 +00:00
|
|
|
this.note = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the note block.
|
2011-01-23 08:36:26 +00:00
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
public NoteBlock(int data) {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.NOTE_BLOCK, data);
|
2011-01-23 08:36:26 +00:00
|
|
|
this.note = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-23 10:03:49 +00:00
|
|
|
* Construct the note block.
|
2011-01-23 08:36:26 +00:00
|
|
|
*
|
2011-02-18 23:49:50 +00:00
|
|
|
* @param data
|
2011-01-23 08:36:26 +00:00
|
|
|
* @param note
|
|
|
|
*/
|
|
|
|
public NoteBlock(int data, byte note) {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.NOTE_BLOCK, data);
|
2011-01-23 08:36:26 +00:00
|
|
|
this.note = note;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the note
|
|
|
|
*/
|
|
|
|
public byte getNote() {
|
|
|
|
return note;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param note the note to set
|
|
|
|
*/
|
|
|
|
public void setNote(byte note) {
|
|
|
|
this.note = note;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the name of the title entity ID.
|
|
|
|
*
|
|
|
|
* @return title entity ID
|
|
|
|
*/
|
|
|
|
public String getTileEntityID() {
|
|
|
|
return "Music";
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-23 08:36:26 +00:00
|
|
|
/**
|
|
|
|
* Store additional tile entity data. Returns true if the data is used.
|
|
|
|
*
|
|
|
|
* @return map of values
|
|
|
|
* @throws DataException
|
|
|
|
*/
|
2011-11-23 01:29:48 +00:00
|
|
|
public Map<String, Tag> toTileEntityNBT()
|
2011-01-23 08:36:26 +00:00
|
|
|
throws DataException {
|
2011-11-23 01:29:48 +00:00
|
|
|
Map<String, Tag> values = new HashMap<String, Tag>();
|
2011-01-23 08:36:26 +00:00
|
|
|
values.put("note", new ByteTag("note", note));
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get additional information from the title entity data.
|
|
|
|
*
|
|
|
|
* @param values
|
|
|
|
* @throws DataException
|
|
|
|
*/
|
2011-11-23 01:29:48 +00:00
|
|
|
public void fromTileEntityNBT(Map<String, Tag> values)
|
|
|
|
throws DataException {
|
2011-01-23 08:36:26 +00:00
|
|
|
if (values == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-23 08:36:26 +00:00
|
|
|
Tag t;
|
|
|
|
|
|
|
|
t = values.get("id");
|
2011-11-23 01:29:48 +00:00
|
|
|
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Music")) {
|
2011-01-23 08:36:26 +00:00
|
|
|
throw new DataException("'Music' tile entity expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
t = values.get("note");
|
|
|
|
if (t instanceof ByteTag) {
|
2011-11-23 01:29:48 +00:00
|
|
|
note = ((ByteTag) t).getValue();
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|