Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ devapp/permissions.json
devapp/resource_packs
devapp/behavior_packs

bds

# Swap the comments on the following lines if you don't wish to use zero-installs
# Documentation here: https://yarnpkg.com/features/zero-installs
# !.yarn/cache
Expand Down
4 changes: 3 additions & 1 deletion bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ if (isMainThread) {
serenity.registerProvider(LevelDBProvider, { path: "./worlds" });

// Start the server
serenity.start();
serenity.start().then(() => { }).catch((error) => {
serenity.logger.error("Failed to start SerenityJS server:", error);
});
}
1 change: 1 addition & 0 deletions clones/PocketMine-MP
Submodule PocketMine-MP added at d77520
1 change: 1 addition & 0 deletions clones/PowerNukkitX
Submodule PowerNukkitX added at 712d7c
4 changes: 3 additions & 1 deletion devapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ new Pipeline(serenity, { path: "./plugins" });
serenity.registerProvider(LevelDBProvider, { path: "./worlds" });

// Start the server
serenity.start();
serenity.start().catch((reason) => {
serenity.logger.error("Failed to start SerenityJS server:", reason);
});
47 changes: 38 additions & 9 deletions packages/core/src/block/container.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {
BlockPosition,
type IPosition,
ContainerId,
ContainerOpenPacket,
ContainerType
} from "@serenityjs/protocol";

import { Container } from "../container";
import { ItemStack } from "../item";
import { Player } from "../entity";
import { PlayerOpenedContainerSignal } from "../events";

import { Block } from "./block";
import { ItemStack } from "../item/stack";
import { Player } from "../entity/player";
import { PlayerOpenedContainerSignal } from "../events/player-opened-container";

Check warning on line 12 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import type { Block } from "./block";

class BlockContainer extends Container {
/**
Expand Down Expand Up @@ -37,6 +38,19 @@
// Call the original update method
super.update();

// Call the onContainerUpdate method for the block traits
this.notifyTraits();
}

public updateSlot(slot: number): void {
// Call the original updateSlot method
super.updateSlot(slot);

// Call the onContainerUpdate method for the block traits
this.notifyTraits();
}

private notifyTraits(): void {
// Call the onContainerUpdate method for the block traits
for (const trait of this.block.getAllTraits()) {
try {
Expand All @@ -56,7 +70,7 @@
}
}

public show(player: Player): number {
public show(player: Player, position: IPosition = this.block.position): number {

Check warning on line 73 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `player:·Player,·position:·IPosition·=·this.block.position` with `⏎····player:·Player,⏎····position:·IPosition·=·this.block.position⏎··`
// Create a new PlayerOpenedContainerSignal
const signal = new PlayerOpenedContainerSignal(player, this);

Expand All @@ -72,16 +86,31 @@
// Assign the properties
packet.identifier = identifier;
packet.type = this.type;
packet.position = this.block.position;
packet.uniqueId =
this.type === ContainerType.Container ? -1n : player.uniqueId;
packet.position = position instanceof BlockPosition

Check warning on line 89 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·····`
? position

Check warning on line 90 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
: new BlockPosition(position.x, position.y, position.z);

Check warning on line 91 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
// Vanilla/BDS uses -1 for block container windows, including hoppers.
packet.uniqueId = -1n;

// Send the packet to the player
player.send(packet);

// Update the container
this.update();

// Some block container UIs (such as furnaces) ignore the initial full
// content snapshot until the window exists client-side. Re-send the slots
// on the next tick once the container is definitely open. dunno why its done like this here but i aint rewriting all that
if (this.type !== ContainerType.Container) {
this.block.dimension.schedule(1).on(() => {
if (!this.getAllOccupants().some(([occupant]) => occupant === player)) return;

Check warning on line 106 in packages/core/src/block/container.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·········`

for (let slot = 0; slot < this.getSize(); slot++) {
this.updateSlot(slot);
}
});
}

// Return the container identifier
return identifier;
}
Expand Down
Loading
Loading