Cleaned up ContainerBlock inventory reading from NBT

Changed ListTag's List parameter to List<? extends Tag>
Dieser Commit ist enthalten in:
zml2008 2012-03-29 21:11:49 -07:00
Ursprung 33752eb058
Commit 3bfb12c051
13 geänderte Dateien mit 185 neuen und 302 gelöschten Zeilen

Datei anzeigen

@ -49,7 +49,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.2.3-R0.3-SNAPSHOT</version>
<version>1.2.4-R1.0</version>
</dependency>
<!-- Archive reading library for snapshots -->

Datei anzeigen

@ -2,24 +2,24 @@ package com.sk89q.jnbt;
/*
* JNBT License
*
*
* Copyright (c) 2010 Graham Edgecombe
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -30,7 +30,7 @@ package com.sk89q.jnbt;
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*/
import java.util.Collections;
@ -40,9 +40,9 @@ import com.sk89q.jnbt.Tag;
/**
* The <code>TAG_List</code> tag.
*
*
* @author Graham Edgecombe
*
*
*/
public final class ListTag extends Tag {
@ -58,7 +58,7 @@ public final class ListTag extends Tag {
/**
* Creates the tag.
*
*
* @param name
* The name.
* @param type
@ -66,7 +66,7 @@ public final class ListTag extends Tag {
* @param value
* The value.
*/
public ListTag(String name, Class<? extends Tag> type, List<Tag> value) {
public ListTag(String name, Class<? extends Tag> type, List<? extends Tag> value) {
super(name);
this.type = type;
this.value = Collections.unmodifiableList(value);
@ -74,7 +74,7 @@ public final class ListTag extends Tag {
/**
* Gets the type of item in this list.
*
*
* @return The type of item in this list.
*/
public Class<? extends Tag> getType() {

Datei anzeigen

@ -19,24 +19,24 @@ import com.sk89q.worldedit.data.InvalidFormatException;
/*
* JNBT License
*
*
* Copyright (c) 2010 Graham Edgecombe
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -47,20 +47,20 @@ import com.sk89q.worldedit.data.InvalidFormatException;
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* A class which contains NBT-related utility methods.
*
*
* @author Graham Edgecombe
*
*
*/
public final class NBTUtils {
/**
* Gets the type name of a tag.
*
*
* @param clazz
* The tag class.
* @return The type name.
@ -98,7 +98,7 @@ public final class NBTUtils {
/**
* Gets the type code of a tag class.
*
*
* @param clazz
* The tag class.
* @return The type code.
@ -129,7 +129,7 @@ public final class NBTUtils {
} else if (clazz.equals(StringTag.class)) {
return NBTConstants.TYPE_STRING;
} else if (clazz.equals(IntArrayTag.class)) {
return NBTConstants.TYPE_INT_ARRAY;
return NBTConstants.TYPE_INT_ARRAY;
} else {
throw new IllegalArgumentException("Invalid tag classs ("
+ clazz.getName() + ").");
@ -138,7 +138,7 @@ public final class NBTUtils {
/**
* Gets the class of a type of tag.
*
*
* @param type
* The type.
* @return The class.
@ -183,7 +183,7 @@ public final class NBTUtils {
private NBTUtils() {
}
/**
* Get child tag of a NBT structure.
*

Datei anzeigen

@ -93,9 +93,9 @@ public class BlockVector extends Vector {
*/
@Override
public int hashCode() {
return (Integer.valueOf((int) x).hashCode() << 19) ^
(Integer.valueOf((int) y).hashCode() << 12) ^
Integer.valueOf((int) z).hashCode();
return ((int) x << 19) ^
((int) y << 12) ^
(int) z;
}
@Override

Datei anzeigen

@ -42,7 +42,7 @@ public class BaseBlock {
* @param type
*/
public BaseBlock(int type) {
this.type = (short) type;
this(type, 0);
}
/**
@ -166,7 +166,7 @@ public class BaseBlock {
}
/**
*
*
*
* @param iter
* @return

Datei anzeigen

@ -25,25 +25,19 @@ import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
/**
* Represents chests.
*
* @author sk89q
*/
public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
/**
* Store the list of items.
*/
private BaseItemStack[] items;
public class ChestBlock extends ContainerBlock {
/**
* Construct the chest block.
*/
public ChestBlock() {
super(BlockID.CHEST);
items = new BaseItemStack[27];
super(BlockID.CHEST, 27);
}
/**
@ -52,8 +46,7 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB
* @param data
*/
public ChestBlock(int data) {
super(BlockID.CHEST, data);
items = new BaseItemStack[27];
super(BlockID.CHEST, data, 27);
}
/**
@ -63,24 +56,8 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB
* @param items
*/
public ChestBlock(int data, BaseItemStack[] items) {
super(BlockID.CHEST, data);
this.items = items;
}
/**
* Get the list of items.
*
* @return
*/
public BaseItemStack[] getItems() {
return items;
}
/**
* Set the list of items.
*/
public void setItems(BaseItemStack[] items) {
this.items = items;
super(BlockID.CHEST, data, 27);
setItems(items);
}
/**
@ -100,36 +77,8 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB
*/
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));
if(item.getEnchantments().size() > 0) {
Map<String, Tag> ench = new HashMap<String, Tag>();
CompoundTag compound = new CompoundTag("tag", ench);
List<Tag> list = new ArrayList<Tag>();
ListTag enchlist = new ListTag("ench", CompoundTag.class, list);
for(Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
CompoundTag enchantcompound = new CompoundTag(null, enchantment);
enchantment.put("id", new ShortTag("id", entry.getKey().shortValue()));
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
list.add(enchantcompound);
}
ench.put("ench", enchlist);
data.put("tag", compound);
}
itemsList.add(itemTag);
}
}
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(getItems())));
return values;
}
@ -150,39 +99,15 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB
throw new DataException("'Chest' tile entity expected");
}
ListTag items = (ListTag) NBTUtils.getChildTag(values, "Items", ListTag.class);
BaseItemStack[] newItems = new BaseItemStack[27];
for (Tag tag : items.getValue()) {
List<CompoundTag> items = new ArrayList<CompoundTag>();
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
if (!(tag instanceof CompoundTag)) {
throw new DataException("CompoundTag expected as child tag of Chest's Items");
}
CompoundTag item = (CompoundTag) tag;
Map<String, Tag> itemValues = item.getValue();
short id = NBTUtils.getChildTag(itemValues, "id", ShortTag.class).getValue();
short damage = NBTUtils.getChildTag(itemValues, "Damage", ShortTag.class).getValue();
byte count = NBTUtils.getChildTag(itemValues, "Count", ByteTag.class).getValue();
byte slot = NBTUtils.getChildTag(itemValues, "Slot", ByteTag.class).getValue();
if (slot >= 0 && slot <= 26) {
BaseItemStack itemstack = new BaseItemStack(id, count, damage);
if(itemValues.containsKey("tag")) {
ListTag ench = (ListTag) NBTUtils.getChildTag(itemValues, "tag", CompoundTag.class).getValue().get("ench");
for(Tag e : ench.getValue()) {
Map<String, Tag> vars = ((CompoundTag) e).getValue();
short enchid = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
short enchlvl = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
itemstack.getEnchantments().put((int) enchid, (int)enchlvl);
}
}
newItems[slot] = itemstack;
}
items.add((CompoundTag) tag);
}
this.items = newItems;
setItems(deserializeInventory(items));
}
}

