refactor: split java libs and nbt into separate projects

This commit is contained in:
Tropical
2026-03-30 12:54:00 -05:00
parent 5c17c5c9ff
commit da1d6d8e97
535 changed files with 1286 additions and 1208 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class Arrays {
public:
static void fill(doubleArray arr, unsigned int from, unsigned int to,
double value) {
assert(from >= 0);
assert(from <= to);
assert(to <= arr.length);
std::fill(arr.data + from, arr.data + to, value);
}
static void fill(floatArray arr, unsigned int from, unsigned int to,
float value) {
assert(from >= 0);
assert(from <= to);
assert(to <= arr.length);
std::fill(arr.data + from, arr.data + to, value);
}
static void fill(BiomeArray arr, unsigned int from, unsigned int to,
Biome* value) {
assert(from >= 0);
assert(from <= to);
assert(to <= arr.length);
std::fill(arr.data + from, arr.data + to, value);
}
static void fill(byteArray arr, unsigned int from, unsigned int to,
uint8_t value) {
assert(from >= 0);
assert(from <= to);
assert(to <= arr.length);
std::fill(arr.data + from, arr.data + to, value);
}
static void fill(byteArray arr, uint8_t value) {
std::fill(arr.data, arr.data + arr.length, value);
}
};

View File

@@ -0,0 +1,36 @@
#pragma once
// A buffer is a linear, finite sequence of elements of a specific primitive
// type. Aside from its content, the essential properties of a buffer are its
// capacity, limit, and position:
//
// A buffer's capacity is the number of elements it contains. The capacity of a
// buffer is never negative and never changes.
//
// A buffer's limit is the index of the first element that should not be read or
// written. A buffer's limit is never negative and is never greater than its
// capacity.
//
// A buffer's position is the index of the next element to be read or written.
// A buffer's position is never negative and is never greater than its limit.
class Buffer {
protected:
const unsigned int m_capacity;
unsigned int m_position;
unsigned int m_limit;
unsigned int m_mark;
bool hasBackingArray;
public:
Buffer(unsigned int capacity);
virtual ~Buffer() {}
Buffer* clear();
Buffer* limit(unsigned int newLimit);
unsigned int limit();
Buffer* position(unsigned int newPosition);
unsigned int position();
unsigned int remaining();
virtual Buffer* flip() = 0;
};

View File

@@ -0,0 +1,46 @@
#pragma once
#include <cstdint>
#include "Buffer.h"
#include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "../../../Minecraft.World/ConsoleHelpers/Definitions.h" // 4jcraft TODO
class IntBuffer;
class FloatBuffer;
class ByteBuffer : public Buffer {
protected:
uint8_t* buffer;
ByteOrder byteOrder;
public:
ByteBuffer(unsigned int capacity);
static ByteBuffer* allocateDirect(int capacity);
ByteBuffer(unsigned int capacity, uint8_t* backingArray);
virtual ~ByteBuffer();
static ByteBuffer* wrap(byteArray& b);
static ByteBuffer* allocate(unsigned int capacity);
void order(ByteOrder a);
ByteBuffer* flip();
uint8_t* getBuffer();
int getSize();
int getInt();
int getInt(unsigned int index);
void get(byteArray) {} // 4J - TODO
uint8_t get(int index);
int64_t getLong();
short getShort();
void getShortArray(shortArray& s);
ByteBuffer* put(int index, uint8_t b);
ByteBuffer* putInt(int value);
ByteBuffer* putInt(unsigned int index, int value);
ByteBuffer* putShort(short value);
ByteBuffer* putShortArray(shortArray& s);
ByteBuffer* putLong(int64_t value);
ByteBuffer* put(byteArray inputArray);
byteArray array();
IntBuffer* asIntBuffer();
FloatBuffer* asFloatBuffer();
};

View File

