aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2021-05-07 19:40:22 +0200
committermakamys <makamys@outlook.com>2021-05-07 19:40:22 +0200
commit2eba035a4b02b0a8a0f4834d16ced168b352fcf3 (patch)
tree7aa49a7e58707a9ee1336dab26c0974f8b3edf04 /src/main/java/makamys/lodmod/renderer/ChunkMesh.java
parent063ebc49399c840e250d03d4ec4a1ce2f4f4345d (diff)
downloadNeodymium-2eba035a4b02b0a8a0f4834d16ced168b352fcf3.tar.gz
Neodymium-2eba035a4b02b0a8a0f4834d16ced168b352fcf3.tar.bz2
Neodymium-2eba035a4b02b0a8a0f4834d16ced168b352fcf3.zip
Save ChunkMeshes to disk (no loading yet)
Diffstat (limited to 'src/main/java/makamys/lodmod/renderer/ChunkMesh.java')
-rw-r--r--src/main/java/makamys/lodmod/renderer/ChunkMesh.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
index 2251da8..45510ef 100644
--- a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
@@ -1,7 +1,9 @@
package makamys.lodmod.renderer;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
+import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
@@ -14,6 +16,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.lwjgl.BufferUtils;
@@ -24,6 +27,9 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.nbt.NBTBase;
+import net.minecraft.nbt.NBTTagByteArray;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class ChunkMesh extends Mesh {
@@ -33,6 +39,8 @@ public class ChunkMesh extends Mesh {
int z;
Flags flags;
+ NBTBase nbtData;
+
public static int usedRAM = 0;
public static int instances = 0;
@@ -44,6 +52,7 @@ public class ChunkMesh extends Mesh {
this.quadCount = quadCount;
this.buffer = createBuffer(data, stringTable);
+ this.nbtData = new NBTTagByteArray(data);
usedRAM += buffer.limit();
instances++;
@@ -56,12 +65,28 @@ public class ChunkMesh extends Mesh {
this.flags = flags;
this.quadCount = quadCount;
- this.buffer = createBuffer(quads);
+ this.nbtData = toNBT(quads, quadCount);
+ // TODO move this somewhere else
+ List<String> nameList = (List<String>) ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).mapUploadedSprites.keySet().stream().collect(Collectors.toList());
+ this.buffer = createBuffer(((NBTTagByteArray)nbtData).func_150292_c(), nameList);
usedRAM += buffer.limit();
instances++;
}
+ private NBTBase toNBT(List<MeshQuad> quads, int quadCount) {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(quadCount * 6 * 13);
+ DataOutputStream out = new DataOutputStream(byteOut);
+ try {
+ for(int pass = 0; pass <= 9; pass++){
+ for(MeshQuad quad : quads) {
+ quad.writeToDisk(out, pass);
+ }
+ }
+ } catch(IOException e) {}
+ return new NBTTagByteArray(byteOut.toByteArray());
+ }
+
void destroy() {
usedRAM -= buffer.limit();
instances--;