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

Commit c143ea0

Browse files
committed
Compatibility
+Rails +Doors (couldn't figure out how to get on which side hinge is, so not 100% accurate) +Buttons -GetBlockIndex() returns right index 100%
1 parent 048ba38 commit c143ea0

File tree

6 files changed

+373
-57
lines changed

6 files changed

+373
-57
lines changed

Maths/Vector3i.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public struct Vector3i
1313
{
1414
public static readonly Vector3i Zero = new Vector3i(0, 0, 0);
1515
public static readonly Vector3i One = new Vector3i(1, 1, 1);
16+
public static readonly Vector3i UnitX = new Vector3i(1, 0, 0);
17+
public static readonly Vector3i UnitY = new Vector3i(0, 1, 0);
18+
public static readonly Vector3i UnitZ = new Vector3i(0, 0, 1);
1619

1720
public int X;
1821
public int Y;

Palette.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public Palette(string _name, int _data, int[] _textures)
2424
public Palette(string _name, int _data, int _texture) : this(_name, _data, new int[1] { _texture })
2525
{ }
2626

27+
public static bool operator ==(Palette a, Palette b)
28+
=> a.textures.Length == b.textures.Length && a.data == b.data && a.name == b.name;
29+
public static bool operator !=(Palette a, Palette b)
30+
=> a.textures.Length != b.textures.Length || a.data != b.data || a.name != b.name;
31+
2732
public override string ToString() => $"Name: {name}, Numb tex: {textures.Length}, Data: {data}";
2833
}
2934
}

SubChunk.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void CreateMeshData()
6060

6161
origz = z;
6262
origy = y;
63+
origx = x;
6364

6465
if (z == 0) {
6566
z = 16;
@@ -69,6 +70,11 @@ public void CreateMeshData()
6970
if (y == -1)
7071
y = 16;
7172

73+
if (Math.Abs(z) % 16 == 0 && y == 16) {
74+
y--;
75+
x--;
76+
}
77+
7278
int renderer = renderers[currentBlock];
7379
if (renderer > -1 && blocks[currentBlock] < palette.Length) { // don't render air
7480
#if DEBUG
@@ -77,26 +83,27 @@ public void CreateMeshData()
7783
World.blockRenderers[renderer](new Vector3(x, y, z), pos * 16, pal.textures, pal.data,
7884
ref vertices, ref triangles);
7985
#else
80-
try {
81-
Palette pal = palette[blocks[currentBlock]];
82-
World.blockRenderers[renderer](new Vector3(x, y, z), pos * 16, pal.textures, pal.data,
83-
ref vertices, ref triangles);
84-
} catch (Exception ex) {
85-
uint b = blocks[currentBlock];
86-
string name = "Couldn't get";
87-
string data = "Couldn't get";
88-
if (b >= 0 && b < palette.Length) {
89-
name = palette[b].name;
90-
data = palette[b].data.ToString();
91-
}
92-
Util.Exit(EXITCODE.World_Render_Block, ex, $"Block ID: {blocks[currentBlock]}, SubChunk pos: {pos}, Renderer ID: {renderer}, " +
93-
$"Block Name: {name}, Block Data: {data}");
86+
try {
87+
Palette pal = palette[blocks[currentBlock]];
88+
World.blockRenderers[renderer](new Vector3(x, y, z), pos * 16, pal.textures, pal.data,
89+
ref vertices, ref triangles);
90+
} catch (Exception ex) {
91+
uint b = blocks[currentBlock];
92+
string name = "Couldn't get";
93+
string data = "Couldn't get";
94+
if (b >= 0 && b < palette.Length) {
95+
name = palette[b].name;
96+
data = palette[b].data.ToString();
9497
}
98+
Util.Exit(EXITCODE.World_Render_Block, ex, $"Block ID: {blocks[currentBlock]}, SubChunk pos: {pos}, Renderer ID: {renderer}, " +
99+
$"Block Name: {name}, Block Data: {data}");
100+
}
95101
#endif
96102
}
97103

98104
z = origz;
99105
y = origy;
106+
x = origx;
100107
}
101108
}
102109

@@ -197,6 +204,7 @@ public void GetBlockIndex(int bx, int by, int bz, out int blockIndex)
197204

198205
origz = z;
199206
origy = y;
207+
origx = x;
200208

