Skip to content

Commit c64060b

Browse files
committed
1.1.0 update
1 parent 159eb91 commit c64060b

85 files changed

Lines changed: 3600 additions & 785 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
**/*/test.ts
33
**/*/test.js
4-
bun.lockb
4+
bun.lockb
5+
*.txt
6+
bench.ts

documentations/binary_operator.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
## Binary Operator
2+
3+
BlockCore provides a `Binary` class that implements basic arithmetic operations using bitwise operations. These implementations are useful for understanding binary arithmetic or in scenarios where traditional arithmetic operations aren't preferred.
4+
5+
### Available Operations
6+
7+
#### Addition (ADDER)
8+
9+
Adds two numbers using binary operations.
10+
11+
```typescript
12+
import { Binary } from "./block-core";
13+
14+
const sum = Binary.ADDER(5, 3); // Returns 8
15+
```
16+
17+
How it works:
18+
19+
1. Uses bitwise AND (&) to find carry bits
20+
2. Uses bitwise XOR (^) for addition without carry
21+
3. Shifts carry left by 1 position
22+
4. Repeats until no carry remains
23+
24+
#### Subtraction (SUBTRACTER)
25+
26+
Subtracts one number from another using binary operations.
27+
28+
```typescript
29+
import { Binary } from "./block-core";
30+
31+
const difference = Binary.SUBTRACTER(10, 3); // Returns 7
32+
```
33+
34+
How it works:
35+
36+
1. Uses bitwise NOT (~) and AND (&) to find borrow bits
37+
2. Uses bitwise XOR (^) for subtraction without borrow
38+
3. Shifts borrow left by 1 position
39+
4. Repeats until no borrow remains
40+
41+
#### Division (DIVIDER)
42+
43+
Performs integer division using binary operations.
44+
45+
```typescript
46+
import { Binary } from "./block-core";
47+
48+
const quotient = Binary.DIVIDER(15, 3); // Returns 5
49+
```
50+
51+
How it works:
52+
53+
1. Implements long division algorithm in binary
54+
2. Uses 31-bit precision
55+
3. Processes bits from most significant to least significant
56+
4. Builds quotient bit by bit
57+
58+
#### Multiplication (MULTIPLER)
59+
60+
Multiplies two numbers using binary operations.
61+
62+
```typescript
63+
import { Binary } from "./block-core";
64+
65+
const product = Binary.MULTIPLER(4, 3); // Returns 12
66+
```
67+
68+
How it works:
69+
70+
1. Optimizes by swapping operands if needed
71+
2. Uses Russian Peasant multiplication algorithm
72+
3. Repeatedly shifts and adds based on bits
73+
4. Accumulates partial products
74+
75+
### Usage Examples
76+
77+
```typescript
78+
import { Binary } from "./block-core";
79+
80+
// Addition
81+
const sum = Binary.ADDER(25, 17);
82+
console.log(sum); // 42
83+
84+
// Subtraction
85+
const difference = Binary.SUBTRACTER(100, 45);
86+
console.log(difference); // 55
87+
88+
// Division
89+
const quotient = Binary.DIVIDER(156, 12);
90+
console.log(quotient); // 13
91+
92+
// Multiplication
93+
const product = Binary.MULTIPLER(23, 7);
94+
console.log(product); // 161
95+
```
96+
97+
### Notes
98+
99+
- All operations work with integer values
100+
- Division returns only the quotient (no remainder)
101+
- Operations may have different performance characteristics compared to native arithmetic
102+
- Best used for educational purposes or specific binary arithmetic needs
103+
- All methods are static and can be called directly from the Binary class
104+
105+
### Implementation Details
106+
107+
Each operation is implemented using only bitwise operators:
108+
109+
- `&` (AND)
110+
- `|` (OR)
111+
- `^` (XOR)
112+
- `~` (NOT)
113+
- `<<` (Left shift)
114+
- `>>` (Right shift)
115+
116+
This makes them interesting examples of how arithmetic can be performed at the binary level without using traditional arithmetic operators.

documentations/chunk_manager.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
## Managing Chunk Zones
2+
3+
BlockCore provides two classes for managing chunk zones: `Chunker` for 3D chunks and `ChunkerXZ` for 2D chunks in the XZ plane. These classes help you define and manage areas in your world.
4+
5+
### 3D Chunks (Chunker)
6+
7+
The `Chunker` class manages three-dimensional zones defined by start and end positions.
8+
9+
#### Basic Usage
10+
11+
```typescript
12+
import { Chunker } from "./block-core";
13+
14+
// Create a new 3D chunk
15+
const chunk = new Chunker(
16+
{ x: 0, y: 0, z: 0 }, // Start position
17+
{ x: 16, y: 256, z: 16 }, // End position
18+
);
19+
20+
// Check if a position is inside the chunk
21+
const isInside = chunk.isInsideOfChunk({ x: 8, y: 64, z: 8 }); // true
22+
23+
// Check if chunks overlap
24+
const otherChunk = new Chunker(
25+
{ x: 10, y: 0, z: 10 },
26+
{ x: 26, y: 256, z: 26 },
27+
);
28+
const isOverlapping = chunk.isOverlapping(otherChunk); // true
29+
```
30+
31+
#### Methods
32+
33+
- `isInsideOfChunk(pos: ChunkerPos): boolean`
34+
35+
- Checks if a position is within the chunk boundaries
36+
- Position must have x, y, and z coordinates
37+
38+
- `isOverlapping(other: Chunker): boolean`
39+
40+
- Checks if this chunk overlaps with another chunk
41+
- Returns true if any part of the chunks intersect
42+
43+
- `getData: { s_pos: ChunkerPos, e_pos: ChunkerPos }`
44+
- Gets the chunk's start and end positions
45+
46+
### 2D Chunks (ChunkerXZ)
47+
48+
The `ChunkerXZ` class manages two-dimensional zones in the XZ plane, useful for defining areas regardless of height.
49+
50+
#### Basic Usage
51+
52+
```typescript
53+
import { ChunkerXZ } from "./block-core";
54+
55+
// Create a new 2D chunk
56+
const chunk = new ChunkerXZ(
57+
{ x: 0, z: 0 }, // Start position
58+
{ x: 16, z: 16 }, // End position
59+
);
60+
61+
// Check if a position is inside the chunk
62+
const isInside = chunk.isInsideOfChunk({ x: 8, z: 8 }); // true
63+
64+
// Check if chunks overlap
65+
const otherChunk = new ChunkerXZ({ x: 10, z: 10 }, { x: 26, z: 26 });
66+
const isOverlapping = chunk.isOverlapping(otherChunk); // true
67+
```
68+
69+
#### Methods
70+
71+
- `isInsideOfChunk(pos: ChunkerPosXZ): boolean`
72+
73+
- Checks if a position is within the chunk boundaries
74+
- Position only needs x and z coordinates
75+
76+
- `isOverlapping(other: ChunkerXZ): boolean`
77+
78+
- Checks if this chunk overlaps with another chunk
79+
- Returns true if any part of the chunks intersect
80+
81+
- `getData: { s_pos: ChunkerPosXZ, e_pos: ChunkerPosXZ }`
82+
- Gets the chunk's start and end positions
83+
84+
### Type Definitions
85+
86+
```typescript
87+
interface ChunkerPos {
88+
x: number;
89+
y: number;
90+
z: number;
91+
}
92+
93+
interface ChunkerPosXZ {
94+
x: number;
95+
z: number;
96+
}
97+
```
98+
99+
### Common Use Cases
100+
101+
1. Defining Protected Areas
102+
103+
```typescript
104+
const spawnProtection = new ChunkerXZ({ x: -100, z: -100 }, { x: 100, z: 100 });
105+
106+
// Check if player is in protected area
107+
const isProtected = spawnProtection.isInsideOfChunk(playerPosition);
108+
```
109+
110+
2. Creating Building Zones
111+
112+
```typescript
113+
const buildingZone = new Chunker(
114+
{ x: 0, y: 0, z: 0 },
115+
{ x: 100, y: 256, z: 100 },
116+
);
117+
118+
// Check if block placement is allowed
119+
const canBuild = buildingZone.isInsideOfChunk(blockPosition);
120+
```
121+
122+
3. Detecting Zone Conflicts
123+
124+
```typescript
125+
const zone1 = new ChunkerXZ({ x: 0, z: 0 }, { x: 50, z: 50 });
126+
const zone2 = new ChunkerXZ({ x: 40, z: 40 }, { x: 90, z: 90 });
127+
128+
// Check if zones overlap
129+
const hasConflict = zone1.isOverlapping(zone2);
130+
```
131+
132+
### Notes
133+
134+
- Coordinates can be provided in any order - the system automatically determines min/max values
135+
- Both classes handle coordinate calculations efficiently
136+
- Useful for defining protection zones, build areas, or any other spatial boundaries
137+
- ChunkerXZ is more performant when Y-axis checks aren't needed

