Skip to content

Commit 8b431b3

Browse files
committed
Registry sync for JEI
1 parent 498d7fa commit 8b431b3

File tree

6 files changed

+69
-24
lines changed

6 files changed

+69
-24
lines changed

src/main/generated_resources/data/allomancy/recipe/lerasium_investing.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "allomancy:investing",
3-
"input": "#allomancy:converts_to_lerasium",
3+
"ingredient": "#allomancy:converts_to_lerasium",
44
"result": {
55
"count": 1,
66
"id": "allomancy:lerasium_nugget"
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
package com.legobmw99.allomancy.integration.jei;
22

33
import com.legobmw99.allomancy.Allomancy;
4-
import com.legobmw99.allomancy.modules.consumables.ConsumeSetup;
54
import com.legobmw99.allomancy.modules.consumables.item.recipe.VialItemRecipe;
65
import com.legobmw99.allomancy.modules.extras.ExtrasSetup;
7-
import com.legobmw99.allomancy.modules.world.recipe.InvestingRecipe;
86
import mezz.jei.api.IModPlugin;
97
import mezz.jei.api.JeiPlugin;
10-
import mezz.jei.api.constants.VanillaTypes;
8+
import mezz.jei.api.registration.IRecipeCatalystRegistration;
119
import mezz.jei.api.registration.IRecipeCategoryRegistration;
1210
import mezz.jei.api.registration.IRecipeRegistration;
1311
import mezz.jei.api.registration.IVanillaCategoryExtensionRegistration;
14-
import net.minecraft.core.registries.Registries;
1512
import net.minecraft.network.chat.Component;
16-
import net.minecraft.resources.ResourceKey;
1713
import net.minecraft.resources.ResourceLocation;
18-
import net.minecraft.world.item.Items;
19-
import net.minecraft.world.item.crafting.Ingredient;
20-
import net.minecraft.world.item.crafting.RecipeHolder;
21-
22-
import java.util.List;
2314

2415
@JeiPlugin
2516
public class AllomancyJeiPlugin implements IModPlugin {
@@ -40,19 +31,22 @@ public void registerCategories(IRecipeCategoryRegistration registration) {
4031
registration.addRecipeCategories(new InvestingRecipeCategory(registration.getJeiHelpers().getGuiHelper()));
4132
}
4233

34+
@Override
35+
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
36+
registration.addCraftingStation(InvestingRecipeCategory.TYPE, ExtrasSetup.CHARGED_BRONZE_EARRING);
37+
}
38+
4339
@Override
4440
public void registerRecipes(IRecipeRegistration registration) {
45-
// TODO: actually list/show mobs? Would have same registry problem as below.
46-
registration.addIngredientInfo(
47-
List.of(ExtrasSetup.CHARGED_BRONZE_EARRING.toStack(), ExtrasSetup.BRONZE_EARRING.toStack()),
48-
VanillaTypes.ITEM_STACK, Component.translatable("allomancy.jei.charged_earring.1"),
49-
Component.translatable("allomancy.jei.charged_earring.2"),
50-
Component.translatable("allomancy.jei.charged_earring.3"));
51-
52-
// TODO figure out how to use Registry now
53-
registration.addRecipes(InvestingRecipeCategory.TYPE, List.of(new RecipeHolder<>(
54-
ResourceKey.create(Registries.RECIPE, Allomancy.rl("lerasium_investing")),
55-
new InvestingRecipe(Ingredient.of(Items.NETHER_STAR), ConsumeSetup.LERASIUM_NUGGET.toStack()))));
41+
// TODO: actually list/show mobs?
42+
registration.addIngredientInfo(ExtrasSetup.CHARGED_BRONZE_EARRING,
43+
Component.translatable("allomancy.jei.charged_earring.1"),
44+
Component.translatable("allomancy.jei.charged_earring.2"),
45+
Component.translatable("allomancy.jei.charged_earring.3"));
46+
47+
if (RecipeEventHandler.recipes != null) {
48+
registration.addRecipes(InvestingRecipeCategory.TYPE, RecipeEventHandler.recipes);
49+
}
5650
}
5751

5852
}

