From d55ebcaf1ae6545650d925c4d6c95f8b67e8695d Mon Sep 17 00:00:00 2001 From: makamys Date: Sat, 2 Dec 2023 17:16:45 +0100 Subject: Move NeoRegion size to a constant --- .../java/makamys/neodymium/renderer/NeoRegion.java | 25 +++++++++++----------- .../makamys/neodymium/renderer/NeoRenderer.java | 7 ++++-- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main/java/makamys/neodymium/renderer/NeoRegion.java b/src/main/java/makamys/neodymium/renderer/NeoRegion.java index f983beb..36f5909 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRegion.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRegion.java @@ -3,8 +3,9 @@ package makamys.neodymium.renderer; import net.minecraft.entity.Entity; public class NeoRegion { + public static final int SIZE = 32; - private NeoChunk[][] data = new NeoChunk[32][32]; + private NeoChunk[][] data = new NeoChunk[SIZE][SIZE]; int regionX, regionZ; @@ -16,9 +17,9 @@ public class NeoRegion { this.regionX = regionX; this.regionZ = regionZ; - for(int i = 0; i < 32; i++) { - for(int j = 0; j < 32; j++) { - data[i][j] = new NeoChunk(regionX * 32 + i, regionZ * 32 + j, this); + for(int i = 0; i < SIZE; i++) { + for(int j = 0; j < SIZE; j++) { + data[i][j] = new NeoChunk(regionX * SIZE + i, regionZ * SIZE + j, this); } } } @@ -28,11 +29,11 @@ public class NeoRegion { } public NeoChunk getChunkAbsolute(int chunkXAbs, int chunkZAbs) { - return getChunk(chunkXAbs - regionX * 32, chunkZAbs - regionZ * 32); + return getChunk(chunkXAbs - regionX * SIZE, chunkZAbs - regionZ * SIZE); } public NeoChunk getChunk(int x, int z) { - if(x >= 0 && x < 32 && z >= 0 && z < 32) { + if(x >= 0 && x < SIZE && z >= 0 && z < SIZE) { return data[x][z]; } else { return null; @@ -40,8 +41,8 @@ public class NeoRegion { } public void tick() { - for(int i = 0; i < 32; i++) { - for(int j = 0; j < 32; j++) { + for(int i = 0; i < SIZE; i++) { + for(int j = 0; j < SIZE; j++) { NeoChunk chunk = data[i][j]; if(chunk != null) { chunk.tick(); @@ -57,8 +58,8 @@ public class NeoRegion { } public void destroy() { - for(int i = 0; i < 32; i++) { - for(int j = 0; j < 32; j++) { + for(int i = 0; i < SIZE; i++) { + for(int j = 0; j < SIZE; j++) { NeoChunk chunk = data[i][j]; if(chunk != null) { chunk.destroy(); @@ -68,8 +69,8 @@ public class NeoRegion { } public double distanceTaxicab(Entity entity) { - double centerX = ((regionX * 32) + 16) * 16; - double centerZ = ((regionZ * 32) + 16) * 16; + double centerX = ((regionX * SIZE) + SIZE / 2) * 16; + double centerZ = ((regionZ * SIZE) + SIZE / 2) * 16; return Math.max(Math.abs(centerX - entity.posX), Math.abs(centerZ - entity.posZ)); diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 9b33b91..3ded5da 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -566,10 +566,13 @@ public class NeoRenderer { } private NeoRegion getRegionContaining(int chunkX, int chunkZ) { - ChunkCoordIntPair key = new ChunkCoordIntPair(Math.floorDiv(chunkX , 32), Math.floorDiv(chunkZ, 32)); + int regionX = Math.floorDiv(chunkX, NeoRegion.SIZE); + int regionZ = Math.floorDiv(chunkZ, NeoRegion.SIZE); + ChunkCoordIntPair key = new ChunkCoordIntPair(regionX, regionZ); + NeoRegion region = loadedRegionsMap.get(key); if(region == null) { - region = NeoRegion.load(Math.floorDiv(chunkX , 32), Math.floorDiv(chunkZ , 32)); + region = NeoRegion.load(regionX, regionZ); loadedRegionsMap.put(key, region); } return region; -- cgit