Skip to content

Commit

Permalink
Split AdornRecipes into recipe type/serializer classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Oct 1, 2024
1 parent 82fe878 commit 1be2115
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import juuxel.adorn.item.AdornItems;
import juuxel.adorn.menu.BrewerMenu;
import juuxel.adorn.platform.ItemBridge;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeTypes;
import juuxel.adorn.recipe.BrewerInput;
import juuxel.adorn.recipe.FluidBrewingRecipe;
import juuxel.adorn.recipe.InventoryWrappingRecipeInput;
Expand Down Expand Up @@ -167,7 +167,7 @@ public static void tick(World world, BlockPos pos, BlockState state, BrewerBlock
}

var input = new RecipeInputImpl(brewer);
var recipe = world.getRecipeManager().getFirstMatch(AdornRecipes.BREWING_TYPE.get(), input, world).map(RecipeEntry::value).orElse(null);
var recipe = world.getRecipeManager().getFirstMatch(AdornRecipeTypes.BREWING.get(), input, world).map(RecipeEntry::value).orElse(null);

if (recipe != null && brewer.getStack(INPUT_SLOT).isOf(AdornItems.MUG.get())) {
if (brewer.progress++ >= MAX_PROGRESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import juuxel.adorn.AdornCommon;
import juuxel.adorn.block.AdornBlocks;
import juuxel.adorn.client.gui.screen.TradingStationScreen;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeTypes;
import juuxel.adorn.recipe.FluidBrewingRecipe;
import juuxel.adorn.recipe.ItemBrewingRecipe;

Expand All @@ -28,7 +28,7 @@ public void register(EmiRegistry registry) {

var recipeManager = registry.getRecipeManager();

for (var entry : recipeManager.listAllOfType(AdornRecipes.BREWING_TYPE.get())) {
for (var entry : recipeManager.listAllOfType(AdornRecipeTypes.BREWING.get())) {
BrewingEmiRecipe emiRecipe = switch (entry.value()) {
case ItemBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe);
case FluidBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import juuxel.adorn.AdornCommon;
import juuxel.adorn.block.AdornBlocks;
import juuxel.adorn.client.gui.screen.TradingStationScreen;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeTypes;
import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
Expand Down Expand Up @@ -37,7 +37,7 @@ public void registerCategories(IRecipeCategoryRegistration registration) {

@Override
public void registerRecipes(IRecipeRegistration registration) {
registerRecipes(registration, AdornRecipes.BREWING_TYPE.get(), JeiRecipeTypes.BREWER);
registerRecipes(registration, AdornRecipeTypes.BREWING.get(), JeiRecipeTypes.BREWER);
}

private <I extends RecipeInput, T extends Recipe<I>> void registerRecipes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import juuxel.adorn.compat.rei.AdornReiServer;
import juuxel.adorn.compat.rei.BrewerDisplay;
import juuxel.adorn.lib.AdornTags;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeTypes;
import juuxel.adorn.recipe.FluidBrewingRecipe;
import juuxel.adorn.recipe.ItemBrewingRecipe;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
Expand All @@ -28,8 +28,8 @@ public void registerCategories(CategoryRegistry registry) {

@Override
public void registerDisplays(DisplayRegistry registry) {
registry.registerRecipeFiller(ItemBrewingRecipe.class, AdornRecipes.BREWING_TYPE.get(), entry -> new BrewerDisplay(entry.value()));
registry.registerRecipeFiller(FluidBrewingRecipe.class, AdornRecipes.BREWING_TYPE.get(), entry -> new BrewerDisplay(entry.value()));
registry.registerRecipeFiller(ItemBrewingRecipe.class, AdornRecipeTypes.BREWING.get(), entry -> new BrewerDisplay(entry.value()));
registry.registerRecipeFiller(FluidBrewingRecipe.class, AdornRecipeTypes.BREWING.get(), entry -> new BrewerDisplay(entry.value()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
package juuxel.adorn.recipe;

import juuxel.adorn.AdornCommon;
import juuxel.adorn.lib.registry.Registered;
import juuxel.adorn.lib.registry.Registrar;
import juuxel.adorn.lib.registry.RegistrarFactory;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SpecialRecipeSerializer;
import net.minecraft.registry.RegistryKeys;

public final class AdornRecipes {
public final class AdornRecipeSerializers {
public static final Registrar<RecipeSerializer<?>> RECIPE_SERIALIZERS = RegistrarFactory.get().create(RegistryKeys.RECIPE_SERIALIZER);
public static final Registrar<RecipeType<?>> RECIPE_TYPES = RegistrarFactory.get().create(RegistryKeys.RECIPE_TYPE);

public static final Registered<RecipeType<BrewingRecipe>> BREWING_TYPE = registerRecipeType("brewing");
public static final Registered<RecipeSerializer<ItemBrewingRecipe>> BREWING_SERIALIZER =
public static final Registered<RecipeSerializer<ItemBrewingRecipe>> BREWING =
RECIPE_SERIALIZERS.register("brewing", ItemBrewingRecipe.Serializer::new);
public static final Registered<RecipeSerializer<FluidBrewingRecipe>> BREWING_FROM_FLUID_SERIALIZER =
public static final Registered<RecipeSerializer<FluidBrewingRecipe>> BREWING_FROM_FLUID =
RECIPE_SERIALIZERS.register("brewing_from_fluid", FluidBrewingRecipe.Serializer::new);

public static final Registered<RecipeSerializer<FertilizerRefillingRecipe>> FERTILIZER_REFILLING_SERIALIZER =
public static final Registered<RecipeSerializer<FertilizerRefillingRecipe>> FERTILIZER_REFILLING =
RECIPE_SERIALIZERS.register("fertilizer_refilling", () -> new SpecialRecipeSerializer<>(FertilizerRefillingRecipe::new));

private static <R extends Recipe<?>> Registered<RecipeType<R>> registerRecipeType(String id) {
return RECIPE_TYPES.register(id, () -> new RecipeType<>() {
@Override
public String toString() {
return AdornCommon.NAMESPACE + ':' + id;
}
});
}

public static void init() {
}
}
27 changes: 27 additions & 0 deletions common/src/main/java/juuxel/adorn/recipe/AdornRecipeTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package juuxel.adorn.recipe;

import juuxel.adorn.AdornCommon;
import juuxel.adorn.lib.registry.Registered;
import juuxel.adorn.lib.registry.Registrar;
import juuxel.adorn.lib.registry.RegistrarFactory;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.registry.RegistryKeys;

public final class AdornRecipeTypes {
public static final Registrar<RecipeType<?>> RECIPE_TYPES = RegistrarFactory.get().create(RegistryKeys.RECIPE_TYPE);

public static final Registered<RecipeType<BrewingRecipe>> BREWING = registerRecipeType("brewing");

private static <R extends Recipe<?>> Registered<RecipeType<R>> registerRecipeType(String id) {
return RECIPE_TYPES.register(id, () -> new RecipeType<>() {
@Override
public String toString() {
return AdornCommon.NAMESPACE + ':' + id;
}
});
}

public static void init() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public sealed interface BrewingRecipe extends Recipe<BrewerInput> permits FluidBrewingRecipe, ItemBrewingRecipe {
@Override
default RecipeType<?> getType() {
return AdornRecipes.BREWING_TYPE.get();
return AdornRecipeTypes.BREWING.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean fits(int width, int height) {

@Override
public RecipeSerializer<?> getSerializer() {
return AdornRecipes.FERTILIZER_REFILLING_SERIALIZER.get();
return AdornRecipeSerializers.FERTILIZER_REFILLING.get();
}

private record MatchResult(ItemStack wateringCan, int fertilizers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ItemStack getResult(RegistryWrapper.WrapperLookup registries) {

@Override
public RecipeSerializer<?> getSerializer() {
return AdornRecipes.BREWING_FROM_FLUID_SERIALIZER.get();
return AdornRecipeSerializers.BREWING_FROM_FLUID.get();
}

public static final class Serializer implements RecipeSerializer<FluidBrewingRecipe> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ItemStack getResult(RegistryWrapper.WrapperLookup registries) {

@Override
public RecipeSerializer<?> getSerializer() {
return AdornRecipes.BREWING_SERIALIZER.get();
return AdornRecipeSerializers.BREWING.get();
}

public static final class Serializer implements RecipeSerializer<ItemBrewingRecipe> {
Expand Down
6 changes: 4 additions & 2 deletions fabric/src/main/java/juuxel/adorn/Adorn.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import juuxel.adorn.loot.AdornLootConditionTypes;
import juuxel.adorn.loot.AdornLootFunctionTypes;
import juuxel.adorn.menu.AdornMenus;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeSerializers;
import juuxel.adorn.recipe.AdornRecipeTypes;
import juuxel.adorn.resources.AdornResources;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -53,7 +54,8 @@ public static void init() {
AdornStats.init();
SofaSleeping.init();
AdornCriteria.init();
AdornRecipes.init();
AdornRecipeTypes.init();
AdornRecipeSerializers.init();
AdornLootConditionTypes.init();
AdornLootFunctionTypes.init();
Compat.init();
Expand Down
10 changes: 6 additions & 4 deletions forge/src/main/java/juuxel/adorn/platform/forge/Adorn.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import juuxel.adorn.platform.forge.event.ItemEvents;
import juuxel.adorn.platform.forge.networking.AdornNetworking;
import juuxel.adorn.platform.forge.registrar.ForgeRegistrar;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.AdornRecipeSerializers;
import juuxel.adorn.recipe.AdornRecipeTypes;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
Expand All @@ -53,10 +54,11 @@ public Adorn() {
register(AdornBlockEntities.BLOCK_ENTITIES, modBus);
AdornItemGroups.init();
register(AdornItemGroups.ITEM_GROUPS, modBus);
AdornRecipes.init();
AdornRecipeTypes.init();
AdornRecipeSerializers.init();
register(AdornMenus.MENUS, modBus);
register(AdornRecipes.RECIPE_SERIALIZERS, modBus);
register(AdornRecipes.RECIPE_TYPES, modBus);
register(AdornRecipeSerializers.RECIPE_SERIALIZERS, modBus);
register(AdornRecipeTypes.RECIPE_TYPES, modBus);
register(AdornLootConditionTypes.LOOT_CONDITION_TYPES, modBus);
register(AdornLootFunctionTypes.LOOT_FUNCTION_TYPES, modBus);
register(AdornStats.CUSTOM_STATS, modBus);
Expand Down

0 comments on commit 1be2115

Please sign in to comment.