Skip to content

Commit

Permalink
mob spawning now according Minecraft sources
Browse files Browse the repository at this point in the history
  • Loading branch information
EtlamGit authored and EtlamGit committed Jan 25, 2014
1 parent 71be2b5 commit fa6507d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 53 deletions.
63 changes: 53 additions & 10 deletions blockidentifier.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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();
Expand All @@ -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"))
{
Expand Down
10 changes: 7 additions & 3 deletions blockidentifier.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +62,8 @@ class BlockInfo
bool enabled;
bool transparent;
bool liquid;
bool cubesolid;
bool rendernormal;
bool providepower;
quint32 colors[16];
};

Expand Down
Loading

0 comments on commit fa6507d

Please sign in to comment.