Skip to content

Commit

Permalink
feat(world): scale component now affects collision box
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe-Devr committed Sep 17, 2024
1 parent e732ed1 commit fb9f493
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/world/src/components/entity/data/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ class EntityScaleComponent extends EntityDataComponent {
// Set the entity to have a custom scale
this.setCurrentValue(this.defaultValue, false);
}

public setCurrentValue(value: number, sync?: boolean): void {
// Get the entity collision height and width
const entityHeight = this.entity.getComponent(
"minecraft:boundingbox_height"
);
const entityWidth = this.entity.getComponent("minecraft:boundingbox_width");

// Recalculate the collision size
if (entityHeight)
entityHeight.setCurrentValue(
(entityHeight.getCurrentValue() as number) * value
);

if (entityWidth)
entityWidth.setCurrentValue(
(entityWidth.getCurrentValue() as number) * value
);

// Continue with the base method
super.setCurrentValue(value, sync);
}
}

export { EntityScaleComponent };

0 comments on commit fb9f493

Please sign in to comment.