NBT_Value* Furnace::getSlotEntity(int8_t slotNumber) { // Return null of we don't have anything in this slot if(m_slots[slotNumber].count == 0) { return NULL; } // Create a new slot NBT entity and add it's data NBT_Value* slot = new NBT_Value(NBT_Value::TAG_COMPOUND); slot->Insert("Count", new NBT_Value(m_slots[slotNumber].count)); slot->Insert("Damage", new NBT_Value(m_slots[slotNumber].damage)); slot->Insert("Slot", new NBT_Value(slotNumber)); slot->Insert("id", new NBT_Value(m_slots[slotNumber].id)); return slot; }
void BlockChest::onStartedDigging(User* user, int8_t status, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { // Locksystem if (user->inv[36 + user->currentItemSlot()].getType() == ITEM_WOODEN_AXE) { int chunk_x = blockToChunk(x); int chunk_z = blockToChunk(z); sChunk* chunk = ServerInstance->map(map)->loadMap(chunk_x, chunk_z); if (chunk == NULL) { return; } NBT_Value* entityList = (*(*(chunk->nbt))["Level"])["TileEntities"]; if (!entityList) { entityList = new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND); chunk->nbt->Insert("TileEntities", entityList); } if (entityList->GetType() == NBT_Value::TAG_LIST) { if (entityList->GetListType() != NBT_Value::TAG_COMPOUND) { entityList->SetType(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND); } std::vector<NBT_Value*> *entities = entityList->GetList(); std::vector<NBT_Value*>::iterator iter = entities->begin(), end = entities->end(); //bool done = false; // Unused variable for (; iter != end; iter++) { if ((**iter)["x"] == NULL || (**iter)["y"] == NULL || (**iter)["z"] == NULL || (**iter)["x"]->GetType() != NBT_Value::TAG_INT || (**iter)["y"]->GetType() != NBT_Value::TAG_INT || (**iter)["z"]->GetType() != NBT_Value::TAG_INT) { continue; } if ((int32_t)(*(**iter)["x"]) == x && (int32_t)(*(**iter)["y"]) == y && (int32_t)(*(**iter)["z"]) == z) { int8_t locked; NBT_Value* nbtLockdata = (**iter)["Lockdata"]; if (nbtLockdata != NULL) { std::string player = *(*nbtLockdata)["player"]->GetString(); // Toggle lock if player is the owner of block if (player == user->nick) { locked = *(*nbtLockdata)["locked"]; locked = (locked == 1) ? 0 : 1; *(*nbtLockdata)["locked"] = locked; if (locked == 1) { ServerInstance->chat()->sendMsg(user, MC_COLOR_RED + "Chest locked", Chat::USER); } else { ServerInstance->chat()->sendMsg(user, MC_COLOR_RED + "Chest opened", Chat::USER); } } } else { // If lockdata is missing (old chest) NBT_Value* nbtLock = new NBT_Value(NBT_Value::TAG_COMPOUND); nbtLock->Insert("player", new NBT_Value(user->nick)); nbtLock->Insert("locked", new NBT_Value((int8_t)1)); (*iter)->Insert("Lockdata", nbtLock); } break; } } } } }
void NetherGen::generateChunk(int x, int z, int map) { NBT_Value* main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value* val = new NBT_Value(NBT_Value::TAG_COMPOUND); val->Insert("Sections", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("HeightMap", new NBT_Value(heightmap)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((int64_t)time(NULL))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((char)1)); main->Insert("Level", val); /* uint32_t chunkid; ServerInstance->map()->posToId(x, z, &chunkid); ServerInstance->map()->maps[chunkid].x = x; ServerInstance->map()->maps[chunkid].z = z; */ sChunk* chunk = new sChunk(); //chunk->blocks = &((*t_blocks)[0]); //chunk->data = &((*t_data)[0]); //chunk->blocklight = &((*t_blocklight)[0]); //chunk->skylight = &((*t_skylight)[0]); chunk->heightmap = &(heightmap[0]); chunk->nbt = main; chunk->x = x; chunk->z = z; ServerInstance->map(map)->chunks.insert(ChunkMap::value_type(ChunkMap::key_type(x, z), chunk)); memset(chunk->blocks, 0, 16*16*256); memset(chunk->addblocks, 0, 16*16*256/2); memset(chunk->data, 0, 16*16*256/2); memset(chunk->blocklight, 0, 16*16*256/2); memset(chunk->skylight, 0, 16*16*256/2); chunk->chunks_present = 0xffff; generateWithNoise(x, z, map); // Update last used time //ServerInstance->map()->mapLastused[chunkid] = (int)time(0); // Not changed //ServerInstance->map()->mapChanged[chunkid] = ServerInstance->config()->bData("save_unchanged_chunks"); //ServerInstance->map()->maps[chunkid].nbt = main; if (addOre) { AddOre(x, z, map, BLOCK_GLOWSTONE); AddOre(x, z, map, BLOCK_STATIONARY_LAVA); } // Add trees if (addTrees) { AddTrees(x, z, map, fastrand() % 2 + 3); } if (expandBeaches) { ExpandBeaches(x, z, map); } }
void MapGen::generateChunk(int x, int z, int map) { NBT_Value *main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value *val = new NBT_Value(NBT_Value::TAG_COMPOUND); val->Insert("Blocks", new NBT_Value(blocks)); val->Insert("Data", new NBT_Value(blockdata)); val->Insert("SkyLight", new NBT_Value(skylight)); val->Insert("BlockLight", new NBT_Value(blocklight)); val->Insert("HeightMap", new NBT_Value(heightmap)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((int64_t)time(NULL))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((int8_t)1)); main->Insert("Level", val); /* uint32_t chunkid; Mineserver::get()->map()->posToId(x, z, &chunkid); Mineserver::get()->map()->maps[chunkid].x = x; Mineserver::get()->map()->maps[chunkid].z = z; */ std::vector<uint8_t> *t_blocks = (*val)["Blocks"]->GetByteArray(); std::vector<uint8_t> *t_data = (*val)["Data"]->GetByteArray(); std::vector<uint8_t> *t_blocklight = (*val)["BlockLight"]->GetByteArray(); std::vector<uint8_t> *t_skylight = (*val)["SkyLight"]->GetByteArray(); std::vector<uint8_t> *heightmap = (*val)["HeightMap"]->GetByteArray(); sChunk *chunk = new sChunk(); chunk->blocks = &((*t_blocks)[0]); chunk->data = &((*t_data)[0]); chunk->blocklight = &((*t_blocklight)[0]); chunk->skylight = &((*t_skylight)[0]); chunk->heightmap = &((*heightmap)[0]); chunk->nbt = main; chunk->x = x; chunk->z = z; Mineserver::get()->map(map)->chunks.linkChunk(chunk, x, z); if(Mineserver::get()->config()->bData("mapgen.flatgrass")) generateFlatgrass(x, z, map); else generateWithNoise(x, z, map); // Update last used time //Mineserver::get()->map()->mapLastused[chunkid] = (int)time(0); // Not changed chunk->changed = Mineserver::get()->config()->bData("map.save_unchanged_chunks"); //Mineserver::get()->map()->maps[chunkid].nbt = main; if(addOre) { AddOre(x, z, map, BLOCK_COAL_ORE); AddOre(x, z, map, BLOCK_IRON_ORE); AddOre(x, z, map, BLOCK_GOLD_ORE); AddOre(x, z, map, BLOCK_DIAMOND_ORE); AddOre(x, z, map, BLOCK_REDSTONE_ORE); AddOre(x, z, map, BLOCK_LAPIS_ORE); } AddOre(x, z, map, BLOCK_GRAVEL); // Add trees if(addTrees) AddTrees(x, z, map); // add trees will make a *kind-of* forest of 16*16 chunks if(expandBeaches) ExpandBeaches(x, z, map); }
void HeavenGen::generateChunk(int x, int z, int map) { NBT_Value* main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value* val = new NBT_Value(NBT_Value::TAG_COMPOUND); generateWithNoise(x, z, map); val->Insert("Blocks", new NBT_Value(heavenblocks)); val->Insert("Data", new NBT_Value(blockdata)); val->Insert("SkyLight", new NBT_Value(skylight)); val->Insert("BlockLight", new NBT_Value(blocklight)); val->Insert("HeightMap", new NBT_Value(heightmap)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((int64_t)time(NULL))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((char)1)); main->Insert("Level", val); /* uint32_t chunkid; Mineserver::get()->map()->posToId(x, z, &chunkid); Mineserver::get()->map()->maps[chunkid].x = x; Mineserver::get()->map()->maps[chunkid].z = z; */ std::vector<uint8_t> *t_blocks = (*val)["Blocks"]->GetByteArray(); std::vector<uint8_t> *t_data = (*val)["Data"]->GetByteArray(); std::vector<uint8_t> *t_blocklight = (*val)["BlockLight"]->GetByteArray(); std::vector<uint8_t> *t_skylight = (*val)["SkyLight"]->GetByteArray(); std::vector<uint8_t> *heightmap = (*val)["HeightMap"]->GetByteArray(); sChunk* chunk = new sChunk(); chunk->blocks = &((*t_blocks)[0]); chunk->data = &((*t_data)[0]); chunk->blocklight = &((*t_blocklight)[0]); chunk->skylight = &((*t_skylight)[0]); chunk->heightmap = &((*heightmap)[0]); chunk->nbt = main; chunk->x = x; chunk->z = z; Mineserver::get()->map(map)->chunks.linkChunk(chunk, x, z); // Update last used time //Mineserver::get()->map()->mapLastused[chunkid] = (int)time(0); // Not changed //Mineserver::get()->map()->mapChanged[chunkid] = Mineserver::get()->config()->bData("save_unchanged_chunks"); //Mineserver::get()->map()->maps[chunkid].nbt = main; if (addOre) { AddOre(x, z, map, BLOCK_STATIONARY_WATER); } // Add trees if (addTrees) { AddTrees(x, z, map, fastrand() % 2 + 3); } if (expandBeaches) { ExpandBeaches(x, z, map); } }
void BiomeGen::generateChunk(int x, int z, int map) { NBT_Value* main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value* val = new NBT_Value(NBT_Value::TAG_COMPOUND); val->Insert("Sections", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("HeightMap", new NBT_Value(heightmap)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((int64_t)time(NULL))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((int8_t)1)); main->Insert("Level", val); sChunk* chunk = new sChunk(); //chunk->blocks = new uint8_t[16 * 16 * 256]; //chunk->addblocks = new uint8_t[16 * 16 * 256 / 2]; //chunk->data = new uint8_t[16 * 16 * 256 / 2]; //chunk->blocklight = new uint8_t[16 * 16 * 256 / 2]; //chunk->skylight = new uint8_t[16 * 16 * 256 / 2]; chunk->heightmap = &((*(*val)["HeightMap"]->GetIntArray())[0]); heightmap_pointer = chunk->heightmap; chunk->nbt = main; chunk->x = x; chunk->z = z; memset(chunk->blocks, 0, 16*16*256); memset(chunk->addblocks, 0, 16*16*256/2); memset(chunk->data, 0, 16*16*256/2); memset(chunk->blocklight, 0, 16*16*256/2); memset(chunk->skylight, 0, 16*16*256/2); chunk->chunks_present = 0xffff; ServerInstance->map(map)->chunks.insert(ChunkMap::value_type(ChunkMap::key_type(x, z), chunk)); if (ServerInstance->config()->bData("mapgen.flatgrass")) { generateFlatgrass(x, z, map); } else { generateWithNoise(x, z, map); } // Update last used time //ServerInstance->map()->mapLastused[chunkid] = (int)time(0); // Not changed chunk->changed = ServerInstance->config()->bData("map.save_unchanged_chunks"); //ServerInstance->map()->maps[chunkid].nbt = main; if (addOre) { AddOre(x, z, map, BLOCK_COAL_ORE); AddOre(x, z, map, BLOCK_IRON_ORE); AddOre(x, z, map, BLOCK_GOLD_ORE); AddOre(x, z, map, BLOCK_DIAMOND_ORE); AddOre(x, z, map, BLOCK_REDSTONE_ORE); AddOre(x, z, map, BLOCK_LAPIS_ORE); } AddOre(x, z, map, BLOCK_GRAVEL); // Add trees if (addTrees) { AddTrees(x, z, map); // add trees will make a *kind-of* forest of 16*16 chunks } }
bool User::saveData() { std::string outfile = Map::get().mapDirectory+"/players/"+this->nick+".dat"; // Try to create parent directories if necessary struct stat stFileInfo; if(stat(outfile.c_str(), &stFileInfo) != 0) { std::string outdir = Map::get().mapDirectory+"/players"; if(stat(outdir.c_str(), &stFileInfo) != 0) { #ifdef WIN32 if(_mkdir(outdir.c_str()) == -1) #else if(mkdir(outdir.c_str(), 0755) == -1) #endif return false; } } NBT_Value val(NBT_Value::TAG_COMPOUND); val.Insert("OnGround", new NBT_Value((sint8)1)); val.Insert("Air", new NBT_Value((sint16)300)); val.Insert("AttackTime", new NBT_Value((sint16)0)); val.Insert("DeathTime", new NBT_Value((sint16)0)); val.Insert("Fire", new NBT_Value((sint16)-20)); val.Insert("Health", new NBT_Value((sint16)20)); val.Insert("HurtTime", new NBT_Value((sint16)0)); val.Insert("FallDistance", new NBT_Value(54.f)); NBT_Value *nbtInv = new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND); //Start with main items Item *slots = (Item *)&inv.main; char slotid = 0; char itemslot = 0; for(int i = 0; i < 36+4+4; i++) { //Crafting items after main if(i == 36) { slots = (Item *)&inv.crafting; itemslot = 80; slotid = 0; } //Equipped items last else if(i == 36+4) { slots = (Item *)&inv.equipped; itemslot = 100; slotid = 0; } if(slots[(uint8)slotid].count) { NBT_Value *val = new NBT_Value(NBT_Value::TAG_COMPOUND); val->Insert("Count", new NBT_Value((sint8)slots[(uint8)slotid].count)); val->Insert("Slot", new NBT_Value((sint8)itemslot)); val->Insert("Damage", new NBT_Value((sint16)slots[(uint8)slotid].health)); val->Insert("id", new NBT_Value((sint16)slots[(uint8)slotid].type)); nbtInv->GetList()->push_back(val); } slotid++; itemslot++; } val.Insert("Inventory", nbtInv); NBT_Value *nbtPos = new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_DOUBLE); nbtPos->GetList()->push_back(new NBT_Value((double)pos.x)); nbtPos->GetList()->push_back(new NBT_Value((double)pos.y)); nbtPos->GetList()->push_back(new NBT_Value((double)pos.z)); val.Insert("Pos", nbtPos); NBT_Value *nbtRot = new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_FLOAT); nbtRot->GetList()->push_back(new NBT_Value((float)pos.yaw)); nbtRot->GetList()->push_back(new NBT_Value((float)pos.pitch)); val.Insert("Rotation", nbtRot); NBT_Value *nbtMotion = new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_DOUBLE); nbtMotion->GetList()->push_back(new NBT_Value((double)0.0)); nbtMotion->GetList()->push_back(new NBT_Value((double)0.0)); nbtMotion->GetList()->push_back(new NBT_Value((double)0.0)); val.Insert("Motion", nbtMotion); val.SaveToFile(outfile); return true; }
void MapGen::generateChunk(int x, int z) { NBT_Value *main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value *val = new NBT_Value(NBT_Value::TAG_COMPOUND); if(Mineserver::get()->config()->bData("mapgen.flatgrass")) generateFlatgrass(); else generateWithNoise(x, z); val->Insert("Blocks", new NBT_Value(blocks, 16*16*128)); val->Insert("Data", new NBT_Value(blockdata, 16*16*128/2)); val->Insert("SkyLight", new NBT_Value(skylight, 16*16*128/2)); val->Insert("BlockLight", new NBT_Value(blocklight, 16*16*128/2)); val->Insert("HeightMap", new NBT_Value(heightmap, 16*16)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((sint64)time(NULL))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((char)1)); main->Insert("Level", val); /* uint32 chunkid; Mineserver::get()->map()->posToId(x, z, &chunkid); Mineserver::get()->map()->maps[chunkid].x = x; Mineserver::get()->map()->maps[chunkid].z = z; */ std::vector<uint8> *t_blocks = (*val)["Blocks"]->GetByteArray(); std::vector<uint8> *t_data = (*val)["Data"]->GetByteArray(); std::vector<uint8> *t_blocklight = (*val)["BlockLight"]->GetByteArray(); std::vector<uint8> *t_skylight = (*val)["SkyLight"]->GetByteArray(); std::vector<uint8> *heightmap = (*val)["HeightMap"]->GetByteArray(); sChunk *chunk = new sChunk(); chunk->blocks = &((*t_blocks)[0]); chunk->data = &((*t_data)[0]); chunk->blocklight = &((*t_blocklight)[0]); chunk->skylight = &((*t_skylight)[0]); chunk->heightmap = &((*heightmap)[0]); chunk->nbt = main; chunk->x = x; chunk->z = z; Mineserver::get()->map()->chunks.LinkChunk(chunk, x, z); // Update last used time //Mineserver::get()->map()->mapLastused[chunkid] = (int)time(0); // Not changed //Mineserver::get()->map()->mapChanged[chunkid] = Mineserver::get()->config()->bData("save_unchanged_chunks"); //Mineserver::get()->map()->maps[chunkid].nbt = main; if(addOre) AddOres(x, z); // Add trees if(addTrees) AddTrees(x, z); if(expandBeaches) ExpandBeaches(x, z); }
void EximGen::generateChunk(int x, int z, int map) { NBT_Value* main = new NBT_Value(NBT_Value::TAG_COMPOUND); NBT_Value* val = new NBT_Value(NBT_Value::TAG_COMPOUND); val->Insert("Sections", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("HeightMap", new NBT_Value(heightmap)); val->Insert("Entities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("TileEntities", new NBT_Value(NBT_Value::TAG_LIST, NBT_Value::TAG_COMPOUND)); val->Insert("LastUpdate", new NBT_Value((int64_t)time(nullptr))); val->Insert("xPos", new NBT_Value(x)); val->Insert("zPos", new NBT_Value(z)); val->Insert("TerrainPopulated", new NBT_Value((int8_t)1)); main->Insert("Level", val); sChunk* chunk = new sChunk(); NBT_Value* val1 = (*val)["HeightMap"]; chunk->heightmap = val1->GetIntArray()->data(); chunk->nbt = main; chunk->x = x<<4; chunk->z = z<<4; ServerInstance->map(map)->chunks.insert(ChunkMap::value_type(ChunkMap::key_type(x, z), chunk)); memset(chunk->blocks, 0, 16*16*256); memset(chunk->addblocks, 0, 16*16*256/2); memset(chunk->data, 0, 16*16*256/2); memset(chunk->blocklight, 0, 16*16*256/2); memset(chunk->skylight, 0, 16*16*256/2); chunk->chunks_present = 0xffff; ChunkInfo info(chunk); if (ServerInstance->config()->bData("mapgen.flatgrass")) { generateFlatgrass(x, z, map); } else { generateWithNoise(info); } // Not changed chunk->changed = ServerInstance->config()->bData("map.save_unchanged_chunks"); if (false && addOre) { AddOre(x, z, map, BLOCK_COAL_ORE); AddOre(x, z, map, BLOCK_IRON_ORE); AddOre(x, z, map, BLOCK_GOLD_ORE); AddOre(x, z, map, BLOCK_DIAMOND_ORE); AddOre(x, z, map, BLOCK_REDSTONE_ORE); AddOre(x, z, map, BLOCK_LAPIS_ORE); } //AddOre(x, z, map, BLOCK_GRAVEL); //AddOre(x, z, map, BLOCK_DIRT); // guess what, dirt also exists underground // Add trees if (addTrees) { //AddTrees(x, z, map); } if (expandBeaches) { //ExpandBeaches(x, z, map); } // AddRiver(x, z, map); }