Skip to content

Commit

Permalink
fix(world): Inverted block collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe-Devr committed Sep 22, 2024
1 parent 68170ef commit 21babbf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/world/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ class Block {
* @returns Wether or not the block has any existing collision
*/
public hasCollision(): boolean {
if (!this.isAir()) return false;
if (this.isAir()) return false;
if (!this.hasComponent("minecraft:collision_box"))
new BlockCollisionComponent(this);
return this.getComponent("minecraft:collision_box").boxes.length > 0;
Expand Down
6 changes: 2 additions & 4 deletions packages/world/src/components/block/collision-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BlockCollisionComponent extends BlockComponent {

// Initialize with a default solid collision box if the block is not air
this.boxes = [];
if (!block.isSolid()) this.addCollision(BlockCollisionComponent.Solid);
if (block.isSolid()) this.addCollision(BlockCollisionComponent.Solid);
}

/**
Expand All @@ -46,9 +46,7 @@ class BlockCollisionComponent extends BlockComponent {
// Iterate through each collision box and check for intersections.
for (const box of this.boxes) {
// Move the box to the block's position and check for intersections.
const movedBox = box.move(
BlockPosition.toVector3f(this.block.position)
);
const movedBox = box.move(BlockPosition.toVector3f(this.block.position));
const result = AABB.Intercept(movedBox, start, end);

// Continue if no intersection is found.
Expand Down

0 comments on commit 21babbf

Please sign in to comment.