Skip to content

Commit 536187f

Browse files
authored
1.21.2 (#31)
* feat: 1.21.2 initial changes. armor represented as components yay * feat: rc1, generate slot display types * feat: gen recipe display and recipe book categories * feat: consume effect generation * chore: 1.21.2
1 parent 39aa498 commit 536187f

File tree

7 files changed

+53
-41
lines changed

7 files changed

+53
-41
lines changed

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

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

3+
import net.minecraft.core.registries.BuiltInRegistries;
4+
import net.minecraft.core.registries.Registries;
35
import net.minestom.generators.*;
46
import net.minestom.generators.loot_tables.BlockLootTableGenerator;
57
import net.minestom.generators.loot_tables.ChestLootTableGenerator;
@@ -31,7 +33,11 @@ public enum DataGenType {
3133
SOUND_SOURCES("sound_sources", new SoundSourceGenerator()),
3234
VILLAGER_PROFESSIONS("villager_professions", new VillagerProfessionGenerator()),
3335
VILLAGER_TYPES("villager_types", new VillagerTypeGenerator()),
34-
RECIPE_TYPE("recipe_types", new RecipeTypeGenerator()),
36+
RECIPE_TYPE("recipe_types", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_TYPE)),
37+
RECIPE_DISPLAY_TYPE("recipe_display_types", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_DISPLAY)),
38+
SLOT_DISPLAY_TYPE("slot_display_types", new GenericRegistryGenerator<>(BuiltInRegistries.SLOT_DISPLAY)),
39+
RECIPE_BOOK_CATEGORY("recipe_book_categories", new GenericRegistryGenerator<>(BuiltInRegistries.RECIPE_BOOK_CATEGORY)),
40+
CONSUME_EFFECT("consume_effects", new GenericRegistryGenerator<>(BuiltInRegistries.CONSUME_EFFECT_TYPE)),
3541

3642
// Tags are specified as a special case in datagen
3743

@@ -45,6 +51,7 @@ public enum DataGenType {
4551
ENCHANTMENTS("enchantments", new GenericResourceGenerator("enchantment", List.of(), true)),
4652
PAINTING_VARIANTS("painting_variants", new GenericResourceGenerator("painting_variant")),
4753
JUKEBOX_SONGS("jukebox_songs", new GenericResourceGenerator("jukebox_song")),
54+
INSTRUMENTS("instruments", new GenericResourceGenerator("instrument")),
4855

4956
BLOCK_LOOT_TABLES("loot_tables/block_loot_tables", new BlockLootTableGenerator()),
5057
CHEST_LOOT_TABLES("loot_tables/chest_loot_tables", new ChestLootTableGenerator()),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public JsonObject generate() {
5757

5858
// There are only XY and XYZ offset functions, so we simply execute the offset func
5959
// and check if the Y value is 0. It is seeded to the coordinates, so it should be reliable.
60-
var result = defaultBlockState.getOffset(EmptyBlockGetter.INSTANCE, new BlockPos(42, 42, 42));
60+
var result = defaultBlockState.getOffset(new BlockPos(42, 42, 42));
6161
if (result.y != 0) {
6262
blockJson.addProperty("maxVerticalOffset", BlockBehaviourHack.getMaxVerticalOffset(block));
6363
}
@@ -151,7 +151,7 @@ private void writeState(ResourceLocation location, Block block, BlockState block
151151
appendState(blockJson, state, "shape", blockState.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
152152
appendState(blockJson, state, "collisionShape", blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
153153
appendState(blockJson, state, "interactionShape", blockState.getInteractionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
154-
appendState(blockJson, state, "occlusionShape", blockState.getOcclusionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
154+
appendState(blockJson, state, "occlusionShape", blockState.getOcclusionShape().toAabbs().toString(), String.class);
155155
appendState(blockJson, state, "visualShape", blockState.getVisualShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CollisionContext.empty()).toAabbs().toString(), String.class);
156156

157157
// Redstone bits

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public JsonObject generate() {
107107
}
108108

109109
private double findDrag(EntityType<?> entityType) {
110-
if (entityType == EntityType.BOAT) return 0;
110+
if (isBoat(entityType)) return 0;
111111

112112
if (entityType == EntityType.LLAMA_SPIT) return 0.01;
113113
if (entityType == EntityType.ENDER_PEARL) return 0.01;
@@ -133,7 +133,7 @@ private double findAcceleration(EntityType<?> entityType) {
133133
if (entityType == EntityType.ENDER_PEARL) return 0.03;
134134
if (entityType == EntityType.SNOWBALL) return 0.03;
135135

136-
if (entityType == EntityType.BOAT) return 0.04;
136+
if (isBoat(entityType)) return 0.04;
137137
if (entityType == EntityType.TNT) return 0.04;
138138
if (entityType == EntityType.FALLING_BLOCK) return 0.04;
139139
if (entityType == EntityType.ITEM) return 0.04;
@@ -164,4 +164,8 @@ private double findAcceleration(EntityType<?> entityType) {
164164
throw new RuntimeException(e);
165165
}
166166
}
167+
168+
private static boolean isBoat(@NotNull EntityType<?> entityType) {
169+
return BuiltInRegistries.ENTITY_TYPE.getKey(entityType).toString().contains("boat");
170+
}
167171
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 GenericRegistryGenerator<T> extends DataGenerator {
10+
private final Registry<T> registry;
11+
12+
public GenericRegistryGenerator(@NotNull Registry<T> registry) {
13+
this.registry = registry;
14+
}
15+
16+
@Override
17+
public JsonArray generate() {
18+
JsonArray output = new JsonArray();
19+
20+
for (T entry : registry) {
21+
JsonObject result = new JsonObject();
22+
23+
result.addProperty("id", registry.getId(entry));
24+
//noinspection DataFlowIssue We got `entry` from the registry, it is not null.
25+
result.addProperty("name", registry.getKey(entry).toString());
26+
appendEntry(result, entry);
27+
28+
output.add(result);
29+
}
30+
31+
return output;
32+
}
33+
34+
protected void appendEntry(JsonObject object, T entry) {
35+
}
36+
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ public JsonObject generate() {
5959
itemJson.addProperty("correspondingBlock", blockRegistry.getKey(block).toString());
6060
}
6161

62-
// Armor properties (which aren't components still??)
63-
if (item instanceof ArmorItem armorItem) {
64-
JsonObject armorProperties = new JsonObject();
65-
armorProperties.addProperty("defense", armorItem.getDefense());
66-
armorProperties.addProperty("toughness", armorItem.getToughness());
67-
armorProperties.addProperty("slot", armorItem.getEquipmentSlot().getName());
68-
itemJson.add("armorProperties", armorProperties);
69-
}
70-
7162
// Spawn egg properties
7263
if (item instanceof SpawnEggItem spawnEggItem) {
7364
JsonObject spawnEggProperties = new JsonObject();

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

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

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ metadata.format.version = "1.1"
22

33
[versions]
44
gson = "2.10.1"
5-
minecraft = "1.21"
5+
minecraft = "1.21.2"
66

77
slf4j-api = "2.0.7"
88
logback = "1.4.5"

0 commit comments

Comments
 (0)