Skip to content

Commit

Permalink
preparation of definition files for Converter for pre 1.13 maps
Browse files Browse the repository at this point in the history
Create new definition file for new block definitions after "The
Flattening". To stay backwards compatible, we can not change the
vanilla_ids.json file to a completely new format without breaking old
Minutor releases. The old definition file will get the translation table
for the Converter.

Due to old block ID and data values some complicated code was necessary
that can be removed now:
* removed map with lists of BlockInfo, no collisions are possible
anymore, therfore we don't need a nested list
* removed block cache, all new block definitions will fit into on QMap
* removed ID
* removed data field for getBlock queries

Enabled mob spawn highlighting again, not fully working for now
  • Loading branch information
EtlamGit committed Jul 28, 2018
1 parent c9901e0 commit 9f5897b
Show file tree
Hide file tree
Showing 8 changed files with 4,849 additions and 1,967 deletions.
66 changes: 29 additions & 37 deletions blockidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ bool BlockInfo::doesBlockHaveSolidTopSurface(int data) {
return false;
}

bool BlockInfo::doesBlockHaveSolidTopSurface() {
if (this->isOpaque() && this->renderAsNormalBlock()) return true;
if (this->hopper) return true;
return false;
}

bool BlockInfo::isBlockNormalCube() {
return this->isOpaque() && this->renderAsNormalBlock() &&
!this->canProvidePower();
Expand All @@ -46,14 +52,15 @@ void BlockInfo::setName(const QString & newname) {
// set name
name = newname;
// precompute mob spawning conditions
bedrock = this->name.contains("Bedrock");
hopper = this->name.contains("Hopper");
stairs = this->name.contains("Stairs");
halfslab = this->name.contains("Slab") && !this->name.contains("Double") &&
!this->name.contains("Full");
snow = this->name.contains("Snow");
bedrock = this->name.contains("Bedrock", Qt::CaseInsensitive);
hopper = this->name.contains("Hopper", Qt::CaseInsensitive);
stairs = this->name.contains("Stairs", Qt::CaseInsensitive);
halfslab = this->name.contains("Slab", Qt::CaseInsensitive) &&
!this->name.contains("Double", Qt::CaseInsensitive) &&
!this->name.contains("Full", Qt::CaseInsensitive);
snow = this->name.contains("Snow", Qt::CaseInsensitive);
// precompute biome based watercolormodifier
water = this->name.contains("water");
water = this->name.contains("Water", Qt::CaseInsensitive);
}

const QString & BlockInfo::getName() { return name; }
Expand All @@ -73,27 +80,23 @@ void BlockInfo::setBiomeGrass(bool value) { grass = value; }
void BlockInfo::setBiomeFoliage(bool value) { foliage = value; }

BlockIdentifier::BlockIdentifier() {
// clear cache pointers
for (int i = 0; i < 65536; i++)
cache[i] = NULL;
for (int i = 0; i < 16; i++)
unknownBlock.colors[i] = 0xff00ff;
unknownBlock.alpha = 1.0;
unknownBlock.setName("Unknown");
}

BlockIdentifier::~BlockIdentifier() {
clearCache();
for (int i = 0; i < packs.length(); i++) {
for (int j = 0; j < packs[i].length(); j++)
delete packs[i][j];
}
}

// this routine is ridiculously slow
BlockInfo &BlockIdentifier::getBlock(QString name, int data) {
BlockInfo &BlockIdentifier::getBlock(QString name) {
// first apply the mask
if (blocks.contains(name)) {
return *(blocks[name].first());
return *blocks[name];
}
// data &= blocks[name].first()->mask;
//
Expand Down Expand Up @@ -133,17 +136,13 @@ void BlockIdentifier::enableDefinitions(int pack) {
int len = packs[pack].length();
for (int i = 0; i < len; i++)
packs[pack][i]->enabled = true;
// clear cache
clearCache();
}

void BlockIdentifier::disableDefinitions(int pack) {
if (pack < 0) return;
int len = packs[pack].length();
for (int i = 0; i < len; i++)
packs[pack][i]->enabled = false;
// clear cache
clearCache();
}

int BlockIdentifier::addDefinitions(JSONArray *defs, int pack) {
Expand All @@ -154,31 +153,24 @@ int BlockIdentifier::addDefinitions(JSONArray *defs, int pack) {
int len = defs->length();
for (int i = 0; i < len; i++)
parseDefinition(dynamic_cast<JSONObject *>(defs->at(i)), NULL, pack);
// clear cache
clearCache();
return pack;
}

void BlockIdentifier::clearCache() {
for (int i = 0; i < 65536; i++) {
cache[i] = NULL;
}
}

void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent,
int pack) {
int id;
QString name;
if (parent == NULL) {
id = b->at("id")->asNumber();
} else {
id = parent->id;
int data = b->at("data")->asNumber();
id |= data << 12;
}
BlockInfo *block = new BlockInfo();
block->id = id;

// int id;
// if (parent == NULL) {
// id = b->at("id")->asNumber();
// } else {
// id = parent->id;
// int data = b->at("data")->asNumber();
// id |= data << 12;
// }
// block->id = id;

QString name;
if (b->has("name"))
name = b->at("name")->asString();
else if (parent != NULL)
Expand Down Expand Up @@ -280,6 +272,6 @@ void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent,
parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), block, pack);
}

blocks[name].append(block);
blocks.insert(name, block);
packs[pack].append(block);
}
9 changes: 4 additions & 5 deletions blockidentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BlockInfo {
bool isOpaque();
bool isLiquid();
bool doesBlockHaveSolidTopSurface(int data);
bool doesBlockHaveSolidTopSurface();
bool isBlockNormalCube();
bool renderAsNormalBlock();
bool canProvidePower();
Expand All @@ -41,7 +42,7 @@ class BlockInfo {
void setBiomeFoliage(bool value);
const QString &getName();

int id;
// int id;
double alpha;
quint8 mask;
bool enabled;
Expand Down Expand Up @@ -72,13 +73,11 @@ class BlockIdentifier {
int addDefinitions(JSONArray *, int pack = -1);
void enableDefinitions(int id);
void disableDefinitions(int id);
BlockInfo &getBlock(QString name, int data);
BlockInfo &getBlock(QString name);
private:
void clearCache();
void parseDefinition(JSONObject *block, BlockInfo *parent, int pack);
QMap<QString, QList<BlockInfo *>> blocks;
QMap<QString, BlockInfo*> blocks;
QList<QList<BlockInfo*> > packs;
BlockInfo *cache[65536];
};

#endif // BLOCKIDENTIFIER_H_
22 changes: 15 additions & 7 deletions definitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void DefinitionManager::refresh() {
table->setRowCount(0);
QStringList types;
types << tr("block") << tr("biome") << tr("dimension")
<< tr("entity") << tr("pack");
<< tr("entity") << tr("pack") << tr("converter");
for (int i = 0; i < sorted.length(); i++) {
Definition &def = definitions[sorted[i].toString()];
int row = table->rowCount();
Expand Down Expand Up @@ -371,6 +371,10 @@ void DefinitionManager::loadDefinition(QString path) {
QString key = d.name + type;
d.enabled = true; // should look this up
if (type == "block") {
// d.id = convertManager->addDefinitions(
// dynamic_cast<JSONArray*>(def->at("data")));
d.type = Definition::Converter;
} else if (type == "flatblock") {
d.id = blockManager->addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")));
d.type = Definition::Block;
Expand Down Expand Up @@ -421,18 +425,22 @@ void DefinitionManager::loadDefinition(QString path) {
continue;
}
QString type = def->at("type")->asString();
if (type == "block")
d.blockid = blockManager->addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")), d.blockid);
else if (type == "biome")
if (type == "block") {
// d.blockid = blockManager->addDefinitions(
// dynamic_cast<JSONArray*>(def->at("data")), d.blockid);
} else if (type == "flatblock") {
d.blockid = blockManager->addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")), d.blockid);
} else if (type == "biome") {
d.biomeid = biomeManager->addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")), d.biomeid);
else if (type == "dimension")
} else if (type == "dimension") {
d.dimensionid = dimensionManager->addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")), d.dimensionid);
else if (type == "entity")
} else if (type == "entity") {
d.entityid = entityManager.addDefinitions(
dynamic_cast<JSONArray*>(def->at("data")), d.entityid);
}
delete def;
}
definitions.insert(path, d);
Expand Down
2 changes: 1 addition & 1 deletion definitionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Definition {
QString version;
QString path;
QString update;
enum {Block, Biome, Dimension, Entity, Pack} type;
enum {Block, Biome, Dimension, Entity, Pack, Converter} type;
int id;
bool enabled;
// for packs only
Expand Down
Loading

0 comments on commit 9f5897b

Please sign in to comment.