Datei anzeigen

@ -19,23 +19,119 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.data.DataException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a block that stores items.
*
*
* @author sk89q
*/
public interface ContainerBlock {
public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
private BaseItemStack[] items;
public ContainerBlock(int type, int inventorySize) {
super(type);
this.items = new BaseItemStack[inventorySize];
}
public ContainerBlock(int type, int data, int inventorySize) {
super(type, data);
this.items = new BaseItemStack[inventorySize];
}
/**
* Get the list of items.
*
* @return
*/
public BaseItemStack[] getItems();
public BaseItemStack[] getItems() {
return this.items;
}
/**
* Set the list of items.
*
* @param items
*
* @param items
*/
public void setItems(BaseItemStack[] items);
public void setItems(BaseItemStack[] items) {
this.items = items;
}
public Map<String, Tag> serializeItem(BaseItemStack item) {
Map<String, Tag> data = new HashMap<String, Tag>();
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()));
if (item.getEnchantments().size() > 0) {
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
enchantment.put("id", new ShortTag("id", entry.getKey().shortValue()));
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
enchantmentList.add(new CompoundTag(null, enchantment));
}
Map<String, Tag> auxData = new HashMap<String, Tag>();
auxData.put("ench", new ListTag("ench", CompoundTag.class, enchantmentList));
data.put("tag", new CompoundTag("tag", auxData));
}
return data;
}
public BaseItemStack deserializeItem(Map<String, Tag> data) throws DataException {
short id = NBTUtils.getChildTag(data, "id", ShortTag.class).getValue();
short damage = NBTUtils.getChildTag(data, "Damage", ShortTag.class).getValue();
byte count = NBTUtils.getChildTag(data, "Count", ByteTag.class).getValue();
BaseItemStack stack = new BaseItemStack(id, count, damage);
if (data.containsKey("tag")) {
Map<String, Tag> auxData = NBTUtils.getChildTag(data, "tag", CompoundTag.class).getValue();
ListTag ench = (ListTag)auxData.get("ench");
for(Tag e : ench.getValue()) {
Map<String, Tag> vars = ((CompoundTag) e).getValue();
short enchId = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
short enchLevel = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
stack.getEnchantments().put((int) enchId, (int) enchLevel);
}
}
return stack;
}
public BaseItemStack[] deserializeInventory(List<CompoundTag> items) throws DataException {
BaseItemStack[] stacks = new BaseItemStack[items.size()];
for (CompoundTag tag : items) {
Map<String, Tag> item = tag.getValue();
BaseItemStack stack = deserializeItem(item);
byte slot = NBTUtils.getChildTag(item, "Slot", ByteTag.class).getValue();
if (slot >= 0 && slot < stacks.length) {
stacks[slot] = stack;
}
}
return stacks;
}
public List<CompoundTag> serializeInventory(BaseItemStack[] items) {
List<CompoundTag> tags = new ArrayList<CompoundTag>();
for (int i = 0; i < items.length; ++i) {
if (items[i] != null) {
Map<String, Tag> tagData = serializeItem(items[i]);
tagData.put("Slot", new ByteTag("Slot", (byte) i));
tags.add(new CompoundTag("", tagData));
}
}
return tags;
}
}

