Skip to content

Commit

Permalink
Save TagType instead of class name in ListTag
Browse files Browse the repository at this point in the history
Implements #11
  • Loading branch information
piegamesde committed May 2, 2019
1 parent 5eff3fe commit 24b7946
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/flowpowered/nbt/ListTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> {
/**
* The type of entries within this list.
*/
private final Class<T> type;
private final TagType type;
/**
* The value.
*/
Expand All @@ -47,7 +47,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> {
* @param type The type of item in the list.
* @param value The value.
*/
public ListTag(String name, Class<T> type, List<T> value) {
public ListTag(String name, TagType type, List<T> value) {
super(TagType.TAG_LIST, name);
this.type = type;
this.value = value;
Expand All @@ -58,7 +58,7 @@ public ListTag(String name, Class<T> type, List<T> value) {
*
* @return The type of item in this list.
*/
public Class<T> getElementType() {
public TagType getElementType() {
return type;
}

Expand All @@ -81,7 +81,7 @@ public String toString() {
}

StringBuilder bldr = new StringBuilder();
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(TagType.getByTagClass(type).getTypeName()).append("\r\n{\r\n");
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(type.getTypeName()).append("\r\n{\r\n");
for (Tag<?> t : value) {
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/flowpowered/nbt/regionfile/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.flowpowered.nbt.IntTag;
import com.flowpowered.nbt.ListTag;
import com.flowpowered.nbt.Tag;
import com.flowpowered.nbt.TagType;
import com.flowpowered.nbt.stream.NBTInputStream;
import com.flowpowered.nbt.stream.NBTOutputStream;

Expand Down Expand Up @@ -267,7 +268,7 @@ public static void moveChunk(CompoundTag level, int sourceX, int sourceZ, int de
/* Update entities */
for (CompoundTag entity : ((ListTag<CompoundTag>) value.get("Entities")).getValue()) {
List<DoubleTag> pos = ((ListTag<DoubleTag>) entity.getValue().get("Pos")).getValue();
entity.getValue().put(new ListTag<>("Pos", DoubleTag.class,
entity.getValue().put(new ListTag<>("Pos", TagType.TAG_DOUBLE,
Arrays.asList(
new DoubleTag(null, pos.get(0).getValue() + diffX),
new DoubleTag(null, pos.get(1).getValue() + diffY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private Tag readTagPayload(TagType type, String name, int depth) throws IOExcept
tagList.add(tag);
}

return new ListTag(name, clazz, tagList);
return new ListTag(name, childType, tagList);

case TAG_COMPOUND:
CompoundMap compoundTagList = new CompoundMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
*/
@SuppressWarnings("unchecked")
private void writeListTagPayload(ListTag<?> tag) throws IOException {
Class<? extends Tag<?>> clazz = tag.getElementType();
List<Tag<?>> tags = (List<Tag<?>>) tag.getValue();
int size = tags.size();

dataOut.writeByte(TagType.getByTagClass(clazz).getId());
dataOut.writeByte(tag.getElementType().getId());
dataOut.writeInt(size);
for (Tag<?> tag1 : tags) {
writeTagPayload(tag1);
Expand Down

0 comments on commit 24b7946

Please sign in to comment.