HalestormXV

RecipeSerializerInit

Oct 25th, 2020
1,084
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.halestormxv.mysterium.init;
  2.  
  3. import com.halestormxv.mysterium.MysteriumMain;
  4. import com.halestormxv.mysterium.recipes.LunarForgeRecipe;
  5. import com.halestormxv.mysterium.recipes.LunarForgeRecipeSerializer;
  6. import com.halestormxv.mysterium.recipes.ILunarForgeRecipe;
  7. import net.minecraft.item.crafting.IRecipe;
  8. import net.minecraft.item.crafting.IRecipeSerializer;
  9. import net.minecraft.item.crafting.IRecipeType;
  10. import net.minecraft.util.ResourceLocation;
  11. import net.minecraft.util.registry.Registry;
  12. import net.minecraftforge.fml.RegistryObject;
  13. import net.minecraftforge.registries.DeferredRegister;
  14. import net.minecraftforge.registries.ForgeRegistries;
  15.  
  16.  
  17. public class RecipeSerializerInit {
  18.     //Declarations
  19.     public static final IRecipeSerializer<LunarForgeRecipe> LUNAR_FORGE_RECIPE_SERIALIZER = new LunarForgeRecipeSerializer(LunarForgeRecipe::new, 300);
  20.     public static final IRecipeType<ILunarForgeRecipe> LUNAR_FORGE_TYPE = registerType(ILunarForgeRecipe.RECIPE_TYPE_ID);
  21.  
  22.     //Deferred Creation
  23.     public static final DeferredRegister<IRecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MysteriumMain.MOD_ID);
  24.  
  25.     //The Recipe Objects
  26.     public static final RegistryObject<IRecipeSerializer<?>> LUNAR_FORGE_SERIALIZER = RECIPE_SERIALIZERS.register("lunarforge", () -> LUNAR_FORGE_RECIPE_SERIALIZER);
  27.  
  28.     //Private Methods to make it Work
  29.     private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> {
  30.         @Override
  31.         public String toString() {
  32.             return Registry.RECIPE_TYPE.getKey(this).toString();
  33.         }
  34.     }
  35.  
  36.     private static <T extends IRecipeType> T registerType(ResourceLocation recipeTypeId) {
  37.         return (T) Registry.register(Registry.RECIPE_TYPE, recipeTypeId, new RecipeType<>());
  38.     }
  39. }
  40.  
RAW Paste Data