Skip to content

fix: add full Minecraft 1.18+ support for negative Y coordinates#471

Open
keithworrell wants to merge 1 commit into
PrismarineJS:masterfrom
keithworrell:fix/minecraft-1.18-negative-y-support
Open

fix: add full Minecraft 1.18+ support for negative Y coordinates#471
keithworrell wants to merge 1 commit into
PrismarineJS:masterfrom
keithworrell:fix/minecraft-1.18-negative-y-support

Conversation

@keithworrell

Copy link
Copy Markdown

Fixes several critical bugs preventing proper rendering of Minecraft 1.18+ worlds with negative Y coordinates (Y=-64 to Y=320).

Issues Fixed

1. Chunk sections not rendering on initial load Files: viewer/lib/worldrenderer.js (addColumn, removeColumn) Problem: Y loop hardcoded to 0-256, ignoring negative Y sections Solution: Changed range to -64 to 320 (full 1.18+ world height)

2. Section index calculation errors

File: viewer/lib/worker.js
Problem: Math.floor(y / 16) produces negative array indices for Y < 0 Solution: Use Math.floor((y - chunk.minY) / 16) to account for minY offset

3. Unknown entity crashes

File: viewer/lib/entity/Entity.js
Problem: Throws error when encountering unknown entity types Solution: Log warning and create placeholder mesh instead

4. Null block handling

File: viewer/lib/models.js
Problem: Crashes when chunk not fully loaded
Solution: Skip null blocks gracefully

Testing

Tested on Minecraft 1.21.1 (protocol 767) with:

  • Flat creative world at Y=-60
  • Underground structures at Y < 0
  • Chunk loading/unloading
  • Browser refresh persistence

Before/After

Before: Chunks at negative Y don't render until blocks are modified After: All chunks render immediately on initial load

Fixes rendering for underground bases, caves, and flat worlds introduced in Minecraft 1.18 (Nov 2021).

Fixes several critical bugs preventing proper rendering of Minecraft 1.18+ worlds with negative Y coordinates (Y=-64 to Y=320).

## Issues Fixed

### 1. Chunk sections not rendering on initial load
**Files**: viewer/lib/worldrenderer.js (addColumn, removeColumn)
**Problem**: Y loop hardcoded to 0-256, ignoring negative Y sections
**Solution**: Changed range to -64 to 320 (full 1.18+ world height)

### 2. Section index calculation errors
**File**: viewer/lib/worker.js
**Problem**: Math.floor(y / 16) produces negative array indices for Y < 0
**Solution**: Use Math.floor((y - chunk.minY) / 16) to account for minY offset

### 3. Unknown entity crashes
**File**: viewer/lib/entity/Entity.js
**Problem**: Throws error when encountering unknown entity types
**Solution**: Log warning and create placeholder mesh instead

### 4. Null block handling
**File**: viewer/lib/models.js
**Problem**: Crashes when chunk not fully loaded
**Solution**: Skip null blocks gracefully

## Testing
Tested on Minecraft 1.21.1 (protocol 767) with:
- Flat creative world at Y=-60
- Underground structures at Y < 0
- Chunk loading/unloading
- Browser refresh persistence

## Before/After
**Before**: Chunks at negative Y don't render until blocks are modified
**After**: All chunks render immediately on initial load

Fixes rendering for underground bases, caves, and flat worlds introduced in Minecraft 1.18 (Nov 2021).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant