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.*;
|
2012-03-30 04:11:49 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-01-23 08:36:26 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents furnaces.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2012-03-30 04:11:49 +00:00
|
|
|
public class FurnaceBlock extends ContainerBlock {
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-23 08:36:26 +00:00
|
|
|
/**
|
|
|
|
* Fuel time.
|
|
|
|
*/
|
|
|
|
private short burnTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cook time.
|
|
|
|
*/
|
|
|
|
private short cookTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the chest block.
|
2012-03-04 00:46:51 +00:00
|
|
|
*
|
|
|
|
* @param type
|
2011-01-23 08:36:26 +00:00
|
|
|
*/
|
|
|
|
public FurnaceBlock(int type) {
|
2012-03-30 04:11:49 +00:00
|
|
|
super(type, 2);
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the chest block.
|
|
|
|
*
|
2012-03-04 00:46:51 +00:00
|
|
|
* @param type
|
2011-01-23 08:36:26 +00:00
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
public FurnaceBlock(int type, int data) {
|
2012-03-30 04:11:49 +00:00
|
|
|
super(type, data, 2);
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the chest block.
|
|
|
|
*
|
2012-03-04 00:46:51 +00:00
|
|
|
* @param type
|
2011-01-23 08:36:26 +00:00
|
|
|
* @param data
|
|
|
|
* @param items
|
|
|
|
*/
|
|
|
|
public FurnaceBlock(int type, int data, BaseItemStack[] items) {
|
2012-03-30 04:11:49 +00:00
|
|
|
super(type, data, 2);
|
|
|
|
setItems(items);
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-23 08:36:26 +00:00
|
|
|
/**
|
|
|
|
* @return the burnTime
|
|
|
|
*/
|
|
|
|
public short getBurnTime() {
|
|
|
|
return burnTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param burnTime the burnTime to set
|
|
|
|
*/
|
|
|
|
public void setBurnTime(short burnTime) {
|
|
|
|
this.burnTime = burnTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the cookTime
|
|
|
|
*/
|
|
|
|
public short getCookTime() {
|
|
|
|
return cookTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param cookTime the cookTime to set
|
|
|
|
*/
|
|
|
|
public void setCookTime(short cookTime) {
|
|
|
|
this.cookTime = cookTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tile entity ID.
|
2012-03-04 00:46:51 +00:00
|
|
|
*
|
2011-01-23 08:36:26 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getTileEntityID() {
|
|
|
|
return "Furnace";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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>();
|
2012-03-30 04:11:49 +00:00
|
|
|
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(getItems())));
|
2011-01-23 08:36:26 +00:00
|
|
|
values.put("BurnTime", new ShortTag("BurnTime", burnTime));
|
|
|
|
values.put("CookTime", new ShortTag("CookTime", cookTime));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tag t = values.get("id");
|
2011-11-23 01:29:48 +00:00
|
|
|
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Furnace")) {
|
2011-01-23 08:36:26 +00:00
|
|
|
throw new DataException("'Furnace' tile entity expected");
|
|
|
|
}
|
|
|
|
|
2012-03-30 04:11:49 +00:00
|
|
|
ListTag items = NBTUtils.getChildTag(values, "Items", ListTag.class);
|
|
|
|
|
|
|
|
List<CompoundTag> compound = new ArrayList<CompoundTag>();
|
2011-01-23 08:36:26 +00:00
|
|
|
|
|
|
|
for (Tag tag : items.getValue()) {
|
|
|
|
if (!(tag instanceof CompoundTag)) {
|
2012-03-30 04:11:49 +00:00
|
|
|
throw new DataException("CompoundTag expected as child tag of Furnace Items");
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
2012-03-30 04:11:49 +00:00
|
|
|
compound.add((CompoundTag) tag);
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
2012-03-30 04:11:49 +00:00
|
|
|
setItems(deserializeInventory(compound));
|
2011-01-23 08:36:26 +00:00
|
|
|
|
|
|
|
t = values.get("BurnTime");
|
|
|
|
if (t instanceof ShortTag) {
|
2011-11-23 01:29:48 +00:00
|
|
|
burnTime = ((ShortTag) t).getValue();
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t = values.get("CookTime");
|
|
|
|
if (t instanceof ShortTag) {
|
2011-11-23 01:29:48 +00:00
|
|
|
cookTime = ((ShortTag) t).getValue();
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|