201209
if (z == 0) {
202210
z = 16;
@@ -206,14 +214,19 @@ public void GetBlockIndex(int bx, int by, int bz, out int blockIndex)
206214
if (y == -1)
207215
y = 16;
208216

217+
if (Math.Abs(z) % 16 == 0 && y == 16) {
218+
y--;
219+
x--;
220+
}
221+
209222
if (new Vector3i(x, y, z) + offset == block) {
210223
blockIndex = currentBlock;
211224
return;
212225
}
213-
214226

215227
z = origz;
216228
y = origy;
229+
x = origx;
217230
}
218231

219232
blockIndex = -1;

VoxelData.cs

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace BuildPlate_Editor
1010
{
11-
public static class VoxelData
12-
{
13-
public const int ChunkWidth = 16;
14-
public const int ChunkHeight = 16;
15-
public const int ChunkLayerLength = ChunkWidth * ChunkWidth;
11+
public static class VoxelData
12+
{
13+
public const int ChunkWidth = 16;
14+
public const int ChunkHeight = 16;
15+
public const int ChunkLayerLength = ChunkWidth * ChunkWidth;
1616
public const int WorldSizeInChunks = 5;
1717

1818
public static readonly Vector3[] voxelVerts = new Vector3[8] {
@@ -52,7 +52,7 @@ public static class VoxelData
5252
};
5353

5454
public static class Slab
55-
{
55+
{
5656
public static readonly Vector3[] bottomVerts = new Vector3[8] {
5757
new Vector3(0.0f, 0.0f, 0.0f),
5858
new Vector3(1.0f, 0.0f, 0.0f),
@@ -137,7 +137,7 @@ public static class Torch // width = 0,125, height = 0,625, light part start = 0
137137
};
138138
}
139139
public static class Stair
140-
{
140+
{
141141
public static readonly Vector3[] zVerts = new Vector3[8] {
142142
new Vector3(0.0f, 0.0f, 0.0f),
143143
new Vector3(1.0f, 0.0f, 0.0f),
@@ -157,7 +157,7 @@ public static class Stair
157157
new Vector3(0.5f, 0.0f, 1.0f),
158158
new Vector3(0.5f, 0.5f, 1.0f),
159159
new Vector3(0.0f, 0.5f, 1.0f)
160-
};
160+
};
161161
public static readonly Vector3[] smallVerts = new Vector3[8] {
162162
new Vector3(0.0f, 0.0f, 0.0f),
163163
new Vector3(0.5f, 0.0f, 0.0f),
@@ -188,7 +188,7 @@ public static class Stair
188188
};
189189
}
190190
public static class Repeater
191-
{
191+
{
192192
public static readonly Vector3[] verts = new Vector3[8] {
193193
new Vector3(0.0f, 0.0f, 0.0f),
194194
new Vector3(1.0f, 0.0f, 0.0f),
@@ -207,7 +207,7 @@ public static class Repeater
207207
};
208208
}
209209
public static class SkyBox
210-
{
210+
{
211211
public static Vector3[] verts = new Vector3[] {
212212
// positions
213213
new Vector3(-1.0f, 1.0f, -1.0f),
@@ -255,11 +255,11 @@ public static class SkyBox
255255
public static uint[] tris;
256256

257257
static SkyBox()
258-
{
258+
{
259259
tris = new uint[verts.Length];
260-
for (uint i = 0; i < tris.Length; i++)
260+
for (uint i = 0; i < tris.Length; i++)
261261
tris[i] = i;
262-
}
262+
}
263263
}
264264
public static class Vine // -z, -x, +z, +x
265265
{
@@ -280,7 +280,7 @@ public static class Vine // -z, -x, +z, +x
280280
};
281281
}
282282
public static class Cactus
283-
{
283+
{
284284
const float offset1 = 0.0625f;
285285
const float offset2 = 1f - offset1;
286286
public static readonly Vector3[] verts = new Vector3[] {
@@ -330,5 +330,69 @@ public static class Cactus
330330
new Vector2(1.0f, 1.0f),
331331
};
332332
}
333+
public static class Button
334+
{
335+
public const float Width = 0.375f;
336+
public const float Heigth = 0.25f;
337+
public const float Depth = 0.125f;
338+
public const float WidthH = Width / 2f;
339+
public const float HeigthH = Heigth / 2f;
340+
public const float DepthH = Depth / 2f;
341+
342+
public static readonly Vector3[] verts = new Vector3[8] {
343+
new Vector3(0.0f, 0.0f, 0.0f),
344+
new Vector3(Width, 0.0f, 0.0f),
345+
new Vector3(Width, Heigth, 0.0f),
346+
new Vector3(0.0f, Heigth, 0.0f),
347+
new Vector3(0.0f, 0.0f, Depth),
348+
new Vector3(Width, 0.0f, Depth),
349+
new Vector3(Width, Heigth, Depth),
350+
new Vector3(0.0f, Heigth, Depth)
351+
};
352+
353+
public static readonly Vector2[,] uvs = new Vector2[,] {
354+
{ // along z
355+
new Vector2(0.0f, 0.0f),
356+
new Vector2(0.0f, Heigth),
357+
new Vector2(Width, 0.0f),
358+
new Vector2(Width, Heigth)
359+
},
360+
{ // along y
361+
new Vector2(0.0f, 0.0f),
362+
new Vector2(0.0f, Depth),
363+
new Vector2(Width, 0.0f),
364+
new Vector2(Width, Depth)
365+
},
366+
{ // along x
367+
new Vector2(0.0f, 0.0f),
368+
new Vector2(0.0f, Heigth),
369+
new Vector2(Depth, 0.0f),
370+
new Vector2(Depth, Heigth)
371+
},
372+
};
373+
}
374+
public static class Rail
375+
{
376+
public const float Y = 0.5f;
377+
public const float DefaultHeight = 0.05f;
378+
public static readonly Vector3[] verts = new Vector3[]
379+
{
380+
new Vector3(0.0f, Y, 0.0f), // 0
381+
new Vector3(1.0f, Y, 0.0f), // 1
382+
new Vector3(0.0f, Y, 1.0f), // 2
383+
new Vector3(1.0f, Y, 1.0f), // 3
384+
};
385+
public static readonly Vector3[] vertsSlope = new Vector3[]
386+
{
387+
new Vector3(0.0f, 0.0f, 0.0f), // 0
388+
new Vector3(1.0f, 0.0f, 0.0f), // 1
389+
new Vector3(0.0f, 1.0f, 1.0f), // 2
390+
new Vector3(1.0f, 1.0f, 1.0f), // 3
391+
};
392+
public static readonly int[,] tris = new int[2, 4] {
393+
{0, 2, 1, 3}, // Top Face
394+
{1, 3, 0, 2}, // Bottom Face
395+
};
396+
}
333397
}
334398
}

Window.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ protected override void OnKeyDown(KeyboardKeyEventArgs e)
214214
keyboardState = e.Keyboard;
215215

216216
if (e.Key == Key.P) {
217-
Vector3i pos = (Vector3i)World.cursorPos;
217+
Vector3i pos = (Vector3i)(Camera.position);// - (Vector3.One / 2f));
218218
World.GetBlockIndex(pos, out int sbi, out int bi);
219-
uint chunkBlock = World.chunks[sbi].GetBlock(pos - World.chunks[sbi].pos * 16);
220-
string blockName = World.chunks[sbi].palette[chunkBlock].name;
219+
/*uint chunkBlock = World.chunks[sbi].GetBlock(pos - World.chunks[sbi].pos * 16);
220+
string blockName = World.chunks[sbi].palette[chunkBlock].name;*/
221221

222222
Console.WriteLine($"Palette Id: {World.GetBlock(sbi, bi)}, Texture Id: {World.GetBlockPalette(sbi, bi).textures[0]}," +
223-
$"Name: {World.GetBlockPalette(sbi, bi).name}");
224-
Console.WriteLine($"ID: {bi}, SUB: {sbi}, Chunk Pos: {World.chunks[sbi].pos * 16}, Cursor pos: {pos}, Name: {blockName}");
223+
$"Name: {World.GetBlockPalette(sbi, bi).name}, Data: {World.GetBlockPalette(sbi, bi).data}, Chunk Index: {sbi}, Block Index: {bi}");
224+
//Console.WriteLine($"ID: {bi}, SUB: {sbi}, Chunk Pos: {World.chunks[sbi].pos * 16}, Cursor pos: {pos}, Name: {blockName}");
225225
}
226226

227227
GUI.OnKeyDown(e.Key, e.Modifiers);

0 commit comments

Comments
 (0)