2010-11-27 03:33:28 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* 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.*;
|
2010-11-27 03:33:28 +00:00
|
|
|
import com.sk89q.worldedit.data.*;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
2011-09-06 08:06:17 +00:00
|
|
|
* Represents mob spawners.
|
2010-11-27 03:33:28 +00:00
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
|
|
|
/**
|
|
|
|
* Store mob spawn type.
|
|
|
|
*/
|
|
|
|
private String mobType;
|
|
|
|
/**
|
|
|
|
* Delay until next spawn.
|
|
|
|
*/
|
|
|
|
private short delay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the mob spawner block.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public MobSpawnerBlock() {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.MOB_SPAWNER);
|
2011-09-06 08:06:17 +00:00
|
|
|
this.mobType = MobType.PIG.getName();
|
2010-11-27 03:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the mob spawner block.
|
|
|
|
*
|
2011-01-23 08:36:26 +00:00
|
|
|
* @param mobType
|
2010-11-27 03:33:28 +00:00
|
|
|
*/
|
|
|
|
public MobSpawnerBlock(String mobType) {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.MOB_SPAWNER);
|
2010-11-27 03:33:28 +00:00
|
|
|
this.mobType = mobType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the mob spawner block.
|
|
|
|
*
|
|
|
|
* @param data
|
2011-01-23 08:36:26 +00:00
|
|
|
*/
|
|
|
|
public MobSpawnerBlock(int data) {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.MOB_SPAWNER, data);
|
2011-01-23 08:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the mob spawner block.
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
* @param mobType
|
2010-11-27 03:33:28 +00:00
|
|
|
*/
|
|
|
|
public MobSpawnerBlock(int data, String mobType) {
|
2011-09-03 16:54:20 +00:00
|
|
|
super(BlockID.MOB_SPAWNER, data);
|
2010-11-27 03:33:28 +00:00
|
|
|
this.mobType = mobType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mob type.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getMobType() {
|
|
|
|
return mobType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the mob type.
|
2011-02-18 23:49:50 +00:00
|
|
|
*
|
|
|
|
* @param mobType
|
2010-11-27 03:33:28 +00:00
|
|
|
*/
|
|
|
|
public void setMobType(String mobType) {
|
|
|
|
this.mobType = mobType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the delay
|
|
|
|
*/
|
|
|
|
public short getDelay() {
|
|
|
|
return delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param delay the delay to set
|
|
|
|
*/
|
|
|
|
public void setDelay(short delay) {
|
|
|
|
this.delay = delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tile entity ID.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getTileEntityID() {
|
|
|
|
return "MobSpawner";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store additional tile entity data. Returns true if the data is used.
|
|
|
|
*
|
|
|
|
* @return map of values
|
|
|
|
* @throws DataException
|
|
|
|
*/
|
|
|
|
public Map<String,Tag> toTileEntityNBT()
|
|
|
|
throws DataException {
|
|
|
|
Map<String,Tag> values = new HashMap<String,Tag>();
|
|
|
|
values.put("EntityId", new StringTag("EntityId", mobType));
|
2011-01-23 08:36:26 +00:00
|
|
|
values.put("Delay", new ShortTag("Delay", delay));
|
2010-11-27 03:33:28 +00:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get additional information from the title entity data.
|
|
|
|
*
|
|
|
|
* @param values
|
|
|
|
* @throws DataException
|
|
|
|
*/
|
|
|
|
public void fromTileEntityNBT(Map<String,Tag> values)
|
|
|
|
throws DataException {
|
|
|
|
if (values == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tag t = values.get("id");
|
|
|
|
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("MobSpawner")) {
|
|
|
|
throw new DataException("'MobSpawner' tile entity expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
StringTag mobTypeTag = (StringTag)Chunk.getChildTag(values, "EntityId", StringTag.class);
|
|
|
|
ShortTag delayTag = (ShortTag)Chunk.getChildTag(values, "Delay", ShortTag.class);
|
|
|
|
|
|
|
|
this.mobType = mobTypeTag.getValue();
|
|
|
|
this.delay = delayTag.getValue();
|
|
|
|
}
|
|
|
|
}
|