From fa6507d165b2048a0231abc640465c6316d7a8ff Mon Sep 17 00:00:00 2001 From: EtlamGit Date: Sat, 25 Jan 2014 08:49:14 +0100 Subject: [PATCH] mob spawning now according Minecraft sources --- blockidentifier.cpp | 63 ++++++++++++++++++++++---- blockidentifier.h | 10 ++-- definitions/vanilla_ids.json | 88 ++++++++++++++++++++---------------- mapview.cpp | 8 +++- 4 files changed, 116 insertions(+), 53 deletions(-) mode change 100644 => 100755 blockidentifier.cpp mode change 100644 => 100755 blockidentifier.h mode change 100644 => 100755 definitions/vanilla_ids.json mode change 100644 => 100755 mapview.cpp diff --git a/blockidentifier.cpp b/blockidentifier.cpp old mode 100644 new mode 100755 index dd8705c6..5c5e284d --- a/blockidentifier.cpp +++ b/blockidentifier.cpp @@ -31,21 +31,55 @@ static BlockInfo unknownBlock; +BlockInfo::BlockInfo() +: transparent(false) +, liquid(false) +, rendernormal(true) +, providepower(false) +{} + bool BlockInfo::isOpaque() { - return !(this->liquid || this->transparent); + return !(this->transparent); } bool BlockInfo::isLiquid() { - return this->liquid; + return this->liquid; +} + +bool BlockInfo::doesBlockHaveSolidTopSurface(int data) +{ + if (this->isOpaque() && this->renderAsNormalBlock()) return true; + if (this->name.contains("Stairs") && ((data&4)==4)) return true; + if (this->name.contains("Slab") && !this->name.contains("Double") && + ((data&8)==8)) return true; + if (this->name.contains("Hopper")) return true; + if (this->name.contains("Snow") && ((data&7)==7)) return true; + return false; +} + +bool BlockInfo::isBlockNormalCube() +{ + return this->isOpaque() && + this->renderAsNormalBlock() && + !this->canProvidePower(); +} + +bool BlockInfo::renderAsNormalBlock() +{ +// if (this->name.contains("Redstone Wire")) && powered return true; else return false; + return this->rendernormal; } -bool BlockInfo::isTransparent() +bool BlockInfo::canProvidePower() { - return this->transparent; + return this->providepower; } + + + BlockIdentifier::BlockIdentifier() { // clear cache pointers @@ -54,8 +88,6 @@ BlockIdentifier::BlockIdentifier() for (int i=0;i<16;i++) unknownBlock.colors[i]=0xff00ff; unknownBlock.alpha=1.0; - unknownBlock.transparent=false; - unknownBlock.cubesolid=false; unknownBlock.name="Unknown"; } BlockIdentifier::~BlockIdentifier() @@ -181,11 +213,22 @@ void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent, int pack block->enabled=true; if (b->has("transparent")) + { block->transparent=b->at("transparent")->asBool(); + block->rendernormal=false; // for most cases except the following + if (b->has("rendercube")) + block->rendernormal=b->at("rendercube")->asBool(); + } else if (parent!=NULL) + { block->transparent=parent->transparent; + block->rendernormal=parent->rendernormal; + } else + { block->transparent=false; + block->rendernormal=true; + } if (b->has("liquid")) block->liquid=b->at("liquid")->asBool(); @@ -194,12 +237,12 @@ void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent, int pack else block->liquid=false; - if (b->has("cubesolid")) - block->cubesolid=b->at("cubesolid")->asBool(); + if (b->has("canProvidePower")) + block->providepower=b->at("canProvidePower")->asBool(); else if (parent!=NULL) - block->cubesolid=parent->cubesolid; + block->providepower=parent->providepower; else - block->cubesolid=false; + block->providepower=false; if (b->has("color")) { diff --git a/blockidentifier.h b/blockidentifier.h old mode 100644 new mode 100755 index a2f2b3e7..f22d7918 --- a/blockidentifier.h +++ b/blockidentifier.h @@ -47,10 +47,13 @@ class JSONObject; class BlockInfo { public: - BlockInfo() {} + BlockInfo(); bool isOpaque(); bool isLiquid(); - bool isTransparent(); + bool doesBlockHaveSolidTopSurface(int data); + bool isBlockNormalCube(); + bool renderAsNormalBlock(); + bool canProvidePower(); int id; QString name; @@ -59,7 +62,8 @@ class BlockInfo bool enabled; bool transparent; bool liquid; - bool cubesolid; + bool rendernormal; + bool providepower; quint32 colors[16]; }; diff --git a/definitions/vanilla_ids.json b/definitions/vanilla_ids.json old mode 100644 new mode 100755 index 10541dd0..6d46aa5b --- a/definitions/vanilla_ids.json +++ b/definitions/vanilla_ids.json @@ -215,7 +215,7 @@ "name": "Oak Leaves", "color": "3d9b3d", "transparent": true, - "cubesolid": true, + "rendercube": true, "mask": 3, "variants": [ { @@ -245,8 +245,7 @@ "name": "Glass", "color": "c0f5fe", "alpha": 0.5, - "transparent": true, - "cubesolid": true + "transparent": true }, { "id": 21, @@ -301,14 +300,14 @@ "id": 28, "name": "Detector Rail", "color": "7d7171", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 29, "name": "Sticky Piston", "color": "7bc070", - "transparent": true, - "cubesolid": true + "transparent": true }, { "id": 30, @@ -346,8 +345,7 @@ "id": 33, "name": "Piston", "color": "9f844d", - "transparent": true, - "cubesolid": true + "transparent": true }, { "id": 34, @@ -620,8 +618,7 @@ "id": 46, "name": "TNT", "color": "a83414", - "transparent": true, - "cubesolid": true + "transparent": true }, { "id": 47, @@ -655,7 +652,7 @@ "name": "Monster Spawner", "color": "1b2a35", "transparent": true, - "cubesolid": true + "rendercube": true }, { "id": 53, @@ -766,13 +763,15 @@ "id": 69, "name": "Lever", "color": "735e39", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 70, "name": "Stone Pressure Plate", "color": "8f8f8f", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 71, @@ -784,7 +783,8 @@ "id": 72, "name": "Wooden Pressure Plate", "color": "bc9862", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 73, @@ -800,19 +800,22 @@ "id": 75, "name": "Redstone Torch (off)", "color": "480000", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 76, "name": "Redstone Torch (on)", "color": "fd0000", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 77, "name": "Stone Button", "color": "a8a8a8", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 78, @@ -826,7 +829,7 @@ "color": "77a9ff", "alpha": 0.62, "transparent": true, - "cubesolid": true + "rendercube": true }, { "id": 80, @@ -879,9 +882,7 @@ { "id": 89, "name": "Glowstone Block", - "color": "f9d49c", - "transparent": true, - "cubesolid": true + "color": "f9d49c" }, { "id": 90, @@ -904,20 +905,21 @@ "id": 93, "name": "Redstone Repeater (off)", "color": "2a0002", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 94, "name": "Redstone Repeater (on)", "color": "fd0101", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 95, "name": "White Stained Glass", "color": "ffffff", "transparent": true, - "cubesolid": true, "alpha": 0.5, "variants": [ { @@ -1250,6 +1252,8 @@ "name": "End Portal Frame", "color": "2f5754", "mask": 4, + "transparent": true, + "rendercube": true, "variants": [ { "data": 4, @@ -1277,8 +1281,7 @@ "id": 124, "name": "Redstone Lamp (on)", "color": "f1d1af", - "transparent": true, - "cubesolid": true + "transparent": true }, { "id": 125, @@ -1380,7 +1383,8 @@ "id": 131, "name": "Tripwire Hook", "color": "6e6e6e", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 132, @@ -1520,7 +1524,8 @@ "id": 143, "name": "Wooden Button", "color": "b4905a", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 144, @@ -1538,43 +1543,50 @@ "id": 146, "name": "Trapped Chest", "color": "ab792d", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 147, "name": "Weighted Pressure Plate (Light)", "color": "fdfb4f", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 148, "name": "Weighted Pressure Plate (Heavy)", "color": "e6e6e6", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 149, - "name": "Redstone Comparator (inaktiv)", + "name": "Redstone Comparator (off)", "color": "4f1010", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 150, - "name": "Redstone Comparator (aktiv)", + "name": "Redstone Comparator (on)", "color": "fd1010", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 151, "name": "Daylight Sensor", "color": "d2c1ab", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 152, "name": "Redstone Block", "color": "bb1c0a", - "transparent": true + "transparent": true, + "canProvidePower": true }, { "id": 153, @@ -1802,7 +1814,7 @@ "name": "Acacia Leaves", "color": "97a636", "transparent": true, - "cubesolid": true, + "rendercube": true, "mask": 1, "variants": [ { diff --git a/mapview.cpp b/mapview.cpp old mode 100644 new mode 100755 index 5f7e9333..36d19806 --- a/mapview.cpp +++ b/mapview.cpp @@ -402,10 +402,14 @@ void MapView::renderChunk(Chunk *chunk) colb = colb * (256 - (depth - y)) / 256; } if ( (flags & flgMobSpawn) && (mlight<8) && - ((block.flags & BlockTransparent) == 0) && - ((block.flags & BlockLiquid) == 0) ) + block.doesBlockHaveSolidTopSurface(data) && + !block.name.contains("Bedrock") ) { // check for 2 air blocks above + // to be correct we would have to test for: + // block1: !isBlockNormalCube && !isLiquid + // block2: !isBlockNormalCube + // and then check the bounding box of the mob... quint16 block1 = 0; // default to air quint16 block2 = 0; // default to air ChunkSection *section2=chunk->sections[(y+2)>>4];