From d320e0573c4d55428588a6972c3da726d5003ee9 Mon Sep 17 00:00:00 2001 From: CoolAs Date: Tue, 29 Sep 2015 10:56:27 +1000 Subject: [PATCH] ItemMobs are now saved correctly --- source/mobs/ItemMob.cpp | 13 +++++++++++-- source/mobs/ItemMob.h | 1 + source/mobs/mobHandler.cpp | 17 +++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/source/mobs/ItemMob.cpp b/source/mobs/ItemMob.cpp index be3a91c1..3bd2f484 100644 --- a/source/mobs/ItemMob.cpp +++ b/source/mobs/ItemMob.cpp @@ -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) diff --git a/source/mobs/ItemMob.h b/source/mobs/ItemMob.h index 6df7cebf..560dc2c1 100644 --- a/source/mobs/ItemMob.h +++ b/source/mobs/ItemMob.h @@ -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() { } diff --git a/source/mobs/mobHandler.cpp b/source/mobs/mobHandler.cpp index 202fecfb..bd2a3fd3 100644 --- a/source/mobs/mobHandler.cpp +++ b/source/mobs/mobHandler.cpp @@ -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; } @@ -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;