@starktma/minecraft-utils 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,77 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @starktma/minecraft-utils — utilities for Minecraft scripting
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a small collection of TypeScript utilities. The code is split into focused modules; this README gives a short summary and points to the source files for details.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick summary
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
7
|
+
- **database** — lightweight JSON storage helpers for Minecraft's dynamic properties. Implements a `DatabaseManager` (low-level serialization/partitioning) and `SimpleDatabase` (convenience base class for storing objects by id). See `src/database` for full details and examples.
|
|
8
|
+
- **math** — common math utilities used across the packages. See `src/math`.
|
|
9
|
+
- **minecraft** — helpers for Minecraft-specific operations and types. See `src/minecraft`.
|
|
10
|
+
- **player-event** — convenience helpers to handle player-related events and payloads. See `src/player-event`.
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## Short database note
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
2. Install the PropertyDatabase module `@starktma/minecraft-utils` using your preferred method (e.g., npm, yarn).
|
|
15
|
-
3. Place the PropertyDatabase module in your server's script directory or in the assets/javascript directory if you're using Anvil.
|
|
14
|
+
The database utilities are intentionally small: `DatabaseManager` handles serializing/partitioning JSON so it can be stored within Minecraft dynamic property limits, and `SimpleDatabase` provides a straightforward API for storing objects keyed by `id`. For full API and examples, open `src/database`.
|
|
16
15
|
|
|
17
|
-
##
|
|
16
|
+
## Installation & quick dev
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
- **To use the published package**: `npm install @starktma/minecraft-utils` (if published to npm or a registry).
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
## Where to look next
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- `
|
|
26
|
-
- `
|
|
27
|
-
- `
|
|
28
|
-
- `getJSONDatabase(databaseName: string)`: Retrieves a database.
|
|
29
|
-
|
|
30
|
-
### SimpleDatabase Class
|
|
31
|
-
|
|
32
|
-
A base class for managing databases of custom objects.
|
|
33
|
-
|
|
34
|
-
#### Methods:
|
|
35
|
-
|
|
36
|
-
- `addObject(object: SimpleObject)`: Adds a new object to the database.
|
|
37
|
-
- `updateObject(object: SimpleObject)`: Updates an existing object.
|
|
38
|
-
- `hasObject(id: string)`: Checks if an object exists.
|
|
39
|
-
- `getObject(id: string)`: Retrieves an object by ID.
|
|
40
|
-
- `removeObject(id: string)`: Removes an object.
|
|
41
|
-
- `getAllObjects()`: Retrieves all objects.
|
|
42
|
-
- `eraseAllObjects()`: Clears the database.
|
|
43
|
-
- `forEach(callback: Function)`: Iterates over objects.
|
|
44
|
-
|
|
45
|
-
### SimpleObject Interface
|
|
46
|
-
|
|
47
|
-
A basic interface for objects managed by `SimpleDatabase`. Must include an `id` property.
|
|
48
|
-
|
|
49
|
-
## NOTE
|
|
50
|
-
|
|
51
|
-
The `DatabaseManager` class is designed to handle JSON databases in Minecraft's world properties and cannot be used directly. Its main job is to convert your database to string formats that can be stored on dynamic properties and back.
|
|
52
|
-
|
|
53
|
-
The `DatabaseManager` class is responsible for deconstructing and reconstructing the database from JSON strings to work around the dynamic property size limits in Minecraft [`32767`].
|
|
54
|
-
|
|
55
|
-
The `SimpleDatabase` class uses the `DatabaseManager` to manage custom objects. It provides methods to add, update, retrieve, and remove objects, as well as to iterate over all objects in the database.
|
|
56
|
-
|
|
57
|
-
The `SimpleDatabase` is intended to be inherited by custom object classes. It requires an `id` property to uniquely identify each object and can be extended with additional properties as needed.
|
|
58
|
-
|
|
59
|
-
The `SimpleObject` interface defines the structure of objects that can be managed by `SimpleDatabase`. It includes an `id` property, which is essential for identifying objects within the database, and can be extended with additional properties to structure your own database objects.
|
|
60
|
-
|
|
61
|
-
## Examples
|
|
62
|
-
|
|
63
|
-
### Creating a Custom Database
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
class MyDatabase extends SimpleDatabase {
|
|
67
|
-
constructor() {
|
|
68
|
-
super("my_database");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
addObject(object: MyObject) {
|
|
72
|
-
super.addObject(object);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Additional custom methods...
|
|
76
|
-
}
|
|
77
|
-
```
|
|
22
|
+
- See the module source for exact types, exported functions, and examples:
|
|
23
|
+
- `src/database` — database manager, simple database base class, and interfaces
|
|
24
|
+
- `src/math` — math helpers
|
|
25
|
+
- `src/minecraft` — Minecraft helpers
|
|
26
|
+
- `src/player-event` — player event helpers
|