Skip to content

Commit

Permalink
Call world biome retrieval methods instead of copying array directly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 authored Dec 6, 2023
1 parent 0206f7d commit 2ca80dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class WorldSlice implements IBlockAccess {
private ClonedChunkSection[] sections;

// Biome data for each chunk section
private byte[][] biomeData;
private BiomeGenBase[][] biomeData;

// The starting point from which this slice captures blocks
private int baseX, baseY, baseZ;
Expand Down Expand Up @@ -126,7 +126,7 @@ public WorldSlice(WorldClient world) {
this.sections = new ClonedChunkSection[SECTION_TABLE_ARRAY_SIZE];
this.blockArrays = new Block[SECTION_TABLE_ARRAY_SIZE][];
this.metadataArrays = new int[SECTION_TABLE_ARRAY_SIZE][];
this.biomeData = new byte[SECTION_TABLE_ARRAY_SIZE][];
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];

for (int x = 0; x < SECTION_LENGTH; x++) {
for (int y = 0; y < SECTION_LENGTH; y++) {
Expand Down Expand Up @@ -210,9 +210,8 @@ public BiomeGenBase getBiomeGenForCoords(int x, int z) {
int relY = 0;
int relZ = z - this.baseZ;

final int k = this.biomeData[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)]
[(x & 15) | (z & 15) << 4] & 255;
BiomeGenBase biome = BiomeGenBase.getBiome(k);
BiomeGenBase biome = this.biomeData[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)]
[(x & 15) | (z & 15) << 4];
// can be null if biome wasn't generated yet
return biome == null ? BiomeGenBase.plains : biome;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.gen.structure.StructureBoundingBox;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

public class ClonedChunkSection {
Expand All @@ -33,7 +32,7 @@ public class ClonedChunkSection {
private ChunkSectionPos pos;

@Getter
private byte[] biomeData;
private BiomeGenBase[] biomeData;

private long lastUsedTimestamp = Long.MAX_VALUE;

Expand All @@ -59,13 +58,13 @@ public void init(ChunkSectionPos pos) {
this.pos = pos;
this.data = new ExtendedBlockStorageExt(section);

this.biomeData = Arrays.copyOf(chunk.getBiomeArray(), chunk.getBiomeArray().length);
this.biomeData = new BiomeGenBase[chunk.getBiomeArray().length];

StructureBoundingBox box = new StructureBoundingBox(pos.getMinX(), pos.getMinY(), pos.getMinZ(), pos.getMaxX(), pos.getMaxY(), pos.getMaxZ());

this.tileEntities.clear();

// Check for tile entities
// Check for tile entities & fill biome data
for(int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
for(int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
for(int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
Expand All @@ -82,6 +81,7 @@ public void init(ChunkSectionPos pos) {
this.tileEntities.put(ChunkSectionPos.packLocal(new BlockPos(tileentity.xCoord & 15, tileentity.yCoord & 15, tileentity.zCoord & 15)), tileentity);
}
}
this.biomeData[(lZ << 4) | lX] = world.getBiomeGenForCoords(x, z);
}
}
}
Expand All @@ -105,8 +105,7 @@ public int getLightLevel(EnumSkyBlock type, int x, int y, int z) {
}

public BiomeGenBase getBiomeForNoiseGen(int x, int y, int z) {
int k = this.biomeData[x | z << 4] & 255;
return BiomeGenBase.getBiome(k);
return this.biomeData[x | z << 4];

}

Expand Down

0 comments on commit 2ca80dc

Please sign in to comment.