Datei anzeigen

@ -32,18 +32,13 @@ import java.util.Map.Entry;
*
* @author sk89q
*/
public class DispenserBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
/**
* Store the list of items.
*/
private BaseItemStack[] items;
public class DispenserBlock extends ContainerBlock {
/**
* Construct the dispenser block.
*/
public DispenserBlock() {
super(BlockID.DISPENSER);
items = new BaseItemStack[9];
super(BlockID.DISPENSER, 9);
}
/**
@ -52,8 +47,7 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai
* @param data
*/
public DispenserBlock(int data) {
super(BlockID.DISPENSER, data);
items = new BaseItemStack[9];
super(BlockID.DISPENSER, data, 9);
}
/**
@ -63,24 +57,8 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai
* @param items
*/
public DispenserBlock(int data, BaseItemStack[] items) {
super(BlockID.DISPENSER, data);
this.items = items;
}
/**
* Get the list of items.
*
* @return
*/
public BaseItemStack[] getItems() {
return items;
}
/**
* Set the list of items.
*/
public void setItems(BaseItemStack[] items) {
this.items = items;
super(BlockID.DISPENSER, data, 9);
this.setItems(items);
}
/**
@ -100,36 +78,8 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai
*/
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));
if(item.getEnchantments().size() > 0) {
Map<String, Tag> ench = new HashMap<String, Tag>();
CompoundTag compound = new CompoundTag("tag", ench);
List<Tag> list = new ArrayList<Tag>();
ListTag enchlist = new ListTag("ench", CompoundTag.class, list);
for(Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
CompoundTag enchantcompound = new CompoundTag(null, enchantment);
enchantment.put("id", new ShortTag("id", entry.getKey().shortValue()));
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
list.add(enchantcompound);
}
ench.put("ench", enchlist);
data.put("tag", compound);
}
itemsList.add(itemTag);
}
}
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(getItems())));
return values;
}
@ -150,39 +100,15 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai
throw new DataException("'Trap' tile entity expected");
}
ListTag items = (ListTag) NBTUtils.getChildTag(values, "Items", ListTag.class);
BaseItemStack[] newItems = new BaseItemStack[9];
for (Tag tag : items.getValue()) {
List<CompoundTag> items = new ArrayList<CompoundTag>();
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).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 = NBTUtils.getChildTag(itemValues, "id", ShortTag.class).getValue();
short damage = NBTUtils.getChildTag(itemValues, "Damage", ShortTag.class).getValue();
byte count = NBTUtils.getChildTag(itemValues, "Count", ByteTag.class).getValue();
byte slot = NBTUtils.getChildTag(itemValues, "Slot", ByteTag.class).getValue();
if (slot >= 0 && slot <= 8) {
BaseItemStack itemstack = new BaseItemStack(id, count, damage);
if(itemValues.containsKey("tag")) {
ListTag ench = (ListTag) NBTUtils.getChildTag(itemValues, "tag", CompoundTag.class).getValue().get("ench");
for(Tag e : ench.getValue()) {
Map<String, Tag> vars = ((CompoundTag) e).getValue();
short enchid = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
short enchlvl = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
itemstack.getEnchantments().put((int) enchid, (int)enchlvl);
}
}
newItems[slot] = itemstack;
}
items.add((CompoundTag) tag);
}
this.items = newItems;
setItems(deserializeInventory(items));
}
}

