Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

NumBlocks: Minecraft 1.8.8's worlds

Mason Chen8cfe52dfad45
diff --git a/games/numblocks/Makefile b/games/numblocks/Makefile
index 5740eb0d..8f68fd71 100644
--- a/games/numblocks/Makefile
+++ b/games/numblocks/Makefile
@@ -9,9 +9,9 @@ NWLINK ?= npx --yes -- [email protected]
BUILD_DIR = output
STRIP ?= arm-none-eabi-strip --strip-unneeded
CLIENT_JAR ?= client.jar
-GEN ?= src/genstub.c
+GEN ?= src/gen.c
GAME = src/main.c src/world.c src/edits.c src/render.c src/player.c src/phys.c src/inv.c src/entity.c src/mob.c src/tick.c src/gui.c src/save.c src/data.c $(GEN)
-HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
+HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h Makefile
CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device)
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant -ffast-math
diff --git a/games/numblocks/src/genstub.c b/games/numblocks/src/genstub.c
deleted file mode 100644
index 6f521f01..00000000
--- a/games/numblocks/src/genstub.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* A stand-in generator (rolling hills, trees, ores) used until the port of
- * Minecraft 1.8.8's generator (gen.c) is in. Same interface as gen.c. */
-#include <math.h>
-#include <stdlib.h>
-#include "nb.h"
-
-static int64_t wseed;
-
-static uint32_t hash3(int x, int y, int z) {
- uint32_t h = (uint32_t)x * 374761393u + (uint32_t)y * 668265263u + (uint32_t)z * 2147483647u + (uint32_t)wseed;
- h = (h ^ (h >> 13)) * 1274126177u;
- return h ^ (h >> 16);
-}
-static float vnoise(float x, float z) {
- int ix = (int)floorf(x), iz = (int)floorf(z);
- float fx = x - ix, fz = z - iz;
- fx = fx * fx * (3 - 2 * fx);
- fz = fz * fz * (3 - 2 * fz);
- float a = (hash3(ix, 0, iz) & 1023) / 1023.0f, b = (hash3(ix + 1, 0, iz) & 1023) / 1023.0f;
- float c = (hash3(ix, 0, iz + 1) & 1023) / 1023.0f, d = (hash3(ix + 1, 0, iz + 1) & 1023) / 1023.0f;
- return a + (b - a) * fx + (c - a) * fz + (a - b - c + d) * fx * fz;
-}
-static int height(int x, int z) {
- float h = 64 + vnoise(x / 32.0f, z / 32.0f) * 16 + vnoise(x / 8.0f, z / 8.0f) * 4 - 6;
- return (int)h;
-}
-
-void gen_init(int64_t seed) { wseed = seed; }
-int gen_biome(int x, int z) { return vnoise(x / 96.0f + 50, z / 96.0f) > 0.6f ? 4 : 1; }
-int gen_top(int x, int z) {
- int h = height(x, z);
- return h < 62 ? 62 : h;
-}
-void gen_spawn(int *x, int *y, int *z) {
- *x = 8;
- *z = 8;
- *y = gen_top(8, 8) + 1;
-}
-
-static bool tree_at(int x, int z) { return (hash3(x, 7, z) % 61) == 0 && height(x, z) >= 63; }
-
-void gen_slab(int cx, int cz, int y0, int h, uint8_t *out) {
- memset(out, B_AIR, (size_t)h * 256);
- for (int z = 0; z < 16; z++)
- for (int x = 0; x < 16; x++) {
- int wx = cx * 16 + x, wz = cz * 16 + z, top = height(wx, wz);
- for (int y = y0; y < y0 + h; y++) {
- int b = B_AIR;
- if (y == 0) b = B_BEDROCK;
- else if (y < top - 3) {
- uint32_t r = hash3(wx, y, wz);
- b = (r % 97) == 0 ? B_COAL_ORE : (r % 151) == 0 ? B_IRON_ORE : (r % 33) == 0 ? B_GRAVEL : B_STONE;
- if (y < 16 && (r % 401) == 0) b = B_DIAMOND_ORE;
- } else if (y < top) b = top < 64 ? B_SAND : B_DIRT;
- else if (y == top) b = top < 63 ? B_SAND : B_GRASS;
- else if (y < 63) b = B_WATER;
- else if (y == top + 1 && top >= 63 && (hash3(wx, y, wz) % 7) == 0) b = (hash3(wx, 1, wz) % 9) ? B_TALL_GRASS : B_POPPY;
- out[(y - y0) * 256 + z * 16 + x] = (uint8_t)b;
- }
- }
- /* trees, from this chunk and its neighbours */
- for (int tz = cz * 16 - 2; tz < cz * 16 + 18; tz++)
- for (int tx = cx * 16 - 2; tx < cx * 16 + 18; tx++) {
- if (!tree_at(tx, tz)) continue;
- int base = height(tx, tz) + 1;
- for (int dy = 0; dy < 7; dy++)
- for (int dz = -2; dz <= 2; dz++)
- for (int dx = -2; dx <= 2; dx++) {
- int wx = tx + dx, wz = tz + dz, y = base + dy, lx = wx - cx * 16, lz = wz - cz * 16;
- if (lx < 0 || lx > 15 || lz < 0 || lz > 15 || y < y0 || y >= y0 + h) continue;
- int b = B_AIR;
- if (dx == 0 && dz == 0 && dy < 5) b = B_LOG_OAK;
- else if (dy >= 3 && dy <= 4 && !(abs(dx) == 2 && abs(dz) == 2)) b = B_LEAVES_OAK;
- else if (dy >= 5 && abs(dx) <= 1 && abs(dz) <= 1 && !(dy == 6 && abs(dx) + abs(dz) == 2)) b = B_LEAVES_OAK;
- if (b != B_AIR) out[(y - y0) * 256 + lz * 16 + lx] = (uint8_t)b;
- }
- }
-}
-float gen_temp_noise(int x, int z) { return 0; }
diff --git a/games/numblocks/src/render.c b/games/numblocks/src/render.c
index 92689d12..b97e388f 100644
--- a/games/numblocks/src/render.c
+++ b/games/numblocks/src/render.c
@@ -359,7 +359,7 @@ static uint16_t trace(float dx, float dy, float dz) {
return c;
}
} else if (m == M_CROSS) {
- Hit h;
+ Hit h = {0};
float t1 = fminf(fminf(tx, ty), tz) - t;
if (hit_cross(blk_tex[b][3], lx, ly, lz, dx, dy, dz, 0, t1, &h)) {
int r, g, bb;
diff --git a/games/numblocks/tests/unit.c b/games/numblocks/tests/unit.c
index 48284d72..51079821 100644
--- a/games/numblocks/tests/unit.c
+++ b/games/numblocks/tests/unit.c
@@ -154,7 +154,7 @@ int main(void) {
/* weather: the clock, the strength, the light, and where rain falls */
extern uint32_t game_time;
world_new(0, "ut4");
- world_follow(8, 70, 8);
+ world_follow(8, 110, 8); /* (high above the ground: only the test's blocks under the sky) */
for (int i = 0; i < VCX * VCZ; i++) vbiome[i] = 1; /* plains */
memset(&weather, 0, sizeof weather);
rain_str = thunder_str = 0;
@@ -169,7 +169,7 @@ int main(void) {
CHECK(rain_str == 1 && sky_sub() == 3); /* rain alone: still day, no sleeping */
weather.thundering = 1, thunder_str = 1;
CHECK(sky_sub() >= 4); /* a storm: dark enough to sleep */
- int y = 70;
+ int y = 110;
for (int z = 0; z <= 4; z++)
for (int x = 0; x <= 4; x++) {
world_set(x, y - 1, z, B_STONE);