Skip to content

Commit 0c0392b

Browse files
authored
Block entity type data & minor cleanup (#49)
1 parent ebf41eb commit 0c0392b

File tree

5 files changed

+45
-40
lines changed

5 files changed

+45
-40
lines changed

DataGenerator/src/main/java/net/minestom/datagen/DataGenType.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
package net.minestom.datagen;
22

33
import net.minecraft.core.registries.BuiltInRegistries;
4-
import net.minecraft.core.registries.Registries;
54
import net.minestom.generators.*;
65
import net.minestom.generators.loot_tables.BlockLootTableGenerator;
76
import net.minestom.generators.loot_tables.ChestLootTableGenerator;
87
import net.minestom.generators.loot_tables.EntityLootTableGenerator;
98
import net.minestom.generators.loot_tables.GameplayLootTableGenerator;
10-
import net.minestom.generators.tags.*;
11-
12-
import java.util.List;
139

1410
public enum DataGenType {
1511
CONSTANTS("constants", new MinecraftConstantGenerator()),
1612
// Tags are specified as a special case in datagen
1713

1814
// Codegen only
1915

20-
COMMAND_ARGUMENTS("command_arguments", new GenericRegistryGenerator<>(BuiltInRegistries.COMMAND_ARGUMENT_TYPE)),
21-
CONSUME_EFFECT("consume_effects", new GenericRegistryGenerator<>(BuiltInRegistries.CONSUME_EFFECT_TYPE)),
16+
COMMAND_ARGUMENTS("command_arguments", new GenericRegistryArrayGenerator<>(BuiltInRegistries.COMMAND_ARGUMENT_TYPE)),
17+
CONSUME_EFFECT("consume_effects", new GenericRegistryArrayGenerator<>(BuiltInRegistries.CONSUME_EFFECT_TYPE)),
2218
CUSTOM_STATISTICS("custom_statistics", new CustomStatisticGenerator()),
2319
DYE_COLORS("dye_colors", new DyeColorGenerator()),
2420
MAP_COLORS("map_colors", new MapColorGenerator()),
2521
PARTICLES("particle", new ParticleGenerator()),
2622
WORLD_EVENTS("world_events", new WorldEventGenerator()),
27-
RECIPE_BOOK_CATEGORY("recipe_book_categories", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_BOOK_CATEGORY)),
28-
RECIPE_DISPLAY_TYPE("recipe_display_types", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_DISPLAY)),
29-
RECIPE_TYPE("recipe_types", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_TYPE)),
30-
SLOT_DISPLAY_TYPE("slot_display_types", new GenericRegistryGenerator<>(BuiltInRegistries.SLOT_DISPLAY)),
23+
RECIPE_BOOK_CATEGORY("recipe_book_categories", new GenericRegistryArrayGenerator<>(BuiltInRegistries.RECIPE_BOOK_CATEGORY)),
24+
RECIPE_DISPLAY_TYPE("recipe_display_types", new GenericRegistryArrayGenerator<>(BuiltInRegistries.RECIPE_DISPLAY)),
25+
RECIPE_TYPE("recipe_types", new GenericRegistryArrayGenerator<>(BuiltInRegistries.RECIPE_TYPE)),
26+
SLOT_DISPLAY_TYPE("slot_display_types", new GenericRegistryArrayGenerator<>(BuiltInRegistries.SLOT_DISPLAY)),
3127
SOUND_SOURCES("sound_sources", new SoundSourceGenerator()),
32-
VILLAGER_TYPES("villager_types", new GenericRegistryGenerator<>(BuiltInRegistries.VILLAGER_TYPE)),
28+
VILLAGER_TYPES("villager_types", new GenericRegistryArrayGenerator<>(BuiltInRegistries.VILLAGER_TYPE)),
29+
BLOCK_ENTITY_TYPES("block_entity_types", new GenericRegistryObjectGenerator<>(BuiltInRegistries.BLOCK_ENTITY_TYPE)),
3330

3431
// Static registries
3532

DataGenerator/src/main/java/net/minestom/generators/CommandArgumentGenerator.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

DataGenerator/src/main/java/net/minestom/generators/GenericRegistryGenerator.java renamed to DataGenerator/src/main/java/net/minestom/generators/GenericRegistryArrayGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import net.minestom.datagen.DataGenerator;
77
import org.jetbrains.annotations.NotNull;
88

9-
public class GenericRegistryGenerator<T> extends DataGenerator {
9+
public class GenericRegistryArrayGenerator<T> extends DataGenerator {
1010
private final Registry<T> registry;
1111

12-
public GenericRegistryGenerator(@NotNull Registry<T> registry) {
12+
public GenericRegistryArrayGenerator(@NotNull Registry<T> registry) {
1313
this.registry = registry;
1414
}
1515

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package net.minestom.generators;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
5+
import net.minecraft.core.Registry;
6+
import net.minestom.datagen.DataGenerator;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class GenericRegistryObjectGenerator<T> extends DataGenerator {
10+
private final Registry<T> registry;
11+
12+
public GenericRegistryObjectGenerator(@NotNull Registry<T> registry) {
13+
this.registry = registry;
14+
}
15+
16+
@Override
17+
public JsonObject generate() {
18+
JsonObject output = new JsonObject();
19+
20+
for (T entry : registry) {
21+
JsonObject result = new JsonObject();
22+
23+
result.addProperty("id", registry.getId(entry));
24+
appendEntry(result, entry);
25+
26+
//noinspection DataFlowIssue We got `entry` from the registry, it is not null.
27+
output.add(registry.getKey(entry).toString(), result);
28+
}
29+
30+
return output;
31+
}
32+
33+
protected void appendEntry(JsonObject object, T entry) {
34+
}
35+
}

DataGenerator/src/main/java/net/minestom/generators/MaterialGenerator.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ public JsonObject generate() {
4646
itemJson.addProperty("correspondingBlock", blockRegistry.getKey(block).toString());
4747
}
4848

49-
// Spawn egg properties
50-
if (item instanceof SpawnEggItem spawnEggItem) {
51-
JsonObject spawnEggProperties = new JsonObject();
52-
spawnEggProperties.addProperty("entityType", entityTypeRegistry.getKey(spawnEggItem.getType(ItemStack.EMPTY)).toString());
53-
itemJson.add("spawnEggProperties", spawnEggProperties);
54-
}
55-
5649
items.add(location.toString(), itemJson);
5750
}
5851
return items;

0 commit comments

Comments
 (0)