|
1 | 1 | # trove
|
2 | 2 |
|
3 |
| -[](LICENSE) |
4 |
| -[](https://github.com/RichardLitt/standard-readme) |
5 |
| -[](https://javadoc.jitpack.io/com/github/GoldenStack/trove/master-SNAPSHOT/javadoc/) |
6 |
| - |
7 |
| -Trove is a versatile loot table library. Although a lot of the base concepts here are similar to Minecraft's loot table |
8 |
| -system, Trove is much more flexible, permitting the usage of multiple different loot types (e.g. items and experience). |
9 |
| -Plus, it has a convenient API, emphasizes immutable data structures, and supports full serialization and deserialization |
10 |
| -of all formats supported by Configurate, including JSON and YAML. |
11 |
| - |
12 |
| -The two modules are `core` and `minestom`. The `core` module contains the basic functioning pieces of the library, while |
13 |
| -`minestom` contains a nearly full implementation for Minecraft's loot tables for Minestom. |
14 |
| - |
15 |
| ---- |
16 |
| - |
17 |
| -## Table of Contents |
18 |
| -- [Install](#install) |
19 |
| -- [Usage](#usage) |
20 |
| -- [Contributing](#contributing) |
21 |
| -- [License](#license) |
| 3 | +Trove is a loot table library for [Minestom](https://github.com/Minestom/Minestom/). It implements |
| 4 | +[nearly every](#completeness) feature from vanilla Minecraft. |
22 | 5 |
|
23 | 6 | ---
|
24 | 7 |
|
25 | 8 | ## Install
|
26 | 9 |
|
27 |
| -To install, simply add the library via [JitPack](https://jitpack.io/#GoldenStack/trove/): |
| 10 | +To install, simply add the library via Maven Central: |
28 | 11 |
|
29 |
| -Details for how to add this library with other build tools (such as Maven) can be found on the page linked above. |
30 | 12 | ``` kts
|
31 | 13 | repositories {
|
32 |
| - ... |
33 |
| - maven(url = "https://jitpack.io") |
| 14 | + mavenCentral() |
34 | 15 | }
|
35 | 16 |
|
36 | 17 | dependencies {
|
37 |
| - ... |
38 |
| - // Minestom and Configurate versions |
39 |
| - // (you can replace Minestom with Minestom-ce if you want) |
40 |
| - implementation("com.github.minestom.minestom:Minestom:VERSION") |
41 |
| - implementation("org.spongepowered:configurate-gson:VERSION") |
| 18 | + implementation 'net.minestom:minestom-snapshots:<version>' |
42 | 19 |
|
43 |
| - implementation("com.github.GoldenStack.trove:MODULE:VERSION") |
| 20 | + implementation 'net.goldenstack.trove:<version>' |
44 | 21 | }
|
45 | 22 | ```
|
46 |
| -Trove relies on Minestom and Configurate, so make sure to add them. |
47 |
| - |
48 |
| -Just replace `MODULE` with the desired module of Trove, and replace `VERSION` with the desired version or commit hash. |
49 |
| - |
50 |
| -Trove currently uses |
| 23 | +Make sure to include Minestom, or else Trove won't work. |
51 | 24 |
|
52 | 25 | ---
|
53 | 26 |
|
54 | 27 | ## Usage
|
55 | 28 |
|
56 | 29 | ### Setup
|
57 | 30 |
|
58 |
| -This setup currently only explains how to set up the Minestom module. |
59 |
| - |
60 |
| -You can use the TroveMinestom class for a very easy setup. Just provide a folder path, and it will recursively parse |
61 |
| -every JSON file inside it. |
62 |
| - |
63 |
| -``` java |
64 |
| -Path lootTableFolder = ...; // Replace with the path to the folder of loot tables |
65 |
| - |
66 |
| -var tableRegistry = TroveMinestom.readTables(lootTableFolder, |
67 |
| - () -> GsonConfigurationLoader.builder().defaultOptions(options -> options.serializers(builder -> builder.registerAll(TroveMinestom.DEFAULT_COLLECTION)))); |
68 |
| -``` |
69 |
| -Each table will be stored via a NamespaceID in the tables object. For example, if the parsed loot table has the path |
70 |
| -"blocks/barrel.json" relative to the loot table folder, its ID will be `minecraft:blocks/barrel`. |
| 31 | +Trove is designed to be extremely simple to use. |
71 | 32 |
|
| 33 | +To obtain a `Map<NamespaceID, LootTable>`, simply call `Trove.readTables(Path.of("path_to_loot_tables"))`. Trove will |
| 34 | +automatically parse out the loot table hierarchy and include it in the table IDs. |
72 | 35 |
|
73 | 36 | ### Generation
|
74 |
| -Actual loot generation is fairly simple - you just need to call `LootTable#generate(LootContext, Consumer<Object>)`. |
75 |
| -The consumer can be a `LootProcessor` if that makes it easier. |
76 |
| - |
77 |
| -Importantly, if you want some of the vanilla features that aren't implemented here, you should implement the |
78 |
| -`VanillaInterface` interface and pass it in as a key to your context. A partial implementation of it that doesn't throw |
79 |
| -any exceptions is `FallbackVanillaInterface`. You may also have to implement some type serializers. |
80 |
| - |
81 |
| -Here's an example that uses the `tableRegistry` variable from the last code snippet: |
82 |
| -``` java |
83 |
| -LootTable table = tableRegistry.getTable(NamespaceID.from("minecraft:blocks/stone")); |
| 37 | +Loot generation is very simple as well. Calling `LootTable#generate(LootContext)` returns a list of items. |
84 | 38 |
|
85 |
| -// You can use the LootContext class to provide important information during generation. |
86 |
| -LootContext context = LootContext.builder() |
87 |
| - .random(...) // Random instance here |
88 |
| - .with(..., ...) // Loot context keys and values added with Builder#with |
89 |
| - .build(); |
90 |
| - |
91 |
| -// Generate the loot |
92 |
| -table.generate(context, loot -> ...); // Do something with the loot |
93 |
| -``` |
| 39 | +If you're implementing block drops, just call `LootTable#blockDrop(LootContext, Instance, Point)`. If you're |
| 40 | +implementing entity drops, call `LootTable#drop(LootContext, Instance, Point)`. |
94 | 41 |
|
95 |
| -You can also use a `LootProcessor` to make this processing easier. For example: |
96 |
| -``` java |
97 |
| -var processor = LootProcessor.processClass(ItemStack.class, item -> { |
98 |
| - // Perform some arbitrary action with the item |
99 |
| -}); |
100 |
| -``` |
| 42 | +--- |
101 | 43 |
|
102 |
| -You can also handle multiple classes at once, or even use a custom predicate: |
103 |
| -``` java |
104 |
| -var processor = LootProcessor.builder() |
105 |
| - .processClass(ItemStack.class, item -> { |
106 |
| - // Perform some calculation |
107 |
| - }).processClass(String.class, string -> { |
108 |
| - // Perform another calculation |
109 |
| - }).process(object -> true, object -> { |
110 |
| - // Perform some calculation with the object |
111 |
| - }).build(); |
112 |
| -``` |
| 44 | +## Completeness |
113 | 45 |
|
114 |
| -Then, you can just provide the processor to the generator: |
115 |
| -``` java |
116 |
| -table.generate(context, processor); |
117 |
| -``` |
| 46 | +TODO |
118 | 47 |
|
119 | 48 | ---
|
120 | 49 |
|
|
0 commit comments