Small cleanup of chunk reading

Dieser Commit ist enthalten in:
zml2008 2011-12-06 07:58:34 -08:00
Ursprung c2460a6305
Commit d0367bfd5c

Datei anzeigen

@ -48,14 +48,14 @@ public class Chunk {
public Chunk(CompoundTag tag) throws DataException { public Chunk(CompoundTag tag) throws DataException {
rootTag = tag; rootTag = tag;
blocks = ((ByteArrayTag) getChildTag( blocks = getChildTag(
rootTag.getValue(), "Blocks", ByteArrayTag.class)).getValue(); rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue();
data = ((ByteArrayTag) getChildTag( data = getChildTag(
rootTag.getValue(), "Data", ByteArrayTag.class)).getValue(); rootTag.getValue(), "Data", ByteArrayTag.class).getValue();
rootX = ((IntTag) getChildTag( rootX = getChildTag(
rootTag.getValue(), "xPos", IntTag.class)).getValue(); rootTag.getValue(), "xPos", IntTag.class).getValue();
rootZ = ((IntTag) getChildTag( rootZ = getChildTag(
rootTag.getValue(), "zPos", IntTag.class)).getValue(); rootTag.getValue(), "zPos", IntTag.class).getValue();
if (blocks.length != 32768) { if (blocks.length != 32768) {
throw new InvalidFormatException("Chunk blocks byte array expected " throw new InvalidFormatException("Chunk blocks byte array expected "
@ -120,8 +120,8 @@ public class Chunk {
* @throws DataException * @throws DataException
*/ */
private void populateTileEntities() throws DataException { private void populateTileEntities() throws DataException {
List<Tag> tags = (List<Tag>) ((ListTag) getChildTag( List<Tag> tags = getChildTag(
rootTag.getValue(), "TileEntities", ListTag.class)) rootTag.getValue(), "TileEntities", ListTag.class)
.getValue(); .getValue();
tileEntities = new HashMap<BlockVector, Map<String, Tag>>(); tileEntities = new HashMap<BlockVector, Map<String, Tag>>();
@ -224,9 +224,8 @@ public class Chunk {
* @return child tag * @return child tag
* @throws InvalidFormatException * @throws InvalidFormatException
*/ */
public static Tag getChildTag(Map<String, Tag> items, String key, public static <T extends Tag> T getChildTag(Map<String,Tag> items, String key,
Class<? extends Tag> expected) Class<T> expected) throws InvalidFormatException {
throws InvalidFormatException {
if (!items.containsKey(key)) { if (!items.containsKey(key)) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag"); throw new InvalidFormatException("Missing a \"" + key + "\" tag");
} }
@ -234,6 +233,6 @@ public class Chunk {
if (!expected.isInstance(tag)) { if (!expected.isInstance(tag)) {
throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName()); throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName());
} }
return tag; return (T) tag;
} }
} }