@@ -0,0 +1,758 @@
#pragma once
class InputStream;
// This file aims to provide functionality to mimic the subset of java's Class
// class that we require. Classes that require this functionality derive from
// BaseObject, and each contain a unique nested class definition Class. There
// are #defines here to simplify declaring classes with this added
// functionality.
// 0b FFFF CCCC CCCC CCCC CCCC CCCC CCEE EEEE
// |||| |||| |||| |||| |||| |||| |||| ||||
// |||| |||| |||| |||| |||| |||| |||| |||\- BIT00: ENUM:
// |||| |||| |||| |||| |||| |||| |||| ||\-- BIT01: ENUM:
// |||| |||| |||| |||| |||| |||| |||| |\--- BIT02: ENUM:
// |||| |||| |||| |||| |||| |||| |||| \---- BIT03: ENUM:
// |||| |||| |||| |||| |||| |||| ||||
// |||| |||| |||| |||| |||| |||| |||\------ BIT04: ENUM:
// |||| |||| |||| |||| |||| |||| ||\------- BIT05: ENUM:
// |||| |||| |||| |||| |||| |||| |\-------- BIT06: CLASS: WATER_MOB
// |||| |||| |||| |||| |||| |||| \--------- BIT07: CLASS: AMBIENT_MOB
// |||| |||| |||| |||| |||| ||||
// |||| |||| |||| |||| |||| |||\----------- BIT08: CLASS: !ENTITY (so
// we can hide TILE_ENTITY and DISPENSER_TILE_ENTITY bits which aren't
// relevant for entities)
// |||| |||| |||| |||| |||| ||\------------ BIT09: CLASS:
// MINECART_CONTAINER
// |||| |||| |||| |||| |||| |\------------- BIT10: CLASS: SLIME
// |||| |||| |||| |||| |||| \-------------- BIT11: CLASS: ZOMBIE
// |||| |||| |||| |||| ||||
// |||| |||| |||| |||| |||\---------------- BIT12: CLASS: SPIDER
// |||| |||| |||| |||| ||\----------------- BIT13: CLASS: COW
// |||| |||| |||| |||| |\------------------ BIT14: CLASS: TAMABLE
// |||| |||| |||| |||| \------------------- BIT15: CLASS: ANIMAL
// |||| |||| |||| ||||
// |||| |||| |||| |||\--------------------- BIT16: CLASS:
// MONSTER
// |||| |||| |||| ||\---------------------- BIT17: CLASS:
// GOLEM
// |||| |||| |||| |\----------------------- BIT18: CLASS: AGABLE_MOB
// |||| |||| |||| \------------------------ BIT19: CLASS:
// PATHFINDER_MOB
// |||| |||| ||||
// |||| |||| |||\-------------------------- BIT20: CLASS:
// PLAYER
// |||| |||| ||\--------------------------- BIT21: CLASS:
// MOB
// |||| |||| |\---------------------------- BIT22: CLASS:
// HANGING_ENTITY
// |||| |||| \----------------------------- BIT23: CLASS:
// THROWABLE
// |||| ||||
// |||| |||\------------------------------- BIT24: CLASS: FIREBALL
// |||| ||\-------------------------------- BIT25: CLASS: MINECART
// |||| |\--------------------------------- BIT26: CLASS: LIVING_ENTITY
// |||| \---------------------------------- BIT27: CLASS: ENTITY
// ||||
// |||\------------------------------------ BIT28: FLAGS: valid in
// spawner flag
// ||\------------------------------------- BIT29: FLAGS:
// Spawnlimitcheck
// |\-------------------------------------- BIT30: FLAGS: Enemy
// \--------------------------------------- BIT31: FLAGS: projectile
#define Bit(a) ((1) << (a))
const unsigned int BIT_NOT_LIVING_ENTITY = Bit(25);
// Classes
const unsigned int BIT_FLYING_MOB = Bit(9);
const unsigned int BIT_WATER_MOB = Bit(10);
const unsigned int BIT_AMBIENT_MOB = Bit(11);
const unsigned int BIT_NOT_ENTITY = Bit(12);
const unsigned int BIT_SLIME = Bit(13);
const unsigned int BIT_ZOMBIE = Bit(14);
const unsigned int BIT_SPIDER = Bit(15);
const unsigned int BIT_COW = Bit(16);
const unsigned int BIT_TAMABLE = Bit(17);
const unsigned int BIT_ANIMAL = Bit(18);
const unsigned int BIT_MONSTER = Bit(19);
const unsigned int BIT_MINECART_CONTAINER = Bit(19) | BIT_NOT_LIVING_ENTITY;
const unsigned int BIT_GOLEM = Bit(20);
const unsigned int BIT_HANGING_ENTITY = Bit(20) | BIT_NOT_LIVING_ENTITY;
const unsigned int BIT_AGABLE_MOB = Bit(21);
const unsigned int BIT_THROWABLE = Bit(21) | BIT_NOT_LIVING_ENTITY;
const unsigned int BIT_PATHFINDER_MOB = Bit(22);
const unsigned int BIT_FIREBALL = Bit(22) | BIT_NOT_LIVING_ENTITY;
const unsigned int BIT_PLAYER = Bit(23);
const unsigned int BIT_MINECART = Bit(23) | BIT_NOT_LIVING_ENTITY;
const unsigned int BIT_MOB = Bit(24);
const unsigned int BIT_GLOBAL_ENTITY = Bit(24) | BIT_NOT_LIVING_ENTITY;
// const unsigned int BIT_NOT_LIVING_ENTITY
// = Bit(25);
const unsigned int BIT_LIVING_ENTITY = Bit(26);
const unsigned int BIT_ENTITY = Bit(27);
// Flags
const unsigned int BIT_VALID_IN_SPAWNER = Bit(28);
const unsigned int BIT_ANIMALS_SPAWN_LIMIT_CHECK = Bit(29);
const unsigned int BIT_ENEMY = Bit(30);
const unsigned int BIT_PROJECTILE = Bit(31U);
// Tile Entities
const unsigned int BIT_TILE_ENTITY = Bit(24) | BIT_NOT_ENTITY;
const unsigned int BIT_DISPENSERTILEENTITY = Bit(25) | BIT_NOT_ENTITY;
const unsigned int BIT_OTHER_NOT_ENTITIES = Bit(26) | BIT_NOT_ENTITY;
// 4J-JEV: These abstract classes only have one subclass, so ignore them.
// const unsigned int BIT_WATER_MOB =
// Bit(15); const unsigned int BIT_FLYING_MOB = Bit(17); const unsigned int
// BIT_AMBIENT_MOB = Bit(18); const unsigned int
// BIT_GLOBAL_ENTITY = Bit();
// #define ETYPE(a,b,c) ( (a) | (b) | (c) )
// 4J Stu - This Enum can be used as a more lightweight version of the above,
// without having do dynamic casts 4J-PB - for replacement of instanceof
enum eINSTANCEOF {
eTYPE_NOTSET = 0,
// Flags.
eTYPE_VALID_IN_SPAWNER_FLAG = BIT_VALID_IN_SPAWNER,
eTYPE_ANIMALS_SPAWN_LIMIT_CHECK = BIT_ANIMALS_SPAWN_LIMIT_CHECK,
eTYPE_ENEMY = BIT_ENEMY,
eTYPE_PROJECTILE = BIT_PROJECTILE,
eTYPE_ENTITY = BIT_ENTITY,
eTYPE_LIVINGENTITY = eTYPE_ENTITY | BIT_LIVING_ENTITY,
eTYPE_MOB = eTYPE_LIVINGENTITY | BIT_MOB,
eTYPE_PATHFINDER_MOB = eTYPE_MOB | BIT_PATHFINDER_MOB,
eTYPE_AGABLE_MOB = eTYPE_PATHFINDER_MOB | BIT_AGABLE_MOB,
eTYPE_VILLAGER = eTYPE_AGABLE_MOB | 0x1, // 0x12000,
// 4J Stu - When adding new categories, please also update
// ConsoleSchematicFile::generateSchematicFile so these can be saved out to
// schematics
eTYPE_ANIMAL = eTYPE_AGABLE_MOB | BIT_ANIMAL,
eTYPE_TAMABLE_ANIMAL = eTYPE_ANIMAL | BIT_TAMABLE,
eTYPE_OCELOT = eTYPE_TAMABLE_ANIMAL | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | 0x1,
eTYPE_WOLF = eTYPE_TAMABLE_ANIMAL | 0x2,
eTYPE_HORSE = eTYPE_ANIMAL | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | 0x1,
eTYPE_SHEEP = eTYPE_ANIMAL | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | 0x2,
eTYPE_PIG = eTYPE_ANIMAL | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | 0x3,
eTYPE_CHICKEN = eTYPE_ANIMAL | 0x4,
eTYPE_COW = eTYPE_ANIMAL | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | BIT_COW,
eTYPE_MUSHROOMCOW = eTYPE_COW | 0x1,
eTYPE_WATERANIMAL = eTYPE_PATHFINDER_MOB | BIT_WATER_MOB, // 0x100,
eTYPE_SQUID = eTYPE_WATERANIMAL | 0x1,
eTYPE_GOLEM = eTYPE_PATHFINDER_MOB | BIT_GOLEM,
eTYPE_SNOWMAN =
eTYPE_GOLEM | eTYPE_ANIMALS_SPAWN_LIMIT_CHECK | 0x1, // 0x4,
eTYPE_VILLAGERGOLEM = eTYPE_GOLEM | 0x2, // 0x1000,
// 4J Stu - If you add new hostile mobs here you should also update the
eTYPE_MONSTER = eTYPE_ENEMY | eTYPE_PATHFINDER_MOB | BIT_MONSTER,
eTYPE_SPIDER = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | BIT_SPIDER,
eTYPE_CAVESPIDER = eTYPE_SPIDER | 0x1,
eTYPE_ZOMBIE = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | BIT_ZOMBIE,
eTYPE_PIGZOMBIE = eTYPE_ZOMBIE | 0x1,
eTYPE_CREEPER = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x1,
eTYPE_GIANT = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x2,
eTYPE_SKELETON = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x3,
eTYPE_ENDERMAN = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x4,
eTYPE_SILVERFISH = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x5,
eTYPE_BLAZE = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x6,
eTYPE_WITCH = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x7,
eTYPE_WITHERBOSS = eTYPE_MONSTER | eTYPE_VALID_IN_SPAWNER_FLAG | 0x8,
eTYPE_AMBIENT = eTYPE_MOB | BIT_AMBIENT_MOB,
eTYPE_BAT = eTYPE_AMBIENT | eTYPE_VALID_IN_SPAWNER_FLAG | 0x1,
eTYPE_FLYING_MOB = eTYPE_MOB | BIT_FLYING_MOB,
eTYPE_GHAST =
eTYPE_FLYING_MOB | eTYPE_VALID_IN_SPAWNER_FLAG | eTYPE_ENEMY | 0x1,
eTYPE_SLIME =
eTYPE_MOB | eTYPE_VALID_IN_SPAWNER_FLAG | eTYPE_ENEMY | BIT_SLIME,
eTYPE_LAVASLIME = eTYPE_SLIME | 0x1,
eTYPE_ENDERDRAGON = eTYPE_MOB | 0x5,
eTYPE_PLAYER = eTYPE_LIVINGENTITY | BIT_PLAYER, // 0x8000,
eTYPE_SERVERPLAYER = eTYPE_PLAYER | 0x1,
eTYPE_REMOTEPLAYER = eTYPE_PLAYER | 0x2,
eTYPE_LOCALPLAYER = eTYPE_PLAYER | 0x3,
eTYPE_GLOBAL_ENTITY = eTYPE_ENTITY | BIT_GLOBAL_ENTITY,
eTYPE_LIGHTNINGBOLT = eTYPE_GLOBAL_ENTITY | 0x1,
eTYPE_MINECART = eTYPE_ENTITY | BIT_MINECART, // 0x200000,
eTYPE_MINECART_RIDEABLE = eTYPE_MINECART | 0x1,
eTYPE_MINECART_SPAWNER = eTYPE_MINECART | 0x6,
eTYPE_MINECART_FURNACE = eTYPE_MINECART | 0x3,
eTYPE_MINECART_TNT = eTYPE_MINECART | 0x4,
eTYPE_MINECART_CONTAINER = eTYPE_MINECART | BIT_MINECART_CONTAINER,
eTYPE_MINECART_CHEST = eTYPE_MINECART_CONTAINER | 0x2,
eTYPE_MINECART_HOPPER = eTYPE_MINECART_CONTAINER | 0x5,
eTYPE_FIREBALL = eTYPE_ENTITY | eTYPE_PROJECTILE | BIT_FIREBALL, // 0x2,
eTYPE_DRAGON_FIREBALL = eTYPE_FIREBALL | 0x1,
eTYPE_WITHER_SKULL = eTYPE_FIREBALL | 0x2,
eTYPE_LARGE_FIREBALL = eTYPE_FIREBALL | 0x3,
eTYPE_SMALL_FIREBALL = eTYPE_FIREBALL | 0x4,
eTYPE_THROWABLE = eTYPE_ENTITY | eTYPE_PROJECTILE | BIT_THROWABLE,
eTYPE_SNOWBALL = eTYPE_THROWABLE | 0x1,
eTYPE_THROWNEGG = eTYPE_THROWABLE | 0x2,
eTYPE_THROWNENDERPEARL = eTYPE_THROWABLE | 0x3,
eTYPE_THROWNPOTION = eTYPE_THROWABLE | 0x4,
eTYPE_THROWNEXPBOTTLE = eTYPE_THROWABLE | 0x5,
eTYPE_HANGING_ENTITY = eTYPE_ENTITY | BIT_HANGING_ENTITY,
eTYPE_PAINTING = eTYPE_HANGING_ENTITY | 0x1,
eTYPE_ITEM_FRAME = eTYPE_HANGING_ENTITY | 0x2,
eTYPE_LEASHFENCEKNOT = eTYPE_HANGING_ENTITY | 0x3,
// Other Entities.
eTYPE_OTHER_ENTITIES = eTYPE_ENTITY + 1,
eTYPE_EXPERIENCEORB = (eTYPE_OTHER_ENTITIES + 2), // 1.8.2
eTYPE_EYEOFENDERSIGNAL = (eTYPE_OTHER_ENTITIES + 3) | eTYPE_PROJECTILE,
eTYPE_FIREWORKS_ROCKET = (eTYPE_OTHER_ENTITIES + 4) | eTYPE_PROJECTILE,
eTYPE_FISHINGHOOK = (eTYPE_OTHER_ENTITIES + 5) | eTYPE_PROJECTILE,
eTYPE_DELAYEDRELEASE = (eTYPE_OTHER_ENTITIES + 6), // 1.8.2
eTYPE_BOAT = (eTYPE_OTHER_ENTITIES + 7),
eTYPE_FALLINGTILE = (eTYPE_OTHER_ENTITIES + 8),
eTYPE_ITEMENTITY = (eTYPE_OTHER_ENTITIES + 9),
eTYPE_PRIMEDTNT = (eTYPE_OTHER_ENTITIES + 10),
eTYPE_ARROW = (eTYPE_OTHER_ENTITIES + 11) | eTYPE_PROJECTILE,
eTYPE_MULTIENTITY_MOB_PART = (eTYPE_OTHER_ENTITIES + 12),
eTYPE_NETHER_SPHERE = (eTYPE_OTHER_ENTITIES + 13),
eTYPE_ENDER_CRYSTAL = (eTYPE_OTHER_ENTITIES + 14),
// === PARTICLES === //
eType_BREAKINGITEMPARTICLE,
eType_BUBBLEPARTICLE,
eType_EXPLODEPARTICLE,
eType_FLAMEPARTICLE,
eType_FOOTSTEPPARTICLE,
eType_HEARTPARTICLE,
eType_LAVAPARTICLE,
eType_NOTEPARTICLE,
eType_NETHERPORTALPARTICLE,
eType_REDDUSTPARTICLE,
eType_SMOKEPARTICLE,
eType_SNOWSHOVELPARTICLE,
eType_SPLASHPARTICLE,
eType_TAKEANIMATIONPARTICLE,
eType_TERRAINPARTICLE,
eType_WATERDROPPARTICLE,
// 1.8.2
eType_CRITPARTICLE,
eType_CRITPARTICLE2,
eType_HUGEEXPLOSIONPARTICLE,
eType_HUGEEXPLOSIONSEEDPARTICLE,
eType_PLAYERCLOUDPARTICLEPARTICLE,
eType_SUSPENDEDPARTICLE,
eType_SUSPENDEDTOWNPARTICLE,
// 1.0.1
eTYPE_DRIPPARTICLE,
eTYPE_ENCHANTMENTTABLEPARTICLE,
eTYPE_SPELLPARTICLE,
// TU9
eTYPE_DRAGONBREATHPARTICLE,
eType_ENDERPARTICLE,
eType_FIREWORKSSTARTERPARTICLE,
eType_FIREWORKSSPARKPARTICLE,
eType_FIREWORKSOVERLAYPARTICLE,
// === Tile Entities === //
eTYPE_TILEENTITY = BIT_TILE_ENTITY,
eTYPE_CHESTTILEENTITY = eTYPE_TILEENTITY | 0x01,
eTYPE_MOBSPAWNERTILEENTITY = eTYPE_TILEENTITY | 0x02,
eTYPE_FURNACETILEENTITY = eTYPE_TILEENTITY | 0x03,
eTYPE_SIGNTILEENTITY = eTYPE_TILEENTITY | 0x04,
eTYPE_MUSICTILEENTITY = eTYPE_TILEENTITY | 0x05,
eTYPE_RECORDPLAYERTILE = eTYPE_TILEENTITY | 0x06,
eTYPE_PISTONPIECEENTITY = eTYPE_TILEENTITY | 0x07,
eTYPE_BREWINGSTANDTILEENTITY = eTYPE_TILEENTITY | 0x08,
eTYPE_ENCHANTMENTTABLEENTITY = eTYPE_TILEENTITY | 0x09,
eTYPE_THEENDPORTALTILEENTITY = eTYPE_TILEENTITY | 0x0A,
eTYPE_SKULLTILEENTITY = eTYPE_TILEENTITY | 0x0B,
eTYPE_ENDERCHESTTILEENTITY = eTYPE_TILEENTITY | 0x0C,
eTYPE_BEACONTILEENTITY = eTYPE_TILEENTITY | 0x0D,
eTYPE_COMMANDBLOCKTILEENTITY = eTYPE_TILEENTITY | 0x0E,
eTYPE_COMPARATORTILEENTITY = eTYPE_TILEENTITY | 0x0F,
eTYPE_DAYLIGHTDETECTORTILEENTITY = eTYPE_TILEENTITY | 0x10,
eTYPE_HOPPERTILEENTITY = eTYPE_TILEENTITY | 0x11,
eTYPE_DISPENSERTILEENTITY = eTYPE_TILEENTITY | BIT_DISPENSERTILEENTITY,
eTYPE_DROPPERTILEENTITY = eTYPE_DISPENSERTILEENTITY | 0x1,
// === Never used === //
// exists to ensure all later entities don't match the bitmasks above
eTYPE_OTHERS = BIT_OTHER_NOT_ENTITIES,
eType_NODE,
eType_ITEM,
eType_ITEMINSTANCE,
eType_MAPITEM,
eType_TILE,
eType_FIRETILE,
};
inline bool eTYPE_DERIVED_FROM(eINSTANCEOF super, eINSTANCEOF sub) {
if ((super & 0x3F) != 0x00)
return super == sub;
else
return (super & sub) == super;
}
inline bool eTYPE_FLAGSET(eINSTANCEOF flag, eINSTANCEOF claz) {
return (flag & claz) == flag;
}
/// FOR CHECKING ///
#if !(defined _WINDOWS64)
class SubClass {
static void checkDerivations() {}
};
#else
class SubClass {
public:
bool m_isTerminal;
const std::string m_name;
const eINSTANCEOF m_id;
std::vector<eINSTANCEOF> m_parents;
static std::unordered_map<eINSTANCEOF, SubClass*> s_ids;
SubClass(const std::string& name, eINSTANCEOF id) : m_name(name), m_id(id) {
s_ids.insert(std::pair<eINSTANCEOF, SubClass*>(id, this));
m_isTerminal = true;
}
SubClass* addParent(eINSTANCEOF id) {
SubClass* parent = s_ids.at(id);
parent->m_isTerminal = false;
m_parents.push_back(id);
for (auto itr = parent->m_parents.begin();
itr != parent->m_parents.end(); itr++) {
m_parents.push_back(*itr);
}
return this;
}
bool justFlag() { return (m_id & 0xF00000) == m_id; }
#define SUBCLASS(x) (new SubClass(#x, x))
static void checkDerivations() {
std::vector<SubClass*>* classes = new std::vector<SubClass*>();
classes->push_back(SUBCLASS(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(SUBCLASS(eTYPE_ENEMY));
classes->push_back(SUBCLASS(eTYPE_PROJECTILE));
classes->push_back(SUBCLASS(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_LIVINGENTITY)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_MOB)->addParent(eTYPE_LIVINGENTITY));
classes->push_back(
SUBCLASS(eTYPE_PATHFINDER_MOB)->addParent(eTYPE_MOB));
classes->push_back(
SUBCLASS(eTYPE_AGABLE_MOB)->addParent(eTYPE_PATHFINDER_MOB));
classes->push_back(
SUBCLASS(eTYPE_VILLAGER)->addParent(eTYPE_AGABLE_MOB));
classes->push_back(SUBCLASS(eTYPE_ANIMAL)->addParent(eTYPE_AGABLE_MOB));
classes->push_back(
SUBCLASS(eTYPE_TAMABLE_ANIMAL)->addParent(eTYPE_ANIMAL));
classes->push_back(SUBCLASS(eTYPE_OCELOT)
->addParent(eTYPE_TAMABLE_ANIMAL)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(
SUBCLASS(eTYPE_WOLF)->addParent(eTYPE_TAMABLE_ANIMAL));
classes->push_back(SUBCLASS(eTYPE_HORSE)
->addParent(eTYPE_ANIMAL)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(SUBCLASS(eTYPE_SHEEP)
->addParent(eTYPE_ANIMAL)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(SUBCLASS(eTYPE_PIG)
->addParent(eTYPE_ANIMAL)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(SUBCLASS(eTYPE_CHICKEN)->addParent(eTYPE_ANIMAL));
classes->push_back(SUBCLASS(eTYPE_COW)
->addParent(eTYPE_ANIMAL)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(SUBCLASS(eTYPE_MUSHROOMCOW)->addParent(eTYPE_COW));
classes->push_back(
SUBCLASS(eTYPE_WATERANIMAL)->addParent(eTYPE_PATHFINDER_MOB));
classes->push_back(SUBCLASS(eTYPE_SQUID)->addParent(eTYPE_WATERANIMAL));
classes->push_back(
SUBCLASS(eTYPE_GOLEM)->addParent(eTYPE_PATHFINDER_MOB));
classes->push_back(SUBCLASS(eTYPE_SNOWMAN)
->addParent(eTYPE_GOLEM)
->addParent(eTYPE_ANIMALS_SPAWN_LIMIT_CHECK));
classes->push_back(
SUBCLASS(eTYPE_VILLAGERGOLEM)->addParent(eTYPE_GOLEM));
classes->push_back(SUBCLASS(eTYPE_MONSTER)
->addParent(eTYPE_ENEMY)
->addParent(eTYPE_PATHFINDER_MOB));
classes->push_back(SUBCLASS(eTYPE_SPIDER)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_CAVESPIDER)->addParent(eTYPE_SPIDER));
classes->push_back(SUBCLASS(eTYPE_ZOMBIE)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_PIGZOMBIE)->addParent(eTYPE_ZOMBIE));
classes->push_back(SUBCLASS(eTYPE_CREEPER)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_GIANT)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_SKELETON)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_ENDERMAN)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_SILVERFISH)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_BLAZE)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_WITCH)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_WITHERBOSS)
->addParent(eTYPE_MONSTER)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_AMBIENT)->addParent(eTYPE_MOB));
classes->push_back(SUBCLASS(eTYPE_BAT)
->addParent(eTYPE_AMBIENT)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG));
classes->push_back(SUBCLASS(eTYPE_FLYING_MOB)->addParent(eTYPE_MOB));
classes->push_back(SUBCLASS(eTYPE_GHAST)
->addParent(eTYPE_FLYING_MOB)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG)
->addParent(eTYPE_ENEMY));
classes->push_back(SUBCLASS(eTYPE_SLIME)
->addParent(eTYPE_MOB)
->addParent(eTYPE_VALID_IN_SPAWNER_FLAG)
->addParent(eTYPE_ENEMY));
classes->push_back(SUBCLASS(eTYPE_LAVASLIME)->addParent(eTYPE_SLIME));
classes->push_back(SUBCLASS(eTYPE_ENDERDRAGON)->addParent(eTYPE_MOB));
classes->push_back(
SUBCLASS(eTYPE_PLAYER)->addParent(eTYPE_LIVINGENTITY));
classes->push_back(
SUBCLASS(eTYPE_SERVERPLAYER)->addParent(eTYPE_PLAYER));
classes->push_back(
SUBCLASS(eTYPE_REMOTEPLAYER)->addParent(eTYPE_PLAYER));
classes->push_back(
SUBCLASS(eTYPE_LOCALPLAYER)->addParent(eTYPE_PLAYER));
classes->push_back(SUBCLASS(eTYPE_MINECART)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_MINECART_RIDEABLE)->addParent(eTYPE_MINECART));
classes->push_back(
SUBCLASS(eTYPE_MINECART_SPAWNER)->addParent(eTYPE_MINECART));
classes->push_back(
SUBCLASS(eTYPE_MINECART_FURNACE)->addParent(eTYPE_MINECART));
classes->push_back(
SUBCLASS(eTYPE_MINECART_TNT)->addParent(eTYPE_MINECART));
classes->push_back(
SUBCLASS(eTYPE_MINECART_CONTAINER)->addParent(eTYPE_MINECART));
classes->push_back(SUBCLASS(eTYPE_MINECART_CHEST)
->addParent(eTYPE_MINECART_CONTAINER));
classes->push_back(SUBCLASS(eTYPE_MINECART_HOPPER)
->addParent(eTYPE_MINECART_CONTAINER));
classes->push_back(SUBCLASS(eTYPE_FIREBALL)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(
SUBCLASS(eTYPE_DRAGON_FIREBALL)->addParent(eTYPE_FIREBALL));
classes->push_back(
SUBCLASS(eTYPE_WITHER_SKULL)->addParent(eTYPE_FIREBALL));
classes->push_back(
SUBCLASS(eTYPE_LARGE_FIREBALL)->addParent(eTYPE_FIREBALL));
classes->push_back(
SUBCLASS(eTYPE_SMALL_FIREBALL)->addParent(eTYPE_FIREBALL));
classes->push_back(SUBCLASS(eTYPE_THROWABLE)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(
SUBCLASS(eTYPE_SNOWBALL)->addParent(eTYPE_THROWABLE));
classes->push_back(
SUBCLASS(eTYPE_THROWNEGG)->addParent(eTYPE_THROWABLE));
classes->push_back(
SUBCLASS(eTYPE_THROWNENDERPEARL)->addParent(eTYPE_THROWABLE));
classes->push_back(
SUBCLASS(eTYPE_THROWNPOTION)->addParent(eTYPE_THROWABLE));
classes->push_back(
SUBCLASS(eTYPE_THROWNEXPBOTTLE)->addParent(eTYPE_THROWABLE));
classes->push_back(
SUBCLASS(eTYPE_HANGING_ENTITY)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_PAINTING)->addParent(eTYPE_HANGING_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_ITEM_FRAME)->addParent(eTYPE_HANGING_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_LEASHFENCEKNOT)->addParent(eTYPE_HANGING_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_GLOBAL_ENTITY)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_LIGHTNINGBOLT)->addParent(eTYPE_GLOBAL_ENTITY));
// classes->push_back( SUBCLASS(eTYPE_OTHER_ENTITIES )->addParent(
// eTYPE_ENTITY ) );
classes->push_back(
SUBCLASS(eTYPE_EXPERIENCEORB)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_EYEOFENDERSIGNAL)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(SUBCLASS(eTYPE_FIREWORKS_ROCKET)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(SUBCLASS(eTYPE_FISHINGHOOK)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(
SUBCLASS(eTYPE_DELAYEDRELEASE)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_BOAT)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_FALLINGTILE)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_ITEMENTITY)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_PRIMEDTNT)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_ARROW)
->addParent(eTYPE_ENTITY)
->addParent(eTYPE_PROJECTILE));
classes->push_back(
SUBCLASS(eTYPE_MULTIENTITY_MOB_PART)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_NETHER_SPHERE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_ENDER_CRYSTAL)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_BREAKINGITEMPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_BUBBLEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_EXPLODEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_FLAMEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_FOOTSTEPPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_HEARTPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_LAVAPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_NOTEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_NETHERPORTALPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_REDDUSTPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_SMOKEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_SNOWSHOVELPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_SPLASHPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_TAKEANIMATIONPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_TERRAINPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_WATERDROPPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_CRITPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_CRITPARTICLE2)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_HUGEEXPLOSIONPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_HUGEEXPLOSIONSEEDPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eType_PLAYERCLOUDPARTICLEPARTICLE)
->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_SUSPENDEDPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_SUSPENDEDTOWNPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_DRIPPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_ENCHANTMENTTABLEPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_SPELLPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eTYPE_DRAGONBREATHPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_ENDERPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_FIREWORKSSTARTERPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_FIREWORKSSPARKPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(
SUBCLASS(eType_FIREWORKSOVERLAYPARTICLE)->addParent(eTYPE_ENTITY));
classes->push_back(SUBCLASS(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_CHESTTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_MOBSPAWNERTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_FURNACETILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_SIGNTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_MUSICTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_RECORDPLAYERTILE)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_PISTONPIECEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_BREWINGSTANDTILEENTITY)
->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_ENCHANTMENTTABLEENTITY)
->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_THEENDPORTALTILEENTITY)
->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_SKULLTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_ENDERCHESTTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_BEACONTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_COMMANDBLOCKTILEENTITY)
->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_COMPARATORTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_DAYLIGHTDETECTORTILEENTITY)
->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_HOPPERTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(
SUBCLASS(eTYPE_DISPENSERTILEENTITY)->addParent(eTYPE_TILEENTITY));
classes->push_back(SUBCLASS(eTYPE_DROPPERTILEENTITY)
->addParent(eTYPE_DISPENSERTILEENTITY));
// classes->push_back( SUBCLASS(eTYPE_OTHERS) );
classes->push_back(SUBCLASS(eType_NODE));
classes->push_back(SUBCLASS(eType_ITEM));
classes->push_back(SUBCLASS(eType_ITEMINSTANCE));
classes->push_back(SUBCLASS(eType_MAPITEM));
classes->push_back(SUBCLASS(eType_TILE));
classes->push_back(SUBCLASS(eType_FIRETILE));
std::vector<std::pair<SubClass*, SubClass*> > m_falsePositives;
std::vector<std::pair<SubClass*, SubClass*> > m_falseNegatives;
std::vector<SubClass*>::iterator it1;
for (it1 = classes->begin(); it1 != classes->end(); it1++) {
SubClass* current = *it1;
// if ( current->justFlag() ) continue;
std::vector<SubClass*>::iterator it2;
for (it2 = classes->begin(); it2 != classes->end(); it2++) {
SubClass* comparing = *it2;
// if ( comparing->justFlag() ) continue;
// We shouldn't be comparing to leaf classes anyway.
// if ( comparing->m_isTerminal ) continue;
eINSTANCEOF typeCurr, typeComp;
typeCurr = current->m_id;
typeComp = comparing->m_id;
bool shouldDerive, doesDerive;
{
std::vector<eINSTANCEOF>::iterator it3;
it3 = find(current->m_parents.begin(),
current->m_parents.end(), typeComp);
shouldDerive = (typeComp == typeCurr) ||
(it3 != current->m_parents.end());
}
doesDerive = eTYPE_DERIVED_FROM(typeComp, typeCurr);
if (shouldDerive != doesDerive) {
std::vector<std::pair<SubClass*, SubClass*> >* errorArray;
if (shouldDerive)
errorArray = &m_falseNegatives;
else
errorArray = &m_falsePositives;
errorArray->push_back(
std::pair<SubClass*, SubClass*>(comparing, current));
}
}
}
std::vector<std::pair<SubClass*, SubClass*> >::iterator itrErr;
for (itrErr = m_falsePositives.begin();
itrErr != m_falsePositives.end(); itrErr++) {
SubClass *sub = itrErr->first, *super = itrErr->second;
printf("[Class.h] Error: '%s' incorrectly derives from '%s'.\n",
sub->m_name.c_str(), super->m_name.c_str());
}
for (itrErr = m_falseNegatives.begin();
itrErr != m_falseNegatives.end(); itrErr++) {
SubClass *sub = itrErr->first, *super = itrErr->second;
printf("[Class.h] Error: '%s' doesn't derive '%s'.\n",
sub->m_name.c_str(), super->m_name.c_str());
}
if ((m_falsePositives.size() > 0) || (m_falseNegatives.size() > 0)) {
__debugbreak();
}
}
};
#endif

