Skip to content

Commit

Permalink
Prismarine: Fix #1328.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphsps committed Apr 17, 2024
1 parent 1394138 commit 2b5bc2f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-cheetahs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@jsprismarine/prismarine": patch
---

Fix "Blocks in negative coordinates don't behave correctly." [#1328](https://github.com/JSPrismarine/JSPrismarine/issues/1328).
8 changes: 4 additions & 4 deletions packages/prismarine/src/world/chunk/BlockStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockMappings } from '../../block/BlockMappings';
import type { LegacyId } from '../../block/BlockMappings';
import { BlockMappings } from '../../block/BlockMappings';

import type BinaryStream from '@jsprismarine/jsbinaryutils';

Expand All @@ -18,9 +18,9 @@ export default class BlockStorage {
}

private static getIndex(bx: number, by: number, bz: number): number {
// bx &= 0x0f;
// by &= 0x0f;
// bz &= 0x0f;
bx = bx & 0x0f;
bz = bz & 0x0f;
by = by & 0x0f;
return ((bx << 8) + (bz << 4)) | by;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/prismarine/src/world/chunk/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class Chunk {
return this.getBlock(bx.getX(), bx.getY(), bx.getZ(), layer);
}

const subChunk = this.getSubChunk(by >> 4);
const subChunk = this.getSubChunk(Math.floor(by / 16));
if (subChunk === null) {
return BlockMappings.getLegacyId(BlockMappings.getRuntimeId('minecraft:air'));
}
Expand All @@ -109,7 +109,7 @@ export default class Chunk {
* @param layer - block storage layer (0 for blocks, 1 for liquids)
*/
public setBlock(bx: number, by: number, bz: number, block: Block, layer = 0): void {
let subChunk = this.getSubChunk(by >> 4);
let subChunk = this.getSubChunk(Math.floor(by / 16));
if (subChunk === null) {
if (block.getName() === 'minecraft:air') {
return;
Expand Down

0 comments on commit 2b5bc2f

Please sign in to comment.