the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Tag.h"
3#include "EndTag.h"
4#include "ByteTag.h"
5#include "ByteArrayTag.h"
6#include "DoubleTag.h"
7#include "FloatTag.h"
8#include "IntTag.h"
9#include "LongTag.h"
10#include "ShortTag.h"
11#include "StringTag.h"
12#include "ListTag.h"
13#include "CompoundTag.h"
14
15Tag::Tag(const wstring &name)
16{
17 if (name.empty())
18 {
19 this->name = L"";
20 }
21 else
22 {
23 this->name = name;
24 }
25}
26
27// 4J - Was Object obj
28bool Tag::equals(Tag *obj)
29{
30 if (obj == NULL )// || !(obj instanceof Tag))
31 {
32 return false;
33 }
34 Tag *o = (Tag *) obj;
35 if (getId() != o->getId())
36 {
37 return false;
38 }
39 if ( (name.empty() && !o->name.empty()) || (!name.empty() && o->name.empty()))
40 {
41 return false;
42 }
43 if (!name.empty() && name.compare(o->name) != 0)
44 {
45 return false;
46 }
47 return true;
48}
49
50void Tag::print(ostream out)
51{
52 out << "";
53}
54
55void Tag::print(char *prefix, wostream out)
56{
57 wstring name = getName();
58
59 out << prefix;
60 out << getTagName(getId());
61 if ( name.length() > 0)
62 {
63 out << L"(\"" << name << L"\")";
64 }
65 out << L": ";
66 out << toString() << endl;
67}
68
69wstring Tag::getName()
70{
71 return name;
72}
73
74Tag *Tag::setName(const wstring& name)
75{
76 this->name = name;
77 return this;
78}
79
80Tag *Tag::readNamedTag(DataInput *dis)
81{
82 return readNamedTag(dis,0);
83}
84
85Tag *Tag::readNamedTag(DataInput *dis, int tagDepth)
86{
87 byte type = dis->readByte();
88 if (type == 0) return new EndTag();
89
90 // 4J Stu - readByte can return -1, so if it's that then also mark as the end tag
91 if(type == 255)
92 {
93 app.DebugPrintf("readNamedTag read a type of 255\n");
94#ifndef _CONTENT_PACKAGE
95 __debugbreak();
96#endif
97 return new EndTag();
98 }
99
100 wstring name = dis->readUTF();//new String(bytes, "UTF-8");
101
102 Tag *tag = newTag(type, name);
103 // short length = dis.readShort();
104 // byte[] bytes = new byte[length];
105 // dis.readFully(bytes);
106
107 tag->load(dis, tagDepth);
108 return tag;
109}
110
111void Tag::writeNamedTag(Tag *tag, DataOutput *dos)
112{
113 dos->writeByte(tag->getId());
114 if (tag->getId() == Tag::TAG_End) return;
115
116 // byte[] bytes = tag.getName().getBytes("UTF-8");
117 // dos.writeShort(bytes.length);
118 // dos.write(bytes);
119 dos->writeUTF(tag->getName());
120
121 tag->write(dos);
122}
123
124Tag *Tag::newTag(byte type, const wstring &name)
125{
126 switch (type)
127 {
128 case TAG_End:
129 return new EndTag(name);
130 case TAG_Byte:
131 return new ByteTag(name);
132 case TAG_Short:
133 return new ShortTag(name);
134 case TAG_Int:
135 return new IntTag(name);
136 case TAG_Long:
137 return new LongTag(name);
138 case TAG_Float:
139 return new FloatTag(name);
140 case TAG_Double:
141 return new DoubleTag(name);
142 case TAG_Byte_Array:
143 return new ByteArrayTag(name);
144 case TAG_Int_Array:
145 return new IntArrayTag(name);
146 case TAG_String:
147 return new StringTag(name);
148 case TAG_List:
149 return new ListTag<Tag>(name);
150 case TAG_Compound:
151 return new CompoundTag(name);
152 }
153 return NULL;
154}
155
156wchar_t *Tag::getTagName(byte type)
157{
158 switch (type)
159 {
160 case TAG_End:
161 return L"TAG_End";
162 case TAG_Byte:
163 return L"TAG_Byte";
164 case TAG_Short:
165 return L"TAG_Short";
166 case TAG_Int:
167 return L"TAG_Int";
168 case TAG_Long:
169 return L"TAG_Long";
170 case TAG_Float:
171 return L"TAG_Float";
172 case TAG_Double:
173 return L"TAG_Double";
174 case TAG_Byte_Array:
175 return L"TAG_Byte_Array";
176 case TAG_Int_Array:
177 return L"TAG_Int_Array";
178 case TAG_String:
179 return L"TAG_String";
180 case TAG_List:
181 return L"TAG_List";
182 case TAG_Compound:
183 return L"TAG_Compound";
184 }
185 return L"UNKNOWN";
186}