Datei anzeigen

@ -21,22 +21,18 @@ package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.data.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
/**
* Represents furnaces.
*
* @author sk89q
*/
public class FurnaceBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
/**
* Store the list of items.
*/
private BaseItemStack[] items;
public class FurnaceBlock extends ContainerBlock {
/**
* Fuel time.
@ -54,8 +50,7 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe
* @param type
*/
public FurnaceBlock(int type) {
super(type);
items = new BaseItemStack[2];
super(type, 2);
}
/**
@ -65,8 +60,7 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe
* @param data
*/
public FurnaceBlock(int type, int data) {
super(type, data);
items = new BaseItemStack[2];
super(type, data, 2);
}
/**
@ -77,24 +71,8 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe
* @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.
*/
public void setItems(BaseItemStack[] items) {
this.items = items;
super(type, data, 2);
setItems(items);
}
/**
@ -142,36 +120,8 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe
*/
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));
if(item.getEnchantments().size() > 0) {
Map<String, Tag> ench = new HashMap<String, Tag>();
CompoundTag compound = new CompoundTag("tag", ench);
List<Tag> list = new ArrayList<Tag>();
ListTag enchlist = new ListTag("ench", CompoundTag.class, list);
for(Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
CompoundTag enchantcompound = new CompoundTag(null, enchantment);
enchantment.put("id", new ShortTag("id", entry.getKey().shortValue()));
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
list.add(enchantcompound);
}
ench.put("ench", enchlist);
data.put("tag", compound);
}
itemsList.add(itemTag);
}
}
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(getItems())));
values.put("BurnTime", new ShortTag("BurnTime", burnTime));
values.put("CookTime", new ShortTag("CookTime", cookTime));
return values;
@ -194,40 +144,17 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe
throw new DataException("'Furnace' tile entity expected");
}
ListTag items = (ListTag) NBTUtils.getChildTag(values, "Items", ListTag.class);
BaseItemStack[] newItems = new BaseItemStack[3];
ListTag items = NBTUtils.getChildTag(values, "Items", ListTag.class);
List<CompoundTag> compound = new ArrayList<CompoundTag>();
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 = NBTUtils.getChildTag(itemValues, "id", ShortTag.class).getValue();
short damage = NBTUtils.getChildTag(itemValues, "Damage", ShortTag.class).getValue();
byte count = NBTUtils.getChildTag(itemValues, "Count", ByteTag.class).getValue();
byte slot = NBTUtils.getChildTag(itemValues, "Slot", ByteTag.class).getValue();
if (slot >= 0 && slot <= 2) {
BaseItemStack itemstack = new BaseItemStack(id, count, damage);
if(itemValues.containsKey("tag")) {
ListTag ench = (ListTag) NBTUtils.getChildTag(itemValues, "tag", CompoundTag.class).getValue().get("ench");
for(Tag e : ench.getValue()) {
Map<String, Tag> vars = ((CompoundTag) e).getValue();
short enchid = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
short enchlvl = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
itemstack.getEnchantments().put((int) enchid, (int)enchlvl);
}
}
newItems[slot] = itemstack;
throw new DataException("CompoundTag expected as child tag of Furnace Items");
}
compound.add((CompoundTag) tag);
}
this.items = newItems;
setItems(deserializeInventory(compound));
t = values.get("BurnTime");
if (t instanceof ShortTag) {

Datei anzeigen

@ -151,8 +151,8 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
throw new DataException("'MobSpawner' tile entity expected");
}
StringTag mobTypeTag = (StringTag) NBTUtils.getChildTag(values, "EntityId", StringTag.class);
ShortTag delayTag = (ShortTag) NBTUtils.getChildTag(values, "Delay", ShortTag.class);
StringTag mobTypeTag = NBTUtils.getChildTag(values, "EntityId", StringTag.class);
ShortTag delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
this.mobType = mobTypeTag.getValue();
this.delay = delayTag.getValue();

