mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-08-23 00:44:32 +00:00
Added full block data support for Bukkit.
This commit is contained in:
parent
f27f922931
commit
360ae06d65
@ -445,28 +445,28 @@ public class CuboidClipboard {
|
|||||||
BlockVector pt = new BlockVector(x, y, z);
|
BlockVector pt = new BlockVector(x, y, z);
|
||||||
BaseBlock block;
|
BaseBlock block;
|
||||||
|
|
||||||
if (blocks[index] == 63 || blocks[index] == 68) { // Signs
|
if (blocks[index] == BlockID.WALL_SIGN || blocks[index] == BlockID.SIGN_POST) {
|
||||||
block = new SignBlock(blocks[index], blockData[index]);
|
block = new SignBlock(blocks[index], blockData[index]);
|
||||||
if (tileEntitiesMap.containsKey(pt)) {
|
} else if (blocks[index] == BlockID.CHEST) {
|
||||||
((TileEntityBlock)block).fromTileEntityNBT(
|
block = new ChestBlock(blockData[index]);
|
||||||
tileEntitiesMap.get(pt));
|
} else if (blocks[index] == BlockID.FURNACE || blocks[index] == BlockID.BURNING_FURNACE) {
|
||||||
}
|
block = new FurnaceBlock(blocks[index], blockData[index]);
|
||||||
} else if(blocks[index] == 54) { // Chest
|
} else if (blocks[index] == BlockID.DISPENSER) {
|
||||||
block = new ChestBlock();
|
block = new DispenserBlock(blockData[index]);
|
||||||
if (tileEntitiesMap.containsKey(pt)) {
|
} else if (blocks[index] == BlockID.MOB_SPAWNER) {
|
||||||
((TileEntityBlock)block).fromTileEntityNBT(
|
block = new MobSpawnerBlock(blockData[index]);
|
||||||
tileEntitiesMap.get(pt));
|
} else if (blocks[index] == BlockID.NOTE_BLOCK) {
|
||||||
}
|
block = new NoteBlock(blockData[index]);
|
||||||
} else if(blocks[index] == 52) { // Mob spawner
|
|
||||||
block = new MobSpawnerBlock();
|
|
||||||
if (tileEntitiesMap.containsKey(pt)) {
|
|
||||||
((TileEntityBlock)block).fromTileEntityNBT(
|
|
||||||
tileEntitiesMap.get(pt));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
block = new BaseBlock(blocks[index], blockData[index]);
|
block = new BaseBlock(blocks[index], blockData[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (block instanceof TileEntityBlock
|
||||||
|
&& tileEntitiesMap.containsKey(pt)) {
|
||||||
|
((TileEntityBlock)block).fromTileEntityNBT(
|
||||||
|
tileEntitiesMap.get(pt));
|
||||||
|
}
|
||||||
|
|
||||||
clipboard.data[x][y][z] = block;
|
clipboard.data[x][y][z] = block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,9 +150,9 @@ public class EditSession {
|
|||||||
|
|
||||||
int existing = world.getBlockType(pt);
|
int existing = world.getBlockType(pt);
|
||||||
|
|
||||||
// Clear the chest so that it doesn't drop items
|
// Clear the container block so that it doesn't drop items
|
||||||
if (existing == 54 && blockBag == null) {
|
if (BlockType.isContainerBlock(existing) && blockBag == null) {
|
||||||
world.clearChest(pt);
|
world.clearContainerBlockContents(pt);
|
||||||
// Ice turns until water so this has to be done first
|
// Ice turns until water so this has to be done first
|
||||||
} else if (existing == BlockID.ICE) {
|
} else if (existing == BlockID.ICE) {
|
||||||
world.setBlockType(pt, 0);
|
world.setBlockType(pt, 0);
|
||||||
@ -189,16 +189,27 @@ public class EditSession {
|
|||||||
// Signs
|
// Signs
|
||||||
if (block instanceof SignBlock) {
|
if (block instanceof SignBlock) {
|
||||||
SignBlock signBlock = (SignBlock) block;
|
SignBlock signBlock = (SignBlock) block;
|
||||||
String[] text = signBlock.getText();
|
world.copyToWorld(pt, signBlock);
|
||||||
world.setSignText(pt, text);
|
|
||||||
// Chests
|
// Chests
|
||||||
} else if (block instanceof ChestBlock && blockBag == null) {
|
} else if (block instanceof ChestBlock && blockBag == null) {
|
||||||
ChestBlock chestBlock = (ChestBlock) block;
|
ChestBlock chestBlock = (ChestBlock) block;
|
||||||
world.setChestContents(pt, chestBlock.getItems());
|
world.copyToWorld(pt, chestBlock);
|
||||||
|
// Furnaces
|
||||||
|
} else if (block instanceof FurnaceBlock && blockBag == null) {
|
||||||
|
FurnaceBlock furnaceBlock = (FurnaceBlock) block;
|
||||||
|
world.copyToWorld(pt, furnaceBlock);
|
||||||
|
// Dispenser
|
||||||
|
} else if (block instanceof DispenserBlock && blockBag == null) {
|
||||||
|
DispenserBlock dispenserBlock = (DispenserBlock) block;
|
||||||
|
world.copyToWorld(pt, dispenserBlock);
|
||||||
// Mob spawners
|
// Mob spawners
|
||||||
} else if (block instanceof MobSpawnerBlock) {
|
} else if (block instanceof MobSpawnerBlock) {
|
||||||
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock) block;
|
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock) block;
|
||||||
world.setMobSpawnerType(pt, mobSpawnerblock.getMobType());
|
world.copyToWorld(pt, mobSpawnerblock);
|
||||||
|
// Note blocks
|
||||||
|
} else if (block instanceof NoteBlock) {
|
||||||
|
NoteBlock noteBlock = (NoteBlock) block;
|
||||||
|
world.copyToWorld(pt, noteBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,16 +316,35 @@ public class EditSession {
|
|||||||
int data = world.getBlockData(pt);
|
int data = world.getBlockData(pt);
|
||||||
|
|
||||||
// Sign
|
// Sign
|
||||||
if (type == 63 || type == 68) {
|
if (type == BlockID.WALL_SIGN || type == BlockID.SIGN_POST) {
|
||||||
String[] text = world.getSignText(pt);
|
SignBlock block = new SignBlock(type, data);
|
||||||
return new SignBlock(type, data, text);
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
// Chest
|
// Chest
|
||||||
} else if (type == 54) {
|
} else if (type == BlockID.CHEST) {
|
||||||
BaseItemStack[] items = world.getChestContents(pt);
|
ChestBlock block = new ChestBlock(data);
|
||||||
return new ChestBlock(data, items);
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
|
// Furnace
|
||||||
|
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE) {
|
||||||
|
FurnaceBlock block = new FurnaceBlock(type, data);
|
||||||
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
|
// Dispenser
|
||||||
|
} else if (type == BlockID.DISPENSER) {
|
||||||
|
DispenserBlock block = new DispenserBlock(data);
|
||||||
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
// Mob spawner
|
// Mob spawner
|
||||||
} else if (type == 52) {
|
} else if (type == BlockID.MOB_SPAWNER) {
|
||||||
return new MobSpawnerBlock(data, world.getMobSpawnerType(pt));
|
MobSpawnerBlock block = new MobSpawnerBlock(data);
|
||||||
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
|
// Note block
|
||||||
|
} else if (type == BlockID.NOTE_BLOCK) {
|
||||||
|
NoteBlock block = new NoteBlock(data);
|
||||||
|
world.copyFromWorld(pt, block);
|
||||||
|
return block;
|
||||||
} else {
|
} else {
|
||||||
return new BaseBlock(type, data);
|
return new BaseBlock(type, data);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,63 +69,29 @@ public abstract class LocalWorld {
|
|||||||
public abstract int getBlockData(Vector pt);
|
public abstract int getBlockData(Vector pt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set sign text.
|
* Attempts to accurately copy a BaseBlock's extra data to the world.
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @param text
|
|
||||||
*/
|
|
||||||
public abstract void setSignText(Vector pt, String[] text);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get sign text.
|
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract String[] getSignText(Vector pt);
|
public abstract boolean copyToWorld(Vector pt, BaseBlock block);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the contents of chests. Will return null if the chest does not
|
* Attempts to read a BaseBlock's extra data from the world.
|
||||||
* really exist or it is the second block for a double chest.
|
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract BaseItemStack[] getChestContents(Vector pt);
|
public abstract boolean copyFromWorld(Vector pt, BaseBlock block);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a chest slot.
|
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @param contents
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract boolean setChestContents(Vector pt,
|
|
||||||
BaseItemStack[] contents);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear a chest's contents.
|
* Clear a chest's contents.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
*/
|
*/
|
||||||
public abstract boolean clearChest(Vector pt);
|
public abstract boolean clearContainerBlockContents(Vector pt);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set mob spawner mob type.
|
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @param mobType
|
|
||||||
*/
|
|
||||||
public abstract void setMobSpawnerType(Vector pt,
|
|
||||||
String mobType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get mob spawner mob type. May return an empty string.
|
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @param mobType
|
|
||||||
*/
|
|
||||||
public abstract String getMobSpawnerType(Vector pt);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a tree at a location.
|
* Generate a tree at a location.
|
||||||
|
@ -46,6 +46,11 @@ public final class BlockID {
|
|||||||
public static final int LEAVES = 18;
|
public static final int LEAVES = 18;
|
||||||
public static final int SPONGE = 19;
|
public static final int SPONGE = 19;
|
||||||
public static final int GLASS = 20;
|
public static final int GLASS = 20;
|
||||||
|
public static final int LAPIS_LAZULI_ORE = 21;
|
||||||
|
public static final int LAPIS_LAZULI_BLOCK = 22;
|
||||||
|
public static final int DISPENSER = 23;
|
||||||
|
public static final int SANDSTONE = 24;
|
||||||
|
public static final int NOTE_BLOCK = 25;
|
||||||
public static final int CLOTH = 35;
|
public static final int CLOTH = 35;
|
||||||
public static final int YELLOW_FLOWER = 37;
|
public static final int YELLOW_FLOWER = 37;
|
||||||
public static final int RED_FLOWER = 38;
|
public static final int RED_FLOWER = 38;
|
||||||
@ -98,8 +103,10 @@ public final class BlockID {
|
|||||||
public static final int FENCE = 85;
|
public static final int FENCE = 85;
|
||||||
public static final int PUMPKIN = 86;
|
public static final int PUMPKIN = 86;
|
||||||
public static final int NETHERSTONE = 87;
|
public static final int NETHERSTONE = 87;
|
||||||
|
public static final int NETHERRACK = 87;
|
||||||
public static final int SLOW_SAND = 88;
|
public static final int SLOW_SAND = 88;
|
||||||
public static final int LIGHTSTONE = 89;
|
public static final int LIGHTSTONE = 89;
|
||||||
public static final int PORTAL = 90;
|
public static final int PORTAL = 90;
|
||||||
public static final int JACKOLANTERN = 91;
|
public static final int JACKOLANTERN = 91;
|
||||||
|
public static final int CAKE_BLOCK = 92;
|
||||||
}
|
}
|
||||||
|
@ -400,6 +400,19 @@ public enum BlockType {
|
|||||||
|| id == 91; // Jack-o-lantern
|
|| id == 91; // Jack-o-lantern
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the block is a container block.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isContainerBlock(int id) {
|
||||||
|
return id == 23 // Dispenser
|
||||||
|
|| id == 61 // Furnace
|
||||||
|
|| id == 62 // Furnace
|
||||||
|
|| id == 54; // Chest
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block or item that would have been dropped. If nothing is
|
* Get the block or item that would have been dropped. If nothing is
|
||||||
* dropped, 0 will be returned. If the block should not be destroyed
|
* dropped, 0 will be returned. If the block should not be destroyed
|
||||||
|
@ -31,7 +31,7 @@ import org.jnbt.*;
|
|||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class ChestBlock extends BaseBlock implements TileEntityBlock {
|
public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||||
/**
|
/**
|
||||||
* Store the list of items.
|
* Store the list of items.
|
||||||
*/
|
*/
|
||||||
|
41
src/com/sk89q/worldedit/blocks/ContainerBlock.java
Normal file
41
src/com/sk89q/worldedit/blocks/ContainerBlock.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// $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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a block that stores items.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public interface ContainerBlock {
|
||||||
|
/**
|
||||||
|
* Get the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BaseItemStack[] getItems();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void setItems(BaseItemStack[] items);
|
||||||
|
}
|
167
src/com/sk89q/worldedit/blocks/DispenserBlock.java
Normal file
167
src/com/sk89q/worldedit/blocks/DispenserBlock.java
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
// $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;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.data.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.jnbt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents dispensers.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class DispenserBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||||
|
/**
|
||||||
|
* Store the list of items.
|
||||||
|
*/
|
||||||
|
private BaseItemStack[] items;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*/
|
||||||
|
public DispenserBlock() {
|
||||||
|
super(54);
|
||||||
|
items = new BaseItemStack[9];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
public DispenserBlock(int data) {
|
||||||
|
super(23, data);
|
||||||
|
items = new BaseItemStack[9];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param items
|
||||||
|
*/
|
||||||
|
public DispenserBlock(int data, BaseItemStack[] items) {
|
||||||
|
super(23, data);
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BaseItemStack[] getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void setItems(BaseItemStack[] items) {
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile entity ID.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTileEntityID() {
|
||||||
|
return "Trap";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
List<Tag> itemsList = new ArrayList<Tag>();
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
BaseItemStack item = items[i];
|
||||||
|
if (item != null) {
|
||||||
|
Map<String,Tag> data = new HashMap<String,Tag>();
|
||||||
|
CompoundTag itemTag = new CompoundTag("Items", data);
|
||||||
|
data.put("id", new ShortTag("id", (short)item.getType()));
|
||||||
|
data.put("Damage", new ShortTag("Damage", item.getDamage()));
|
||||||
|
data.put("Count", new ByteTag("Count", (byte)item.getAmount()));
|
||||||
|
data.put("Slot", new ByteTag("Slot", (byte)i));
|
||||||
|
itemsList.add(itemTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||||
|
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
|
||||||
|
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("Trap")) {
|
||||||
|
throw new DataException("'Trap' tile entity expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class);
|
||||||
|
BaseItemStack[] newItems = new BaseItemStack[27];
|
||||||
|
|
||||||
|
for (Tag tag : items.getValue()) {
|
||||||
|
if (!(tag instanceof CompoundTag)) {
|
||||||
|
throw new DataException("CompoundTag expected as child tag of Trap Items");
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag item = (CompoundTag)tag;
|
||||||
|
Map<String,Tag> itemValues = item.getValue();
|
||||||
|
|
||||||
|
short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class))
|
||||||
|
.getValue();
|
||||||
|
short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class))
|
||||||
|
.getValue();
|
||||||
|
byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class))
|
||||||
|
.getValue();
|
||||||
|
byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class))
|
||||||
|
.getValue();
|
||||||
|
|
||||||
|
if (slot >= 0 && slot <= 26) {
|
||||||
|
newItems[slot] = new BaseItemStack(id, count, damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.items = newItems;
|
||||||
|
}
|
||||||
|
}
|
216
src/com/sk89q/worldedit/blocks/FurnaceBlock.java
Normal file
216
src/com/sk89q/worldedit/blocks/FurnaceBlock.java
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
// $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;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.data.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.jnbt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents furnaces.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class FurnaceBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||||
|
/**
|
||||||
|
* Store the list of items.
|
||||||
|
*/
|
||||||
|
private BaseItemStack[] items;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fuel time.
|
||||||
|
*/
|
||||||
|
private short burnTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cook time.
|
||||||
|
*/
|
||||||
|
private short cookTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*/
|
||||||
|
public FurnaceBlock(int type) {
|
||||||
|
super(type);
|
||||||
|
items = new BaseItemStack[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
public FurnaceBlock(int type, int data) {
|
||||||
|
super(type, data);
|
||||||
|
items = new BaseItemStack[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the chest block.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param items
|
||||||
|
*/
|
||||||
|
public FurnaceBlock(int type, int data, BaseItemStack[] items) {
|
||||||
|
super(type, data);
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BaseItemStack[] getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void setItems(BaseItemStack[] items) {
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTileEntityID() {
|
||||||
|
return "Furnace";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
List<Tag> itemsList = new ArrayList<Tag>();
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
BaseItemStack item = items[i];
|
||||||
|
if (item != null) {
|
||||||
|
Map<String,Tag> data = new HashMap<String,Tag>();
|
||||||
|
CompoundTag itemTag = new CompoundTag("Items", data);
|
||||||
|
data.put("id", new ShortTag("id", (short)item.getType()));
|
||||||
|
data.put("Damage", new ShortTag("Damage", item.getDamage()));
|
||||||
|
data.put("Count", new ByteTag("Count", (byte)item.getAmount()));
|
||||||
|
data.put("Slot", new ByteTag("Slot", (byte)i));
|
||||||
|
itemsList.add(itemTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||||
|
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
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("Furnace")) {
|
||||||
|
throw new DataException("'Furnace' tile entity expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class);
|
||||||
|
BaseItemStack[] newItems = new BaseItemStack[27];
|
||||||
|
|
||||||
|
for (Tag tag : items.getValue()) {
|
||||||
|
if (!(tag instanceof CompoundTag)) {
|
||||||
|
throw new DataException("CompoundTag expected as child tag of Trap Items");
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag item = (CompoundTag)tag;
|
||||||
|
Map<String,Tag> itemValues = item.getValue();
|
||||||
|
|
||||||
|
short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class))
|
||||||
|
.getValue();
|
||||||
|
short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class))
|
||||||
|
.getValue();
|
||||||
|
byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class))
|
||||||
|
.getValue();
|
||||||
|
byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class))
|
||||||
|
.getValue();
|
||||||
|
|
||||||
|
if (slot >= 0 && slot <= 26) {
|
||||||
|
newItems[slot] = new BaseItemStack(id, count, damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.items = newItems;
|
||||||
|
|
||||||
|
t = values.get("BurnTime");
|
||||||
|
if (t instanceof ShortTag) {
|
||||||
|
burnTime = ((ShortTag)t).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
t = values.get("CookTime");
|
||||||
|
if (t instanceof ShortTag) {
|
||||||
|
cookTime = ((ShortTag)t).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
/**
|
/**
|
||||||
* Construct the mob spawner block.
|
* Construct the mob spawner block.
|
||||||
*
|
*
|
||||||
* @param items
|
* @param mobType
|
||||||
*/
|
*/
|
||||||
public MobSpawnerBlock(String mobType) {
|
public MobSpawnerBlock(String mobType) {
|
||||||
super(52);
|
super(52);
|
||||||
@ -62,7 +62,16 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
* Construct the mob spawner block.
|
* Construct the mob spawner block.
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
* @param items
|
*/
|
||||||
|
public MobSpawnerBlock(int data) {
|
||||||
|
super(52, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the mob spawner block.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param mobType
|
||||||
*/
|
*/
|
||||||
public MobSpawnerBlock(int data, String mobType) {
|
public MobSpawnerBlock(int data, String mobType) {
|
||||||
super(52, data);
|
super(52, data);
|
||||||
@ -120,7 +129,7 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
throws DataException {
|
throws DataException {
|
||||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||||
values.put("EntityId", new StringTag("EntityId", mobType));
|
values.put("EntityId", new StringTag("EntityId", mobType));
|
||||||
values.put("Delay", new ShortTag("Delay", (short)0));
|
values.put("Delay", new ShortTag("Delay", delay));
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
117
src/com/sk89q/worldedit/blocks/NoteBlock.java
Normal file
117
src/com/sk89q/worldedit/blocks/NoteBlock.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// $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;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.data.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.jnbt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
||||||
|
/**
|
||||||
|
* Stores the pitch.
|
||||||
|
*/
|
||||||
|
private byte note;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the sign without text.
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
public NoteBlock(int data) {
|
||||||
|
super(25, data);
|
||||||
|
this.note = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the sign with text.
|
||||||
|
*
|
||||||
|
* @param note
|
||||||
|
*/
|
||||||
|
public NoteBlock(int data, byte note) {
|
||||||
|
super(25, data);
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("note", new ByteTag("note", note));
|
||||||
|
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;
|
||||||
|
|
||||||
|
t = values.get("id");
|
||||||
|
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Music")) {
|
||||||
|
throw new DataException("'Music' tile entity expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
t = values.get("note");
|
||||||
|
if (t instanceof ByteTag) {
|
||||||
|
note = ((ByteTag)t).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.entity.MobType;
|
||||||
import com.sk89q.worldedit.ServerInterface;
|
import com.sk89q.worldedit.ServerInterface;
|
||||||
|
|
||||||
public class BukkitServerInterface extends ServerInterface {
|
public class BukkitServerInterface extends ServerInterface {
|
||||||
@ -37,8 +38,7 @@ public class BukkitServerInterface extends ServerInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidMobType(String type) {
|
public boolean isValidMobType(String type) {
|
||||||
// TODO Auto-generated method stub
|
return MobType.fromName(type) != null;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,17 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Furnace;
|
||||||
|
import org.bukkit.block.MobSpawner;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.*;
|
||||||
|
|
||||||
public class BukkitWorld extends LocalWorld {
|
public class BukkitWorld extends LocalWorld {
|
||||||
/**
|
/**
|
||||||
@ -40,51 +43,302 @@ public class BukkitWorld extends LocalWorld {
|
|||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the object.
|
||||||
|
* @param world
|
||||||
|
*/
|
||||||
public BukkitWorld(World world) {
|
public BukkitWorld(World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the world handle.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set block type.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlockType(Vector pt, int type) {
|
public boolean setBlockType(Vector pt, int type) {
|
||||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
|
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get block type.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getBlockType(Vector pt) {
|
public int getBlockType(Vector pt) {
|
||||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getTypeId();
|
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getTypeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set block data.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setBlockData(Vector pt, int data) {
|
public void setBlockData(Vector pt, int data) {
|
||||||
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data);
|
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get block data.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getBlockData(Vector pt) {
|
public int getBlockData(Vector pt) {
|
||||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
|
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to accurately copy a BaseBlock's extra data to the world.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param block
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setSignText(Vector pt, String[] text) {
|
public boolean copyToWorld(Vector pt, BaseBlock block) {
|
||||||
|
// Signs
|
||||||
|
if (block instanceof SignBlock) {
|
||||||
|
setSignText(pt, ((SignBlock)block).getText());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Furnaces
|
||||||
|
} else if (block instanceof FurnaceBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof Furnace)) return false;
|
||||||
|
Furnace bukkit = (Furnace)state;
|
||||||
|
FurnaceBlock we = (FurnaceBlock)block;
|
||||||
|
bukkit.setBurnTime(we.getBurnTime());
|
||||||
|
bukkit.setCookTime(we.getCookTime());
|
||||||
|
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
|
||||||
|
|
||||||
|
// Chests/dispenser
|
||||||
|
} else if (block instanceof ContainerBlock) {
|
||||||
|
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
|
||||||
|
|
||||||
|
// Mob spawners
|
||||||
|
} else if (block instanceof MobSpawnerBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof MobSpawner)) return false;
|
||||||
|
MobSpawner bukkit = (MobSpawner)state;
|
||||||
|
MobSpawnerBlock we = (MobSpawnerBlock)block;
|
||||||
|
bukkit.setMobTypeId(we.getMobType());
|
||||||
|
bukkit.setDelay(we.getDelay());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Note block
|
||||||
|
} else if (block instanceof NoteBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
|
||||||
|
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
|
||||||
|
NoteBlock we = (NoteBlock)block;
|
||||||
|
bukkit.setNote(we.getNote());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to read a BaseBlock's extra data from the world.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param block
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean copyFromWorld(Vector pt, BaseBlock block) {
|
||||||
|
// Signs
|
||||||
|
if (block instanceof SignBlock) {
|
||||||
|
((SignBlock)block).setText(getSignText(pt));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Furnaces
|
||||||
|
} else if (block instanceof FurnaceBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof Furnace)) return false;
|
||||||
|
Furnace bukkit = (Furnace)state;
|
||||||
|
FurnaceBlock we = (FurnaceBlock)block;
|
||||||
|
we.setBurnTime(bukkit.getBurnTime());
|
||||||
|
we.setCookTime(bukkit.getCookTime());
|
||||||
|
((ContainerBlock)block).setItems(getContainerBlockContents(pt));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Chests/dispenser
|
||||||
|
} else if (block instanceof ContainerBlock) {
|
||||||
|
((ContainerBlock)block).setItems(getContainerBlockContents(pt));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Mob spawners
|
||||||
|
} else if (block instanceof MobSpawnerBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof MobSpawner)) return false;
|
||||||
|
MobSpawner bukkit = (MobSpawner)state;
|
||||||
|
MobSpawnerBlock we = (MobSpawnerBlock)block;
|
||||||
|
we.setMobType(bukkit.getMobTypeId());
|
||||||
|
we.setDelay((short)bukkit.getDelay());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Note block
|
||||||
|
} else if (block instanceof NoteBlock) {
|
||||||
|
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (bukkitBlock == null) return false;
|
||||||
|
BlockState state = bukkitBlock.getState();
|
||||||
|
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
|
||||||
|
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
|
||||||
|
NoteBlock we = (NoteBlock)block;
|
||||||
|
we.setNote(bukkit.getNote());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear a chest's contents.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean clearContainerBlockContents(Vector pt) {
|
||||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
if (block == null) return;
|
if (block == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state == null || !(state instanceof Sign)) return;
|
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
|
||||||
|
Inventory inven = chest.getInventory();
|
||||||
|
inven.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a tree at a location.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean generateTree(EditSession editSession, Vector pt) {
|
||||||
|
try {
|
||||||
|
return CraftBukkitInterface.generateTree(editSession, pt);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.log(Level.SEVERE,
|
||||||
|
"Failed to create tree (do you need to update WorldEdit " +
|
||||||
|
"due to a Minecraft update?)", t);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a big tree at a location.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean generateBigTree(EditSession editSession, Vector pt) {
|
||||||
|
try {
|
||||||
|
return CraftBukkitInterface.generateBigTree(editSession, pt);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.log(Level.SEVERE,
|
||||||
|
"Failed to create tree (do you need to update WorldEdit " +
|
||||||
|
"due to a Minecraft update?)", t);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop an item.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param item
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void dropItem(Vector pt, BaseItemStack item) {
|
||||||
|
ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
|
||||||
|
(byte)item.getDamage());
|
||||||
|
world.dropItemNaturally(toLocation(pt), bukkitItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kill mobs in an area.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param radius
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int killMobs(Vector origin, int radius) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location toLocation(Vector pt) {
|
||||||
|
return new Location(world, pt.getX(), pt.getY(), pt.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a sign's text.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param text
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean setSignText(Vector pt, String[] text) {
|
||||||
|
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (block == null) return false;
|
||||||
|
BlockState state = block.getState();
|
||||||
|
if (state == null || !(state instanceof Sign)) return false;
|
||||||
Sign sign = (Sign)state;
|
Sign sign = (Sign)state;
|
||||||
sign.setLine(0, text[0]);
|
sign.setLine(0, text[0]);
|
||||||
sign.setLine(1, text[1]);
|
sign.setLine(1, text[1]);
|
||||||
sign.setLine(2, text[2]);
|
sign.setLine(2, text[2]);
|
||||||
sign.setLine(3, text[3]);
|
sign.setLine(3, text[3]);
|
||||||
sign.update();
|
sign.update();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String[] getSignText(Vector pt) {
|
* Get a sign's text.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String[] getSignText(Vector pt) {
|
||||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
if (block == null) return new String[] { "", "", "", "" };
|
if (block == null) return new String[] { "", "", "", "" };
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
@ -102,76 +356,76 @@ public class BukkitWorld extends LocalWorld {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public BaseItemStack[] getChestContents(Vector pt) {
|
* Get a container block's contents.
|
||||||
// TODO Auto-generated method stub
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private BaseItemStack[] getContainerBlockContents(Vector pt) {
|
||||||
|
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (block == null) {
|
||||||
|
return new BaseItemStack[0];
|
||||||
|
}
|
||||||
|
BlockState state = block.getState();
|
||||||
|
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||||
return new BaseItemStack[0];
|
return new BaseItemStack[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
org.bukkit.block.ContainerBlock container = (org.bukkit.block.ContainerBlock)state;
|
||||||
public boolean setChestContents(Vector pt, BaseItemStack[] contents) {
|
Inventory inven = container.getInventory();
|
||||||
// TODO Auto-generated method stub
|
int size = inven.getSize();
|
||||||
|
BaseItemStack[] contents = new BaseItemStack[size];
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
ItemStack bukkitStack = inven.getItem(i);
|
||||||
|
if (bukkitStack.getTypeId() > 0) {
|
||||||
|
contents[i] = new BaseItemStack(
|
||||||
|
bukkitStack.getTypeId(),
|
||||||
|
bukkitStack.getAmount(),
|
||||||
|
bukkitStack.getDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a container block's contents.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param contents
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean setContainerBlockContents(Vector pt, BaseItemStack[] contents) {
|
||||||
|
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (block == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
BlockState state = block.getState();
|
||||||
|
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
|
||||||
public boolean clearChest(Vector pt) {
|
Inventory inven = chest.getInventory();
|
||||||
// TODO Auto-generated method stub
|
int size = inven.getSize();
|
||||||
return false;
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
if (i >= contents.length + 1) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (contents[i] != null) {
|
||||||
public void setMobSpawnerType(Vector pt, String mobType) {
|
inven.setItem(i, new ItemStack(contents[i].getType(),
|
||||||
// TODO Auto-generated method stub
|
contents[i].getAmount(),
|
||||||
|
(byte)contents[i].getDamage()));
|
||||||
}
|
} else {
|
||||||
|
inven.setItem(i, null);
|
||||||
@Override
|
|
||||||
public String getMobSpawnerType(Vector pt) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean generateTree(EditSession editSession, Vector pt) {
|
|
||||||
try {
|
|
||||||
return CraftBukkitInterface.generateTree(editSession, pt);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.log(Level.SEVERE,
|
|
||||||
"Failed to create tree (do you need to update WorldEdit " +
|
|
||||||
"due to a Minecraft update?)", t);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return true;
|
||||||
public boolean generateBigTree(EditSession editSession, Vector pt) {
|
|
||||||
try {
|
|
||||||
return CraftBukkitInterface.generateBigTree(editSession, pt);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.log(Level.SEVERE,
|
|
||||||
"Failed to create tree (do you need to update WorldEdit " +
|
|
||||||
"due to a Minecraft update?)", t);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dropItem(Vector pt, BaseItemStack item) {
|
|
||||||
ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
|
|
||||||
(byte)item.getDamage());
|
|
||||||
world.dropItemNaturally(toLocation(pt), bukkitItem);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int killMobs(Vector origin, int radius) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Location toLocation(Vector pt) {
|
|
||||||
return new Location(world, pt.getX(), pt.getY(), pt.getZ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user