View File

@@ -0,0 +1,15 @@
#pragma once
class Color {
private:
int colour;
public:
// Creates an opaque sRGB color with the specified red, green, and blue
// values in the range (0.0 - 1.0).
Color(float r, float g, float b);
Color(int r, int g, int b);
static Color getHSBColor(float h, float s, float b);
int getRGB();
};

View File

@@ -0,0 +1,25 @@
#pragma once
#include <string>
#include <exception>
class EOFException : public std::exception {};
class IllegalArgumentException : public std::exception {
public:
std::wstring information;
IllegalArgumentException(const std::wstring& information);
};
class IOException : public std::exception {
public:
std::wstring information;
IOException(const std::wstring& information);
};
class RuntimeException : public std::exception {
public:
RuntimeException(const std::wstring& information);
};

View File

@@ -0,0 +1,58 @@
#pragma once
#include <string>
#include <cstdint>
#include <vector>
// 4J Stu - Represents java standard library class
class FileFilter;
class File {
public:
// The system-dependent path-separator character
static const wchar_t pathSeparator;
// 4J Jev, the start of the file root
static const std::wstring pathRoot;
File() { m_abstractPathName = L""; }
File(const File& parent, const std::wstring& child);
File(const std::wstring& pathname);
File(const std::wstring& parent, const std::wstring& child);
bool _delete();
bool mkdir() const;
bool mkdirs() const;
bool exists() const;
bool isFile() const;
bool renameTo(File dest);
std::vector<File*>* listFiles() const; // Array
std::vector<File*>* listFiles(FileFilter* filter) const;
bool isDirectory() const;
int64_t length();
int64_t lastModified();
const std::wstring getPath() const; // 4J Jev: TODO
std::wstring getName() const;
static int hash_fnct(const File& k);
static bool eq_test(const File& x, const File& y);
private:
void _init();
std::wstring m_abstractPathName;
// 4J Jev, just helper functions, change between paths and
// std::vector<string>
// File(std::vector<std::wstring> *path);
};
struct FileKeyHash {
int operator()(const File& k) const { return File::hash_fnct(k); }
};
struct FileKeyEq {
bool operator()(const File& x, const File& y) const {
return File::eq_test(x, y);
}
};

