Skip to content

Commit

Permalink
chore(world): default block components now register
Browse files Browse the repository at this point in the history
  • Loading branch information
PMK744 committed Jul 22, 2024
1 parent fca6f35 commit d7f8707
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/world/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ class Block {
) ?? [])
new component(this, component.identifier);

// Register the components that are type specific.
for (const identifier of permutation.type.components) {
// Get the component from the registry
const component = BlockComponent.components.get(identifier);

// Check if the component exists.
if (component) new component(this, identifier);
}

// Register the components that are state specific.
for (const key of Object.keys(permutation.state)) {
// Get the component from the registry
Expand Down
19 changes: 11 additions & 8 deletions packages/world/src/components/block/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ import type { Block } from "../../block";
class BlockInventoryComponent extends BlockComponent {
public static readonly identifier = "minecraft:inventory";

public readonly container: BlockContainer;
public readonly containerType: ContainerType = ContainerType.Container;

public readonly containerType: ContainerType = ContainerType.Inventory;
public readonly containerId: ContainerId = ContainerId.Ui;

public readonly containerId: ContainerId = ContainerId.Inventory;
public readonly inventorySize: number = 27;

public readonly inventorySize: number = 36;
public container: BlockContainer;

public selectedSlot: number = 0;

public constructor(block: Block, container?: BlockContainer) {
public constructor(block: Block) {
super(block, BlockInventoryComponent.identifier);
this.container =
container ??
new BlockContainer(block, ContainerType.Container, ContainerId.Ui, 27);
this.container = new BlockContainer(
block,
this.containerType,
this.containerId,
this.inventorySize
);
}

public onInteract(player: Player): void {
Expand Down

0 comments on commit d7f8707

Please sign in to comment.