src/main/java/com/legobmw99/allomancy/integration/jei/InvestingRecipeCategory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
import org.jetbrains.annotations.Nullable;
2121

2222
public class InvestingRecipeCategory implements IRecipeCategory<RecipeHolder<InvestingRecipe>> {
23-
private final IDrawable icon;
2423
public static final IRecipeHolderType<InvestingRecipe> TYPE =
2524
IRecipeType.create(WorldSetup.INVESTING_RECIPE.get());
2625

26+
private final IDrawable icon;
27+
2728
public InvestingRecipeCategory(IGuiHelper helper) {
2829
icon = helper.createDrawableItemLike(ConsumeSetup.LERASIUM_NUGGET.get());
2930
}
@@ -46,6 +47,7 @@ public Component getTitle() {
4647
@Override
4748
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<InvestingRecipe> recipe, IFocusGroup focuses) {
4849
builder.addInputSlot(30, 14).add(recipe.value().getIngredient());
50+
4951
// TODO better liquid rendering?
5052
builder.addSlot(RecipeIngredientRole.CRAFTING_STATION, 40, 24).add(WorldSetup.LERASIUM_FLUID.get());
5153
builder.addOutputSlot(96, 24).add(recipe.value().getResult()).setOutputSlotBackground();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.legobmw99.allomancy.integration.jei;
2+
3+
import com.legobmw99.allomancy.Allomancy;
4+
import com.legobmw99.allomancy.modules.world.WorldSetup;
5+
import com.legobmw99.allomancy.modules.world.recipe.InvestingRecipe;
6+
import net.minecraft.world.item.crafting.RecipeHolder;
7+
import net.neoforged.bus.api.SubscribeEvent;
8+
import net.neoforged.fml.common.EventBusSubscriber;
9+
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
10+
import net.neoforged.neoforge.client.event.RecipesReceivedEvent;
11+
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
12+
13+
import java.util.List;
14+
15+
/**
16+
* This handles the fact that recipes are not, by default, sent to the client any more.
17+
*/
18+
@EventBusSubscriber(modid = Allomancy.MODID)
19+
final class RecipeEventHandler {
20+
private RecipeEventHandler() {}
21+
22+
public static List<RecipeHolder<InvestingRecipe>> recipes = null;
23+
24+
@SubscribeEvent
25+
public static void onRecipesRecieved(final RecipesReceivedEvent event) {
26+
recipes = event.getRecipeMap().byType(WorldSetup.INVESTING_RECIPE.get()).stream().toList();
27+
}
28+
29+
@SubscribeEvent
30+
public static void onClientDisconnect(final ClientPlayerNetworkEvent.LoggingOut event) {
31+
recipes = null;
32+
}
33+
34+
@SubscribeEvent
35+
public static void onDataSync(final OnDatapackSyncEvent event) {
36+
event.sendRecipes(WorldSetup.INVESTING_RECIPE.get());
37+
}
38+
}

src/main/java/com/legobmw99/allomancy/modules/world/WorldSetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public String toString() {
232232
@Override
233233
public MapCodec<InvestingRecipe> codec() {
234234
return RecordCodecBuilder.mapCodec(instance -> instance
235-
.group(Ingredient.CODEC.fieldOf("input").forGetter(InvestingRecipe::getIngredient),
235+
.group(Ingredient.CODEC.fieldOf("ingredient").forGetter(InvestingRecipe::getIngredient),
236236
ItemStack.CODEC.fieldOf("result").forGetter(InvestingRecipe::getResult))
237237
.apply(instance, InvestingRecipe::new));
238238
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "allomancy:investing",
3+
"ingredient": "#minecraft:dirt",
4+
"result": {
5+
"count": 1,
6+
"id": "minecraft:diamond",
7+
"components": {
8+
"minecraft:item_name": "dirty diamond"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)