View File

@@ -0,0 +1,9 @@
#pragma once
class File;
// 4J Jev, java library interface.
class FileFilter {
public:
virtual bool accept(File* dir) = 0;
};

View File

@@ -0,0 +1,11 @@
#pragma once
#include <string>
class File;
// 4J Jev, java lirary interface.
class FilenameFilter {
public:
virtual bool accept(File* dir, const std::wstring& name) = 0;
};

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Buffer.h"
#include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class FloatBuffer : public Buffer {
private:
float* buffer;
public:
FloatBuffer(unsigned int capacity);
FloatBuffer(unsigned int capacity, float* backingArray);
virtual ~FloatBuffer();
FloatBuffer* flip();
FloatBuffer* put(float f);
void get(arrayWithLength<float>* dst);
float* _getDataPointer() { return buffer; }
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include "OutputStream.h"
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class BufferedOutputStream : public OutputStream {
private:
OutputStream* stream;
protected:
byteArray buf; // The internal buffer where data is stored.
unsigned int count; // The number of valid bytes in the buffer.
public:
BufferedOutputStream(OutputStream* out, int size);
~BufferedOutputStream();
virtual void flush();
virtual void close();
virtual void write(byteArray b, unsigned int offset, unsigned int length);
virtual void write(byteArray b);
virtual void write(unsigned int b);
};

