mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-20 09:57:10 +00:00
TU19: merge Minecraft.World/IO
This commit is contained in:
parent
11a0440998
commit
993617025b
|
|
@ -37,6 +37,12 @@ enum ESaveVersions {
|
||||||
// the compressed storage formats
|
// the compressed storage formats
|
||||||
SAVE_FILE_VERSION_COMPRESSED_CHUNK_STORAGE,
|
SAVE_FILE_VERSION_COMPRESSED_CHUNK_STORAGE,
|
||||||
|
|
||||||
|
// This is the version at which we added inhabited time to chunk (1.6.4)
|
||||||
|
SAVE_FILE_VERSION_CHUNK_INHABITED_TIME,
|
||||||
|
|
||||||
|
// 4J Stu - If you add a new version here, the save conversion tool will
|
||||||
|
// also need updated to be able to read this new format
|
||||||
|
|
||||||
SAVE_FILE_VERSION_NEXT,
|
SAVE_FILE_VERSION_NEXT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@ public:
|
||||||
IntArrayTag* o = (IntArrayTag*)obj;
|
IntArrayTag* o = (IntArrayTag*)obj;
|
||||||
return ((data.data == NULL && o->data.data == NULL) ||
|
return ((data.data == NULL && o->data.data == NULL) ||
|
||||||
(data.data != NULL && data.length == o->data.length &&
|
(data.data != NULL && data.length == o->data.length &&
|
||||||
memcmp(data.data, o->data.data, data.length) == 0));
|
memcmp(data.data, o->data.data,
|
||||||
|
data.length * sizeof(int)) == 0));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ public:
|
||||||
AUTO_VAR(itEnd, list.end());
|
AUTO_VAR(itEnd, list.end());
|
||||||
for (AUTO_VAR(it, list.begin()); it != itEnd; it++) (*it)->write(dos);
|
for (AUTO_VAR(it, list.begin()); it != itEnd; it++) (*it)->write(dos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(DataInput* dis) {
|
void load(DataInput* dis) {
|
||||||
type = dis->readByte();
|
type = dis->readByte();
|
||||||
int size = dis->readInt();
|
int size = dis->readInt();
|
||||||
|
|
@ -46,7 +47,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(char* prefix, std::ostream out) {
|
void print(char* prefix, std::ostream out) {
|
||||||
printf(prefix);
|
Tag::print(prefix, out);
|
||||||
|
|
||||||
out << prefix << "{" << std::endl;
|
out << prefix << "{" << std::endl;
|
||||||
|
|
||||||
|
|
@ -54,13 +55,18 @@ public:
|
||||||
strcpy(newPrefix, prefix);
|
strcpy(newPrefix, prefix);
|
||||||
strcat(newPrefix, " ");
|
strcat(newPrefix, " ");
|
||||||
AUTO_VAR(itEnd, list.end());
|
AUTO_VAR(itEnd, list.end());
|
||||||
for (AUTO_VAR(it, list.begin()); it != itEnd; it++) printf(newPrefix);
|
for (AUTO_VAR(it, list.begin()); it != itEnd; it++) {
|
||||||
|
(*it)->print(newPrefix, out);
|
||||||
|
}
|
||||||
delete[] newPrefix;
|
delete[] newPrefix;
|
||||||
out << prefix << "}" << std::endl;
|
out << prefix << "}" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(T* tag) {
|
void add(T* tag) {
|
||||||
type = tag->getId();
|
type = tag->getId();
|
||||||
|
// 4J: List tag write/load doesn't preserve tag names so remove them so
|
||||||
|
// we can safely do comparisons. This is the least invasive fix.
|
||||||
|
tag->setName(L"");
|
||||||
list.push_back(tag);
|
list.push_back(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +81,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag* copy() {
|
virtual Tag* copy() {
|
||||||
ListTag<T>* res = new ListTag<T>(getName());
|
ListTag<T>* res = new ListTag<T>(getName());
|
||||||
res->type = type;
|
res->type = type;
|
||||||
AUTO_VAR(itEnd, list.end());
|
AUTO_VAR(itEnd, list.end());
|
||||||
|
|
@ -86,44 +92,35 @@ public:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
virtual bool equals(Tag* obj) {
|
||||||
bool equals(Object obj)
|
if (Tag::equals(obj)) {
|
||||||
{
|
ListTag* o = (ListTag*)obj;
|
||||||
if (Tag::equals(obj))
|
if (type == o->type) {
|
||||||
{
|
bool equal = false;
|
||||||
ListTag *o = (ListTag *) obj;
|
if (list.size() == o->list.size()) {
|
||||||
if (type == o->type)
|
equal = true;
|
||||||
{
|
AUTO_VAR(itEnd, list.end());
|
||||||
bool equal = false;
|
// 4J Stu - Pretty inefficient method, but acceptable for
|
||||||
if(list.size() == o->list.size())
|
// how small and infrequent these comparisons are.
|
||||||
{
|
for (AUTO_VAR(it, list.begin()); it != itEnd; ++it) {
|
||||||
equal = true;
|
bool thisMatches = false;
|
||||||
AUTO_VAR(itEnd, list.end());
|
for (AUTO_VAR(it2, o->list.begin());
|
||||||
// 4J Stu - Pretty inefficient method, but I think we can live with it give how often it will happen, and the small sizes of the data sets
|
it2 != o->list.end(); ++it2) {
|
||||||
for (AUTO_VAR(it, list.begin()); it != itEnd; it++)
|
if ((*it)->equals(*it2)) {
|
||||||
{
|
thisMatches = true;
|
||||||
bool thisMatches = false;
|
break;
|
||||||
for(AUTO_VAR(it2, o->list.begin()); it != o->list.end(); ++it2)
|
}
|
||||||
{
|
}
|
||||||
if((*it)->equals(*it2))
|
if (!thisMatches) {
|
||||||
{
|
equal = false;
|
||||||
thisMatches = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!thisMatches)
|
|
||||||
{
|
|
||||||
equal = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//return list->equals(o->list);
|
return equal;
|
||||||
return equal;
|
}
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
@ -323,6 +323,17 @@ short DataInputStream::readShort() {
|
||||||
return (short)((a << 8) | (b & 0xff));
|
return (short)((a << 8) | (b & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned short DataInputStream::readUnsignedShort() {
|
||||||
|
if (stream == NULL) {
|
||||||
|
app.DebugPrintf(
|
||||||
|
"DataInputStream::readUnsignedShort() but underlying stream is NULL\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int a = stream->read();
|
||||||
|
int b = stream->read();
|
||||||
|
return static_cast<unsigned short>(((a & 0xff) << 8) | (b & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
// Reads in a string that has been encoded using a modified UTF-8 format. The
|
// Reads in a string that has been encoded using a modified UTF-8 format. The
|
||||||
// general contract of readUTF is that it reads a representation of a Unicode
|
// general contract of readUTF is that it reads a representation of a Unicode
|
||||||
// character string encoded in modified UTF-8 format; this string of characters
|
// character string encoded in modified UTF-8 format; this string of characters
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,13 @@ public:
|
||||||
virtual double readDouble();
|
virtual double readDouble();
|
||||||
virtual float readFloat();
|
virtual float readFloat();
|
||||||
virtual int readInt();
|
virtual int readInt();
|
||||||
virtual int64_t readLong();
|
virtual __int64 readLong();
|
||||||
virtual short readShort();
|
virtual short readShort();
|
||||||
|
virtual unsigned short readUnsignedShort();
|
||||||
virtual std::wstring readUTF();
|
virtual std::wstring readUTF();
|
||||||
void deleteChildStream();
|
void deleteChildStream();
|
||||||
virtual int readUTFChar();
|
virtual int readUTFChar();
|
||||||
virtual PlayerUID readPlayerUID(); // 4J Added
|
virtual PlayerUID readPlayerUID(); // 4J Added
|
||||||
virtual int64_t skip(int64_t n);
|
virtual __int64 skip(__int64 n);
|
||||||
virtual int skipBytes(int n);
|
virtual int skipBytes(int n);
|
||||||
};
|
};
|
||||||
|
|
@ -146,6 +146,17 @@ void DataOutputStream::writeShort(short a) {
|
||||||
written += 2;
|
written += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataOutputStream::writeUnsignedShort(unsigned short a) {
|
||||||
|
if (stream == NULL) {
|
||||||
|
app.DebugPrintf(
|
||||||
|
"DataOutputStream::writeUnsignedShort() but underlying stream is NULL\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stream->write(static_cast<unsigned int>((a >> 8) & 0xff));
|
||||||
|
stream->write(static_cast<unsigned int>(a & 0xff));
|
||||||
|
written += 2;
|
||||||
|
}
|
||||||
|
|
||||||
// Writes a char to the underlying output stream as a 2-byte value, high byte
|
// Writes a char to the underlying output stream as a 2-byte value, high byte
|
||||||
// first. If no exception is thrown, the counter written is incremented by 2.
|
// first. If no exception is thrown, the counter written is incremented by 2.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ public:
|
||||||
virtual void writeInt(int a);
|
virtual void writeInt(int a);
|
||||||
virtual void writeLong(int64_t a);
|
virtual void writeLong(int64_t a);
|
||||||
virtual void writeShort(short a);
|
virtual void writeShort(short a);
|
||||||
|
virtual void writeUnsignedShort(unsigned short a);
|
||||||
virtual void writeChar(wchar_t a);
|
virtual void writeChar(wchar_t a);
|
||||||
virtual void writeChars(const std::wstring& a);
|
virtual void writeChars(const std::wstring& a);
|
||||||
virtual void writeBoolean(bool b);
|
virtual void writeBoolean(bool b);
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@
|
||||||
#include "InputStream.h"
|
#include "InputStream.h"
|
||||||
|
|
||||||
InputStream* InputStream::getResourceAsStream(const std::wstring& fileName) {
|
InputStream* InputStream::getResourceAsStream(const std::wstring& fileName) {
|
||||||
return new FileInputStream(File(fileName));
|
File file(fileName);
|
||||||
|
return file.exists() ? new FileInputStream(file) : NULL;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue