Ma question est très semblable à cela, mais je ne pouvais pas travailler tout à fait dehors, comme le calcul doit être un peu différent: https://gamedev.stackexchange.com/questions/65800/when-storing-voxels-in-chunks-how-do-i-access-them-at-the-world-levelGet bloc voisin qui existe dans un morceau différent
Je suis en train de retirer quelques visages de blocs. J'ai du mal à trouver comment obtenir un bloc si c'est en dehors du segment actuel.
J'ai une classe Chunk qui garde la trace de ses propres blocs. Pour tester, mes morceaux sont 2 x 2, qui contient 4 blocs chacun, tous solides.
class Chunk {
private Blocks[,,] blocks;
public Vector3 position;
public Chunk(Vector3 world_pos){
position = world_position;
// Loops for populating blocks array...
...
// Create mesh
for(...){
for(...){
for(...){
Block block = GetBlock(x, y, z + 1); // Chance of this block being outside of this chunk
}
}
}
}
public Block GetBlock(int x, int y, int z){
...
// If block is not in this chunk, use global GetBlock instead
}
}
I ont une méthode à l'intérieur du bloc appelé « getBlock » qui tente d'obtenir un bloc sur la base des x, y, z et la position. Si les index sont hors de portée, j'appelle alors un "getBlock" global qui tente de trouver le bloc et le bloc à l'intérieur de celui-ci. C'est là que je me bats.
Ceci est ma méthode "getChunk" (pas mon code, trouvé dans un tutoriel), ce qui semble bien se passer.
public Chunk getChunk(int x, int y, int z){
float s = CHUNK_SIZE;
float d = CHUNK_DEPTH;
int posx = Mathf.FloorToInt(x/s) * CHUNK_SIZE;
int posy = Mathf.FloorToInt(y/d) * CHUNK_DEPTH;
int posz = Mathf.FloorToInt(z/s) * CHUNK_SIZE;
Chunk chunk = null;
this.chunks.TryGetValue(new Vector3(posx, posy, posz), out chunk);
return chunk;
}
Voici mon "getBlock" global.
public Block getBlock(int x, int y, int z){
Chunk chunk = this.getChunk(x, y, z);
Block block;
if(chunk == null){
block = Block_Types.AIR;
} else {
// Need to work out the block position I want here
int posx = x;
int posy = y;
int posz = z;
block = chunk.getBlock(posx, posy, posz);
}
return block;
}
Voici une photo si elle aide:
Merci
Cela serait vraiment bénéfique de creuser dans le code de morceau de Minecraft. Essentiellement, vous devez modifier les valeurs xyz des coordonnées du monde en coordonnées de morceau. – Draco18s