aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2021-05-21 00:11:27 +0200
committermakamys <makamys@outlook.com>2021-05-21 06:28:22 +0200
commitf164f74e4c0391fcc557de22e6c1d07c5a4110aa (patch)
tree2163fef4510c424172e14778dfe239ad3aaf754f
parent4f42f761fd6a6511c0dfb34c15acca7f5b5e67c2 (diff)
downloadNeodymium-f164f74e4c0391fcc557de22e6c1d07c5a4110aa.tar.gz
Neodymium-f164f74e4c0391fcc557de22e6c1d07c5a4110aa.tar.bz2
Neodymium-f164f74e4c0391fcc557de22e6c1d07c5a4110aa.zip
SimpleChunkMesh: Don't access server's WorldChunkManager on client thread
I did this in an attempt to fix a bug I had with OWG, but it turned out to be caused by something else. Still, accessing the server's data structures from the client thread is bad form, so I'll keep it like this.
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java2
-rw-r--r--src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java26
2 files changed, 23 insertions, 5 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 534a508..8960d28 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -12,6 +12,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraftforge.event.world.ChunkEvent;
@@ -484,6 +485,7 @@ public class LODRenderer {
ChunkCoordIntPair coords = serverChunkLoadQueue.remove(0);
ChunkProviderServer chunkProviderServer = Minecraft.getMinecraft().getIntegratedServer().worldServers[0].theChunkProviderServer;
Chunk chunk = chunkProviderServer.currentChunkProvider.provideChunk(coords.chunkXPos, coords.chunkZPos);
+ SimpleChunkMesh.prepareFarChunkOnServer(chunk);
farChunks.add(chunk);
}
}
diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
index f9cfcbb..77b9a93 100644
--- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
@@ -38,6 +38,7 @@ public class SimpleChunkMesh extends Mesh {
public static int usedRAM;
public static int instances;
+ public static int divisions = 4;
private static boolean isSolid(Block block) {
return block.isBlockNormalCube() && block.isOpaqueCube() && block.renderAsNormalBlock();
@@ -48,8 +49,6 @@ public class SimpleChunkMesh extends Mesh {
}
public static List<SimpleChunkMesh> generateSimpleMeshes(Chunk target){
- int divisions = 4;
-
SimpleChunkMesh pass1 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 0);
SimpleChunkMesh pass2 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 1);
@@ -64,7 +63,11 @@ public class SimpleChunkMesh extends Mesh {
int xOff = divX * size;
int zOff = divZ * size;
- BiomeGenBase biome = target.getBiomeGenForWorldCoords(xOff, zOff, target.worldObj.getWorldChunkManager());
+ int biomeId = target.getBiomeArray()[xOff << 4 | zOff] & 255;
+ if(biomeId == 255) {
+ System.out.println("Missing biome data for chunk " + target.xPosition + ", " + target.zPosition);
+ }
+ BiomeGenBase biome = BiomeGenBase.getBiome(biomeId) == null ? BiomeGenBase.plains : BiomeGenBase.getBiome(biomeId);
for(y = 255; y > 0; y--) {
Block block = target.getBlock(xOff, y, zOff);
@@ -112,12 +115,12 @@ public class SimpleChunkMesh extends Mesh {
} else if(block instanceof BlockLeaves) {
color = biome.getBiomeFoliageColor(worldX, y, worldZ);
} else {
- color = block.colorMultiplier(target.worldObj, worldX, y, worldZ);
+ color = block.colorMultiplier(Minecraft.getMinecraft().theWorld, worldX, y, worldZ);
}
color = (0xFF << 24) | ((color >> 16 & 0xFF) << 0) | ((color >> 8 & 0xFF) << 8) | ((color >> 0 & 0xFF) << 16);
if(biome.getFloatTemperature(worldX, y, worldZ) < 0.15f) {
- pass1.addCube(worldX, worldY + 0.2f, worldZ, size, size, 1f, Blocks.snow_layer.getIcon(1, 0), Blocks.snow_layer.colorMultiplier(target.worldObj, worldX, y, worldZ), brightnessMult);
+ pass1.addCube(worldX, worldY + 0.2f, worldZ, size, size, 1f, Blocks.snow_layer.getIcon(1, 0), Blocks.snow_layer.colorMultiplier(Minecraft.getMinecraft().theWorld, worldX, y, worldZ), brightnessMult);
pass1.addCube(worldX, worldY - 0.8f, worldZ, size, size, worldY + 1 - 0.8f, icon, color, brightnessMult);
} else {
pass1.addCube(worldX, worldY, worldZ, size, size, worldY + 1, icon, color, brightnessMult);
@@ -237,4 +240,17 @@ public class SimpleChunkMesh extends Mesh {
instances--;
}
+ public static void prepareFarChunkOnServer(Chunk chunk) {
+ for(int divX = 0; divX < divisions; divX++) {
+ for(int divZ = 0; divZ < divisions; divZ++) {
+ int size = 16 / divisions;
+
+ int xOff = divX * size;
+ int zOff = divZ * size;
+
+ chunk.getBiomeGenForWorldCoords(xOff, zOff, chunk.worldObj.getWorldChunkManager());
+ }
+ }
+ }
+
}