Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit f46cbc0

Browse files
committed
Sapling
1 parent 0cf4538 commit f46cbc0

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

Palette.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace BuildPlate_Editor
88
{
99
public class Palette
1010
{
11+
public static readonly Palette NULL = new Palette("bpe:null", 0, new int[0]);
12+
1113
public int[] textures;
1214
public int data;
1315
public string name;

Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static void Main(string[] args)
9898
#if DEBUG
9999
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json";
100100
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json"; // fancy
101+
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0eb3037-94c1-4a85-b0d7-7b8375c6f1b1.json"; // redstone
101102
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\2cb8bda2-c49b-4ead-887f-593d37bc2784.json";
102103
#else
103104
Console.Write("Build plate to edit (.json): ");

World.cs

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,27 @@ public static class World
710710
},
711711
{ "cactus", (int data) => new [] { "cactus_side.tga", "cactus_top.tga", "cactus_bottom.tga" }
712712
},
713+
{ "sapling", (int data) =>
714+
{
715+
int type = data & 0b_0111;
716+
switch (type) {
717+
case 0:
718+
return new [] { "sapling_oak" };
719+
case 1:
720+
return new [] { "sapling_spruce" };
721+
case 2:
722+
return new [] { "sapling_birch" };
723+
case 3:
724+
return new [] { "sapling_jungle" };
725+
case 4:
726+
return new [] { "sapling_acacia" };
727+
case 5:
728+
return new [] { "sapling_roofed_oak" }; // dark oak
729+
default:
730+
return new [] { "sapling_oak" };
731+
}
732+
}
733+
},
713734
// doors
714735
{ "iron_door", (int data) =>
715736
{
@@ -838,6 +859,7 @@ public static class World
838859
{ "brown_mushroom", 8 },
839860
{ "deadbush", 8 },
840861
{ "buttercup", 8 },
862+
{ "sapling", 8 },
841863
{ "iron_bars", 9 },
842864
{ "ladder", 10 },
843865
{ "lantern", 11 },
@@ -850,6 +872,7 @@ public static class World
850872
{ "vine", 19 },
851873
{ "grass", 20 },
852874
{ "cactus", 21 },
875+
{ "water", 22 },
853876
};
854877

855878
public static readonly bool[] RendererIsFullBlockLookUp = new bool[]
@@ -881,11 +904,25 @@ public static class World
881904
// TODO stair other corner, Data meaning from: https://minecraft.fandom.com/wiki/Block_states
882905
public static Dictionary<int, RenderBlock> blockRenderers = new Dictionary<int, RenderBlock>()
883906
{
884-
{ 0, (Vector3 pos, Vector3i cp, int[] tex, int data, ref List<Vertex> vertices, ref List<uint> triangles) => // full
907+
{ 0, (Vector3 pos, Vector3i cp, int[] texA, int data, ref List<Vertex> verts, ref List<uint> tris) => // full
885908
{
886909
Vector3 offset = new Vector3(0f, 0f, 0f);
887910
Vector3 size = new Vector3(1f, 1f, 1f);
888-
CubeTex(tex[0], pos + offset, size, ref vertices, ref triangles);
911+
uint tex = (uint)texA[0];
912+
913+
for (int p = 0; p < 6; p++) {
914+
uint firstVertIndex = (uint)verts.Count;
915+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 0]] * size - size / 2f, VoxelData.voxelUvs[0], tex));
916+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 1]] * size - size / 2f, VoxelData.voxelUvs[1], tex));
917+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 2]] * size - size / 2f, VoxelData.voxelUvs[2], tex));
918+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 3]] * size - size / 2f, VoxelData.voxelUvs[3], tex));
919+
tris.Add(firstVertIndex);
920+
tris.Add(firstVertIndex + 1);
921+
tris.Add(firstVertIndex + 2);
922+
tris.Add(firstVertIndex + 2);
923+
tris.Add(firstVertIndex + 1);
924+
tris.Add(firstVertIndex + 3);
925+
}
889926
}
890927
},
891928
{ 1, (Vector3 pos, Vector3i cp, int[] texA, int data, ref List<Vertex> vertices, ref List<uint> triangles) => // slab
@@ -1616,6 +1653,32 @@ public static class World
16161653
}
16171654
}
16181655
},
1656+
{ 22, (Vector3 pos, Vector3i cp, int[] texA, int data, ref List<Vertex> verts, ref List<uint> tris) => // water
1657+
{
1658+
Vector3 offset = new Vector3(0f, 0f, 0f);
1659+
Vector3 size = new Vector3(1f, 1f, 1f);
1660+
uint tex = (uint)texA[0];
1661+
1662+
Vector3i iPos = new Vector3i((int)pos.X, (int)pos.Y, (int)pos.Z);
1663+
1664+
for (int p = 0; p < 6; p++) {
1665+
int rend = GetRenderer(iPos + cp + VoxelData.faceChecks[p]);
1666+
if (rend == 22)
1667+
continue;
1668+
uint firstVertIndex = (uint)verts.Count;
1669+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 0]] * size - size / 2f, VoxelData.voxelUvs[0], tex));
1670+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 1]] * size - size / 2f, VoxelData.voxelUvs[1], tex));
1671+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 2]] * size - size / 2f, VoxelData.voxelUvs[2], tex));
1672+
verts.Add(new Vertex(pos + VoxelData.voxelVerts[VoxelData.voxelTris[p, 3]] * size - size / 2f, VoxelData.voxelUvs[3], tex));
1673+
tris.Add(firstVertIndex);
1674+
tris.Add(firstVertIndex + 1);
1675+
tris.Add(firstVertIndex + 2);
1676+
tris.Add(firstVertIndex + 2);
1677+
tris.Add(firstVertIndex + 1);
1678+
tris.Add(firstVertIndex + 3);
1679+
}
1680+
}
1681+
},
16191682
};
16201683

16211684
private static BuildPlate plate;
@@ -1667,7 +1730,10 @@ public static Palette GetBlockPalette(Vector3i pos)
16671730
public static Palette GetBlockPalette(int x, int y, int z)
16681731
{
16691732
GetBlockIndex(x, y, z, out int subChunkIndex, out int blockIndex);
1670-
return GetBlockPalette(subChunkIndex, blockIndex);
1733+
if (subChunkIndex < 0)
1734+
return Palette.NULL;
1735+
else
1736+
return GetBlockPalette(subChunkIndex, blockIndex);
16711737
}
16721738
public static Palette GetBlockPalette(int subChunkIndex, int blockIndex)
16731739
=> chunks[subChunkIndex].palette[chunks[subChunkIndex].blocks[blockIndex]];

0 commit comments

Comments
 (0)