-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SerenityJS:develop' into develop
- Loading branch information
Showing
10 changed files
with
98 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./cardinal-direction"; | ||
export * from "./weirdo-direction"; | ||
export * from "./upside-down-bit"; |
53 changes: 53 additions & 0 deletions
53
packages/world/src/components/block/state/upside-down-bit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { BlockComponent } from "../block-component"; | ||
|
||
import type { Vector3f } from "@serenityjs/protocol"; | ||
import type { Player } from "../../../player"; | ||
import type { Block } from "../../../block"; | ||
|
||
class BlockUpsideDownBitComponent extends BlockComponent { | ||
public static readonly identifier = "minecraft:upside_down_bit"; | ||
|
||
public constructor(block: Block) { | ||
super(block, BlockUpsideDownBitComponent.identifier); | ||
} | ||
|
||
public onPlace(_: Player, clickPosition: Vector3f): void { | ||
// Check if the click position is on the top face of the block | ||
if (clickPosition.y === 1) return this.setUpsideDown(false); | ||
|
||
// Check if the click position is on the bottom face of | ||
if (clickPosition.y === 0) return this.setUpsideDown(true); | ||
|
||
// Check if the block needs to be upside down | ||
const upsideDown = clickPosition.y > 0.5; | ||
|
||
// Set the direction of the block | ||
return this.setUpsideDown(upsideDown); | ||
} | ||
|
||
/** | ||
* Sets the direction of the block. | ||
* @param direction The direction to set. | ||
*/ | ||
public setUpsideDown(upsideDown: boolean): void { | ||
// Get the block type | ||
const type = this.block.getType(); | ||
|
||
// Get the state of the block | ||
const state = this.block.permutation.state; | ||
|
||
// Create the state of the block | ||
const newState = { | ||
...state, | ||
upside_down_bit: upsideDown | ||
}; | ||
|
||
// Set the direction of the block | ||
const permutation = type.getPermutation(newState); | ||
|
||
// Set the permutation of the block | ||
if (permutation) this.block.setPermutation(permutation); | ||
} | ||
} | ||
|
||
export { BlockUpsideDownBitComponent }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./state"; | ||
export * from "./update"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Vector3f } from "@serenityjs/protocol"; | ||
import type { Player } from "../../player"; | ||
|
||
interface BlockUpdateOptions { | ||
readonly player?: Player; | ||
readonly clickPosition?: Vector3f; | ||
} | ||
|
||
export { BlockUpdateOptions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters