Skip to content

Commit

Permalink
ItemMobs are now saved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeSilva committed Sep 29, 2015
1 parent a558157 commit d320e05
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 11 additions & 2 deletions source/mobs/ItemMob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ void ItemMob::updateMob(WorldObject &world)

void ItemMob::sendWifiUpdate() { }

void ItemMob::saveToFile(FILE* pFile) { }
void ItemMob::saveToFile(FILE* pFile)
{
int i = x;
int j = y;
fprintf(pFile,"%d %d %d %d %d ",i, j, blockID, amount, displayID);
}

void ItemMob::loadFromFile(FILE* pFile)
{
health = 0;
int i,j;
fscanf(pFile,"%d %d %d %d %d ",&i, &j, &blockID, &amount, &displayID);
x = i;
y = j;
health = 100;
}

void ItemMob::hurt(int hamount, int type)
Expand Down
1 change: 1 addition & 0 deletions source/mobs/ItemMob.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ItemMob : public BaseMob
this->vx = FixedPoint(true, (float((rand() % 10) + 40) / 100.f) * ((rand() % 2) ? -1.f : 1.f) * FixedPoint::SCALER);
else
this->vx = FixedPoint(true, ax * FixedPoint::SCALER);
alive = true;
}

~ItemMob() { }
Expand Down
17 changes: 11 additions & 6 deletions source/mobs/mobHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ static bool canMobSpawnHere(MobType type, WorldObject &world, int a, int b)
{
switch (type)
{
case MOB_PLAYER:
case MOB_PLAYER:
return canPlayerMobSpawnHere(world, a, b);
case MOB_MULTIPLAYER:
case MOB_MULTIPLAYER:
return canMultiplayerMobSpawnHere(world, a, b);
case MOB_ZOMBIE:
case MOB_ZOMBIE:
return canZombieMobSpawnHere(world, a, b);
case MOB_ANIMAL:
case MOB_ANIMAL:
return canAnimalMobSpawnHere(world, a, b);
case MOB_HEROBRINE:
case MOB_HEROBRINE:
return canHerobrineMobSpawnHere(world, a, b);
default:
case MOB_ITEM:
return true;
default:
showError("Checking spawn for non-existent mob type");
break;
}
Expand Down Expand Up @@ -150,6 +152,9 @@ static void newMob(MobType type, int x = 0, int y = 0)
case MOB_HEROBRINE:
mobs.push_back(BaseMob_ptr(new HerobrineMob(x, y)));
break;
case MOB_ITEM:
createItemMob(x,y,DIRT);
break;
default:
showError("Unknown Mob Spawned");
break;
Expand Down

0 comments on commit d320e05

Please sign in to comment.