Datei anzeigen

@ -55,7 +55,7 @@ public class NoteBlock extends BaseBlock implements TileEntityBlock {
/**
* Construct the note block.
*
* @param data
* @param data
* @param note
*/
public NoteBlock(int data, byte note) {

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.data.*;
import java.util.Map;
/**
@ -29,12 +30,13 @@ import java.util.Map;
* @author sk89q
*/
public interface TileEntityBlock {
/**
* Return the name of the title entity ID.
*
* @return tile entity ID
*/
public String getTileEntityID();
public abstract String getTileEntityID();
/**
* Store additional tile entity data.
@ -42,7 +44,7 @@ public interface TileEntityBlock {
* @return map of values
* @throws DataException When invalid data is encountered
*/
public Map<String, Tag> toTileEntityNBT()
public abstract Map<String, Tag> toTileEntityNBT()
throws DataException;
/**
@ -51,6 +53,8 @@ public interface TileEntityBlock {
* @param values map of data
* @throws DataException When invalid data is encountered
*/
public void fromTileEntityNBT(Map<String, Tag> values)
public abstract void fromTileEntityNBT(Map<String, Tag> values)
throws DataException;
}

Datei anzeigen

@ -31,6 +31,11 @@ import com.sk89q.worldedit.*;
* @author sk89q
*/
public abstract class ChunkStore {
/**
* >> to chunk
* << from chunk
*/
public static final int CHUNK_SHIFTS = 4;
/**
* Convert a position to a chunk.
*
@ -66,7 +71,7 @@ public abstract class ChunkStore {
*/
public Chunk getChunk(Vector2D pos, LocalWorld world)
throws DataException, IOException {
CompoundTag tag = getChunkTag(pos, world);
Map<String, Tag> tags = tag.getValue();
if(tags.containsKey("Sections")) {