aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ReadOnlyChunkCache.cpp
blob: dfafdf2d507ecc0adddaef037f2e81502c846269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "ReadOnlyChunkCache.h"
#include "Biome.h"

ReadOnlyChunkCache::ReadOnlyChunkCache(Level *level, ChunkStorage *storage)
{
	chunks = LevelChunkArray(LEN * LEN);
	emptyPixels = byteArray(Level::CHUNK_TILE_COUNT);

    this->level = level;
    this->storage = storage;
}

ReadOnlyChunkCache::~ReadOnlyChunkCache()
{	
	for(unsigned int i = 0; i < chunks.length; ++i)
		delete chunks[i];

	delete[] chunks.data;

	delete[] emptyPixels.data;
}

bool ReadOnlyChunkCache::hasChunk(int x, int z)
{
    int slot = (x & LEN_MASK) | ((z & LEN_MASK) * LEN);
    return chunks[slot] != nullptr && (chunks[slot]->isAt(x, z));
}

LevelChunk *ReadOnlyChunkCache::create(int x, int z)
{
	return getChunk(x, z);
}

LevelChunk *ReadOnlyChunkCache::getChunk(int x, int z)
{
    int slot = (x & LEN_MASK) | ((z & LEN_MASK) * LEN);
	// 4J - removed try/catch
//    try {
        if (!hasChunk(x, z))
		{
            LevelChunk *newChunk = load(x, z);
            if (newChunk == nullptr)
			{
                newChunk = new EmptyLevelChunk(level, emptyPixels, x, z);
            }
            chunks[slot] = newChunk;
        }
        return chunks[slot];
//    } catch (Exception e) {
//        e.printStackTrace();
//        return null;
//    }
}

LevelChunk *ReadOnlyChunkCache::load(int x, int z)
{
	// 4J - remove try/catch
//    try {
        return storage->load(level, x, z);
//    } catch (IOException e) {
//        e.printStackTrace();
//        return null;
//    }
}
	// 4J - TODO - was synchronized
void ReadOnlyChunkCache::postProcess(ChunkSource *parent, int x, int z)
{
}

bool ReadOnlyChunkCache::save(bool force, ProgressListener *progressListener)
{
	return true;
}

bool ReadOnlyChunkCache::tick()
{
	return false;
}

bool ReadOnlyChunkCache::shouldSave()
{
	return false;
}

wstring ReadOnlyChunkCache::gatherStats()
{
	return L"ReadOnlyChunkCache";
}

vector<Biome::MobSpawnerData *> *ReadOnlyChunkCache::getMobsAt(MobCategory *mobCategory, int x, int y, int z)
{
	return nullptr;
}

TilePos *ReadOnlyChunkCache::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z)
{
	return nullptr;
}