Skip to content

Commit a8d4a86

Browse files
Cleanup RecipeSchemaStorage, add RecipeNamespace#withExistingParent
1 parent 937ccc0 commit a8d4a86

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/main/java/dev/latvian/mods/kubejs/recipe/schema/RecipeNamespace.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.minecraft.resources.ResourceLocation;
55

66
import java.util.LinkedHashMap;
7+
import java.util.NoSuchElementException;
78

89
public class RecipeNamespace extends LinkedHashMap<String, RecipeSchemaType> {
910
public final RecipeSchemaStorage storage;
@@ -28,15 +29,28 @@ public RecipeNamespace registerBasic(String id, RecipeKey<?>... keys) {
2829
}
2930

3031
public RecipeNamespace shaped(String id) {
31-
return register(id, storage.shapedSchema);
32+
return withExistingParent(id, ResourceLocation.withDefaultNamespace("shaped"));
3233
}
3334

3435
public RecipeNamespace shapeless(String id) {
35-
return register(id, storage.shapelessSchema);
36+
return withExistingParent(id, ResourceLocation.withDefaultNamespace("shapeless"));
3637
}
3738

3839
public RecipeNamespace special(String id) {
39-
return register(id, storage.specialSchema);
40+
return withExistingParent(id, ResourceLocation.withDefaultNamespace("special"));
41+
}
42+
43+
public RecipeNamespace withExistingParent(String id, ResourceLocation parent) {
44+
return register(id, storage.namespace(parent.getNamespace()).getRegisteredOrThrow(parent.getPath()).schema);
45+
}
46+
47+
public RecipeSchemaType getRegisteredOrThrow(String id) {
48+
var value = get(id);
49+
if (value != null) {
50+
return value;
51+
} else {
52+
throw new NoSuchElementException("Required schema %s not found!".formatted(id));
53+
}
4054
}
4155

4256
@Override

src/main/java/dev/latvian/mods/kubejs/recipe/schema/RecipeSchemaStorage.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.util.HashMap;
3131
import java.util.Map;
32-
import java.util.Objects;
3332

3433
public class RecipeSchemaStorage {
3534

@@ -59,9 +58,7 @@ public void init(RecipeTypeRegistryContext ctx) {
5958
public final Map<String, RecipeNamespace> namespaces;
6059
public final Map<String, ResourceLocation> mappings;
6160
public final Map<String, RecipeSchemaType> schemaTypes;
62-
public RecipeSchema shapedSchema;
63-
public RecipeSchema shapelessSchema;
64-
public RecipeSchema specialSchema;
61+
6562
public Codec<RecipeComponent<?>> recipeComponentCodec;
6663
public Codec<RecipePostProcessor> recipePostProcessorCodec;
6764

@@ -86,9 +83,6 @@ public void fireEvents(RegistryAccessContainer registries, ResourceManager resou
8683
namespaces.clear();
8784
mappings.clear();
8885
schemaTypes.clear();
89-
shapedSchema = null;
90-
shapelessSchema = null;
91-
specialSchema = null;
9286

9387
var jsonOps = registries.json();
9488

@@ -197,10 +191,6 @@ public void fireEvents(RegistryAccessContainer registries, ResourceManager resou
197191
var schemaRegistry = new RecipeSchemaRegistry(this);
198192
JsonRecipeSchemaLoader.load(rcCtx, jsonOps, schemaRegistry, resourceManager);
199193

200-
shapedSchema = Objects.requireNonNull(namespace("minecraft").get("shaped").schema);
201-
shapelessSchema = Objects.requireNonNull(namespace("minecraft").get("shapeless").schema);
202-
specialSchema = Objects.requireNonNull(namespace("minecraft").get("special").schema);
203-
204194
KubeJSPlugins.forEachPlugin(schemaRegistry, KubeJSPlugin::registerRecipeSchemas);
205195
ServerEvents.RECIPE_SCHEMA_REGISTRY.post(ScriptType.SERVER, schemaRegistry);
206196
}

0 commit comments

Comments
 (0)