documentations/custom_commands.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## Creating Custom Commands
2+
3+
BlockCore provides a powerful command builder and register system that allows you to create custom commands with ease. This guide will walk you through the process of creating a custom command using BlockCore.
4+
5+
### CommandBuilder
6+
7+
The main class for building and managing custom commands.
8+
9+
#### Methods
10+
11+
- `Build(command: CommandBuilder): void`
12+
13+
Builds and registers a new command.
14+
15+
| Parameter | Type | Description |
16+
| ------------------- | ----------------- | ---------------------------------------------- |
17+
| `options.register` | `CommandRegister` | The command registration configuration |
18+
| `options.onExecute` | `Function` | Callback function executed when command is run |
19+
20+
### CommandRegister
21+
22+
Class for configuring command properties.
23+
24+
#### Methods
25+
26+
- `setName(name: string): CommandRegister`
27+
28+
Sets the command name.
29+
30+
- `setDescription(desc: string): CommandRegister`
31+
32+
Sets the command description. Defaults to "No Description."
33+
34+
- `setCategory(cname: string): CommandRegister`
35+
36+
Sets the command category. Defaults to "Global"
37+
38+
- `setPerms(perms: string[]): CommandRegister`
39+
40+
Sets required permissions tags.
41+
42+
- `setAliases(alias: string[]): CommandRegister`
43+
44+
Sets alternative command names.
45+
46+
- `setUsage(usage: string[]): CommandRegister`
47+
48+
Sets command usage instructions.
49+
50+
- `setExample(eg: string[]): CommandRegister`
51+
52+
Sets example command usages.
53+
54+
- `setInputs(inputs: InputTypes): CommandRegister`
55+
56+
Sets expected input types for command arguments.
57+
58+
```typescript
59+
type InputTypes = {
60+
[argumentIndex: number]: ("string" | "boolean" | "number" | "playername")[];
61+
};
62+
```
63+
64+
Input type `playername` is a special type that only accepts player names starting with "@".
65+
66+
#### `onExecute` Callback Properties
67+
68+
The callback function receives an object with these properties:
69+
70+
| Property | Type | Description |
71+
| ------------- | ------------- | ------------------------------------ |
72+
| `sender` | `PlayerActor` | The player who executed the command |
73+
| `getInput` | `Function` | Gets parsed input at specified index |
74+
| `core_config` | `Object` | Access to core configuration |
75+
| `logger` | `Logger` | Logger instance for debugging |
76+
77+
Example usage:
78+
79+
```typescript
80+
CommandBuilder.Build({
81+
register: new CommandRegister()
82+
.setName("example")
83+
.setInputs({ 0: ["string"] }),
84+
onExecute: ({ sender, getInput }) => {
85+
const first_input = getInput(0); // Get first argument
86+
const player = sender.unwrap();
87+
player.sendMessage(`Got input: ${first_input}`);
88+
},
89+
});
90+
```
91+
92+
Note: The `CommandBuilder` class provides a convenient way to create and register custom commands, while the `CommandRegister` class allows you to configure the command properties.

0 commit comments

Comments
 (0)