View File

@@ -0,0 +1,26 @@
#pragma once
#include "Reader.h"
class BufferedReader : public Reader {
private:
Reader* reader;
wchar_t* buffer;
unsigned int readMark;
unsigned int bufferedMark;
unsigned int bufferSize;
bool eofReached;
static const unsigned int BUFFER_MORE_AMOUNT = 64;
void bufferMore();
public:
BufferedReader(Reader* in);
virtual ~BufferedReader();
virtual void close();
virtual int read();
virtual int read(wchar_t cbuf[], unsigned int off, unsigned int len);
std::wstring readLine();
};

View File

@@ -0,0 +1,36 @@
#pragma once
// 4J Stu - Represents Java standard library class
#include "InputStream.h"
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class ByteArrayInputStream : public InputStream {
protected:
byteArray buf; // An array of bytes that was provided by the creator of the
// stream.
unsigned int count; // The index one greater than the last valid character
// in the input stream buffer.
unsigned int mark; // The currently marked position in the stream.
unsigned int pos; // The index of the next character to read from the input
// stream buffer.
public:
ByteArrayInputStream(byteArray buf, unsigned int offset,
unsigned int length);
ByteArrayInputStream(byteArray buf);
virtual ~ByteArrayInputStream();
virtual int read();
virtual int read(byteArray b);
virtual int read(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual int64_t skip(int64_t n);
// 4J Stu Added - Sometimes we don't want to delete the data on destroying
// this
void reset() {
buf = byteArray();
count = 0;
mark = 0;
pos = 0;
}
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include "OutputStream.h"
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class ByteArrayOutputStream : public OutputStream {
// Note - when actually implementing, byteArray will need to grow as data is
// written
public:
byteArray buf; // The buffer where data is stored.
protected:
unsigned int count; // The number of valid bytes in the buffer.
public:
ByteArrayOutputStream();
ByteArrayOutputStream(unsigned int size);
virtual ~ByteArrayOutputStream();
virtual void flush() {}
virtual void write(unsigned int b);
virtual void write(byteArray b);
virtual void write(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual byteArray toByteArray();
void reset() { count = 0; }
unsigned int size() { return count; }
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class DataInput {
public:
virtual int read() = 0;
virtual int read(byteArray b) = 0;
virtual int read(byteArray b, unsigned int offset, unsigned int length) = 0;
virtual bool readBoolean() = 0;
virtual uint8_t readByte() = 0;
virtual unsigned char readUnsignedByte() = 0;
virtual bool readFully(byteArray a) = 0;
virtual double readDouble() = 0;
virtual float readFloat() = 0;
virtual int readInt() = 0;
virtual int64_t readLong() = 0;
virtual short readShort() = 0;
virtual wchar_t readChar() = 0;
virtual std::wstring readUTF() = 0;
virtual unsigned long long readPlayerUID() = 0; // 4J Added
virtual int skipBytes(int n) = 0;
};

View File

@@ -0,0 +1,40 @@
#pragma once
// 4J Stu - Represents Java standard library class (although we miss out an
// intermediate inheritance class that we don't care about)
#include <string>
#include "InputStream.h"
#include "DataInput.h"
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class DataInputStream : public InputStream, public DataInput {
private:
InputStream* stream;
public:
DataInputStream(InputStream* in);
virtual int read();
virtual int read(byteArray b);
virtual int read(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual bool readBoolean();
virtual uint8_t readByte();
virtual unsigned char readUnsignedByte();
virtual wchar_t readChar();
virtual bool readFully(byteArray b);
virtual bool readFully(charArray b);
virtual double readDouble();
virtual float readFloat();
virtual int readInt();
virtual int64_t readLong();
virtual short readShort();
virtual unsigned short readUnsignedShort();
virtual std::wstring readUTF();
void deleteChildStream();
virtual int readUTFChar();
virtual unsigned long long readPlayerUID(); // 4J Added
virtual int64_t skip(int64_t n);
virtual int skipBytes(int n);
};

View File

@@ -0,0 +1,22 @@
#pragma once
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
class DataOutput {
public:
virtual void write(unsigned int b) = 0;
virtual void write(byteArray b) = 0;
virtual void write(byteArray b, unsigned int offset,
unsigned int length) = 0;
virtual void writeByte(uint8_t a) = 0;
virtual void writeDouble(double a) = 0;
virtual void writeFloat(float a) = 0;
virtual void writeInt(int a) = 0;
virtual void writeLong(int64_t a) = 0;
virtual void writeShort(short a) = 0;
virtual void writeBoolean(bool v) = 0;
virtual void writeChar(wchar_t v) = 0;
virtual void writeChars(const std::wstring& s) = 0;
virtual void writeUTF(const std::wstring& a) = 0;
virtual void writePlayerUID(unsigned long long player) = 0; // 4J Added
};

View File

@@ -0,0 +1,44 @@
#pragma once
// 4J Stu - Represents Java standard library class (although we miss out an
// intermediate inheritance class that we don't care about)
#include <string>
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "OutputStream.h"
#include "DataOutput.h"
class DataOutputStream : public OutputStream, public DataOutput {
private:
OutputStream* stream;
protected:
int written; // The number of bytes written to the data output stream so
// far.
public:
DataOutputStream(OutputStream* out);
// 4J Stu Added
void deleteChildStream();
virtual void write(unsigned int b);
virtual void write(byteArray b);
virtual void write(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual void writeByte(uint8_t a);
virtual void writeDouble(double a);
virtual void writeFloat(float a);
virtual void writeInt(int a);
virtual void writeLong(int64_t a);
virtual void writeShort(short a);
virtual void writeUnsignedShort(unsigned short a);
virtual void writeChar(wchar_t a);
virtual void writeChars(const std::wstring& a);
virtual void writeBoolean(bool b);
virtual void writeUTF(const std::wstring& a);
virtual void writePlayerUID(unsigned long long player);
virtual void flush();
};

View File

@@ -0,0 +1,25 @@
#pragma once
// 4J Stu - Represents Java standard library class
#include <cstdio>
#include <cstdint>
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "InputStream.h"
class File;
class FileInputStream : public InputStream {
public:
FileInputStream(const File& file);
virtual ~FileInputStream();
virtual int read();
virtual int read(byteArray b);
virtual int read(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual int64_t skip(int64_t n);
private:
std::FILE* m_fileHandle;
};

View File

@@ -0,0 +1,24 @@
#pragma once
// 4J Stu - Represents Java standard lib abstract
#include <cstdio>
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "OutputStream.h"
class File;
class FileOutputStream : public OutputStream {
public:
FileOutputStream(const File& file);
virtual ~FileOutputStream();
virtual void write(unsigned int b);
virtual void write(byteArray b);
virtual void write(byteArray b, unsigned int offset, unsigned int length);
virtual void close();
virtual void flush();
private:
std::FILE* m_fileHandle;
};

View File

@@ -0,0 +1,24 @@
#pragma once
// 4J Stu - We are not using GZIP compression, so this is just a pass through
// class
#include <cstdint>
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "InputStream.h"
class GZIPInputStream : public InputStream {
private:
InputStream* stream;
public:
GZIPInputStream(InputStream* out) : stream(out) {};
virtual int read() { return stream->read(); };
virtual int read(byteArray b) { return stream->read(b); };
virtual int read(byteArray b, unsigned int offset, unsigned int length) {
return stream->read(b, offset, length);
};
virtual void close() { return stream->close(); };
virtual int64_t skip(int64_t n) { return 0; };
};

View File

@@ -0,0 +1,22 @@
#pragma once
// 4J Stu - We are not using GZIP compression, so this is just a pass through
// class
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "OutputStream.h"
class GZIPOutputStream : public OutputStream {
private:
OutputStream* stream;
public:
GZIPOutputStream(OutputStream* out) : stream(out) {};
virtual void write(unsigned int b) { stream->write(b); };
virtual void write(byteArray b) { stream->write(b); };
virtual void write(byteArray b, unsigned int offset, unsigned int length) {
stream->write(b, offset, length);
};
virtual void close() { stream->close(); };
virtual void flush() {}
};

View File

@@ -0,0 +1,20 @@
#pragma once
#include "InputStream.h"
#include "ByteArrayInputStream.h"
#include "DataInput.h"
#include "DataInputStream.h"
#include "FileInputStream.h"
#include "GZIPInputStream.h"
#include "OutputStream.h"
#include "ByteArrayOutputStream.h"
#include "DataOutput.h"
#include "BufferedOutputStream.h"
#include "DataOutputStream.h"
#include "FileOutputStream.h"
#include "GZIPOutputStream.h"
#include "Reader.h"
#include "BufferedReader.h"
#include "InputStreamReader.h"

View File

@@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include <string>
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
// 4J Stu - Represents Java standard lib abstract
class InputStream {
public:
virtual ~InputStream() {}
virtual int read() = 0;
virtual int read(byteArray b) = 0;
virtual int read(byteArray b, unsigned int offset, unsigned int length) = 0;
virtual void close() = 0;
virtual int64_t skip(int64_t n) = 0;
static InputStream* getResourceAsStream(const std::wstring& fileName);
};

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Reader.h"
#include "DataInputStream.h"
class InputStream;
class InputStreamReader : public Reader {
private:
DataInputStream* stream;
public:
InputStreamReader(InputStream* in);
virtual void close();
virtual int read();
virtual int read(wchar_t cbuf[], unsigned int offset, unsigned int length);
};

View File

@@ -0,0 +1,17 @@
#pragma once
#include "../../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
// 4J Stu - Represents Java standard lib abstract
class OutputStream {
public:
virtual ~OutputStream() {}
virtual void write(unsigned int b) = 0;
virtual void write(byteArray b) = 0;
virtual void write(byteArray b, unsigned int offset,
unsigned int length) = 0;
virtual void close() = 0;
virtual void flush() = 0;
};

View File

@@ -0,0 +1,13 @@
#pragma once
class Reader {
public:
virtual ~Reader() {}
virtual void close() = 0; // Closes the stream and releases any system
// resources associated with it.
virtual int read() = 0; // Reads a single character.
virtual int read(
wchar_t cbuf[], unsigned int off,
unsigned int len) = 0; // Reads characters into a portion of an array.
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
#include "Buffer.h"
class IntBuffer : public Buffer {
private:
int* buffer;
public:
IntBuffer(unsigned int capacity);
IntBuffer(unsigned int capacity, int* backingArray);
virtual ~IntBuffer();
virtual IntBuffer* flip();
int get(unsigned int index);
int* getBuffer();
IntBuffer* put(intArray* inputArray, unsigned int offset,
unsigned int length);
IntBuffer* put(intArray inputArray);
IntBuffer* put(int i);
};

View File

@@ -0,0 +1,68 @@
#pragma once
// Java doesn't have a default hash value for ints, however, the hashmap itself
// does some "supplemental" hashing, so our ints actually get hashed by code as
// implemented below. std templates *do* have a standard hash for ints, but it
// would appear to be a bit expensive so matching the java one for now anyway.
// This code implements the supplemental hashing that happens in java so we can
// match what their maps are doing with ints.
struct IntKeyHash {
int operator()(const int& k) const {
// 4jcraft added h to be unsigned, to not cast it later
unsigned int h = k;
h += ~(h << 9);
h ^= (h >> 14);
h += (h << 4);
h ^= (h >> 10);
return h;
}
};
struct IntKeyEq {
bool operator()(const int& x, const int& y) const { return x == y; }
};
// This hash functor is taken from the IntHashMap java class used by the game,
// so that we can use a standard std hashmap with this hash rather than
// implement the class itself
struct IntKeyHash2 {
int operator()(const int& k) const {
unsigned int h = (unsigned int)k;
h ^= (h >> 20) ^ (h >> 12);
return (int)(h ^ (h >> 7) ^ (h >> 4));
}
};
// This hash functor is taken from the LongHashMap java class used by the game,
// so that we can use a standard std hashmap with this hash rather than
// implement the class itself
struct LongKeyHash {
int hash(const int& k) const {
unsigned int h = (unsigned int)k;
h ^= (h >> 20) ^ (h >> 12);
return (int)(h ^ (h >> 7) ^ (h >> 4));
}
int operator()(const int64_t& k) const {
return hash((int)(k ^ (((uint64_t)k) >> 32)));
}
};
struct LongKeyEq {
bool operator()(const int64_t& x, const int64_t& y) const { return x == y; }
};
struct eINSTANCEOFKeyHash {
int operator()(const eINSTANCEOF& k) const {
unsigned int h = (unsigned int)k;
h ^= (h >> 20) ^ (h >> 12);
return (int)(h ^ (h >> 7) ^ (h >> 4));
}
};
struct eINSTANCEOFKeyEq {
bool operator()(const eINSTANCEOF& x, const eINSTANCEOF& y) const {
return x == y;
}
};

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Random.h"
class Math {
private:
static Random rand;
public:
static double random();
static int64_t round(double d);
static int _max(int a, int b);
static float _max(float a, float b);
static int _min(int a, int b);
static float _min(float a, float b);
static float wrapDegrees(float input);
static double wrapDegrees(double input);
};

View File

@@ -0,0 +1,24 @@
#pragma once
class Random {
private:
int64_t seed;
bool haveNextNextGaussian;
double nextNextGaussian;
protected:
int next(int bits);
public:
Random();
Random(int64_t seed);
void setSeed(int64_t s);
void nextBytes(uint8_t* bytes, unsigned int count);
double nextDouble();
double nextGaussian();
int nextInt();
int nextInt(int to);
float nextFloat();
int64_t nextLong();
bool nextBoolean();
};

View File

@@ -0,0 +1,11 @@
#pragma once
template <class T>
class Reference {
private:
T* obj;
public:
T* get() { return obj; }
Reference(T* i) { obj = i; }
};

View File

@@ -0,0 +1,46 @@
#pragma once
#include <cstdint>
#include "../../../Minecraft.World/ConsoleHelpers/ArrayWithLength.h" // 4jcraft TODO
// 4J Jev, just thought it would be easier this way.
#define ArrayCopyFunctionDeclaration(x) \
static void arraycopy(arrayWithLength<x> src, unsigned int srcPos, \
arrayWithLength<x>* dst, unsigned int dstPos, \
unsigned int length);
#define ArrayCopyFunctionDefinition(x) \
void System::arraycopy(arrayWithLength<x> src, unsigned int srcPos, \
arrayWithLength<x>* dst, unsigned int dstPos, \
unsigned int length) { \
arraycopy<x>(src, srcPos, dst, dstPos, length); \
}
class System {
template <class T>
static void arraycopy(arrayWithLength<T> src, unsigned int srcPos,
arrayWithLength<T>* dst, unsigned int dstPos,
unsigned int length);
public:
ArrayCopyFunctionDeclaration(uint8_t) ArrayCopyFunctionDeclaration(Node*)
ArrayCopyFunctionDeclaration(Biome*) ArrayCopyFunctionDeclaration(int)
static int64_t nanoTime();
static int64_t currentTimeMillis();
static int64_t currentRealTimeMillis(); // 4J Added to get real-world time
// for timestamps in saves
static void ReverseUSHORT(unsigned short* pusVal);
static void ReverseSHORT(short* psVal);
static void ReverseULONG(unsigned long* pulVal);
static void ReverseULONG(unsigned int* pulVal);
static void ReverseINT(int* piVal);
static void ReverseULONGLONG(int64_t* pullVal);
static void ReverseWCHARA(wchar_t* pwch, int iLen);
};
#define MAKE_FOURCC(ch0, ch1, ch2, ch3) \
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch0)) | \
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch1)) << 8) | \
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch2)) << 16) | \
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch3)) << 24))