|
6 | 6 | import com.robotgryphon.compactcrafting.blocks.FieldProjectorBlock; |
7 | 7 | import com.robotgryphon.compactcrafting.blocks.FieldProjectorTile; |
8 | 8 | import com.robotgryphon.compactcrafting.items.FieldProjectorItem; |
| 9 | +import com.robotgryphon.compactcrafting.recipes.MiniaturizationRecipe; |
| 10 | +import com.robotgryphon.compactcrafting.recipes.data.MiniaturizationRecipeSerializer; |
| 11 | +import com.robotgryphon.compactcrafting.recipes.data.base.BaseRecipeType; |
| 12 | +import com.robotgryphon.compactcrafting.recipes.data.serialization.layers.FilledLayerSerializer; |
| 13 | +import com.robotgryphon.compactcrafting.recipes.data.serialization.layers.HollowLayerSerializer; |
| 14 | +import com.robotgryphon.compactcrafting.recipes.data.serialization.layers.MixedLayerSerializer; |
| 15 | +import com.robotgryphon.compactcrafting.recipes.data.serialization.layers.RecipeLayerSerializer; |
| 16 | +import com.robotgryphon.compactcrafting.recipes.layers.impl.FilledComponentRecipeLayer; |
| 17 | +import com.robotgryphon.compactcrafting.recipes.layers.impl.HollowComponentRecipeLayer; |
| 18 | +import com.robotgryphon.compactcrafting.recipes.layers.impl.MixedComponentRecipeLayer; |
9 | 19 | import net.minecraft.block.AbstractBlock; |
10 | 20 | import net.minecraft.block.Block; |
11 | 21 | import net.minecraft.block.Blocks; |
12 | 22 | import net.minecraft.block.material.Material; |
13 | 23 | import net.minecraft.item.Item; |
| 24 | +import net.minecraft.item.crafting.IRecipeSerializer; |
14 | 25 | import net.minecraft.tileentity.TileEntityType; |
| 26 | +import net.minecraft.util.ResourceLocation; |
15 | 27 | import net.minecraftforge.common.ToolType; |
| 28 | +import net.minecraftforge.event.RegistryEvent; |
16 | 29 | import net.minecraftforge.eventbus.api.IEventBus; |
| 30 | +import net.minecraftforge.eventbus.api.SubscribeEvent; |
17 | 31 | import net.minecraftforge.fml.RegistryObject; |
| 32 | +import net.minecraftforge.fml.common.Mod; |
18 | 33 | import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; |
19 | | -import net.minecraftforge.registries.DeferredRegister; |
20 | | -import net.minecraftforge.registries.ForgeRegistries; |
| 34 | +import net.minecraftforge.registries.*; |
21 | 35 |
|
22 | 36 | import java.util.function.Supplier; |
23 | 37 |
|
24 | 38 | import static com.robotgryphon.compactcrafting.CompactCrafting.MOD_ID; |
25 | 39 |
|
| 40 | +@SuppressWarnings("unchecked") |
| 41 | +@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) |
26 | 42 | public class Registration { |
27 | 43 |
|
28 | 44 | // ================================================================================================================ |
29 | 45 | // REGISTRIES |
30 | 46 | // ================================================================================================================ |
| 47 | + |
| 48 | + |
31 | 49 | private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID); |
32 | 50 | private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID); |
33 | 51 | private static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, MOD_ID); |
| 52 | + private static final DeferredRegister<IRecipeSerializer<?>> RECIPES = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MOD_ID); |
| 53 | + |
| 54 | + public static DeferredRegister<RecipeLayerSerializer<?>> RECIPE_LAYERS = DeferredRegister.create((Class) RecipeLayerSerializer.class, MOD_ID); |
| 55 | + public static IForgeRegistry<RecipeLayerSerializer<?>> RECIPE_SERIALIZERS; |
| 56 | + |
| 57 | + static { |
| 58 | + RECIPE_LAYERS.makeRegistry("recipe_layer_serializers", () -> new RegistryBuilder<RecipeLayerSerializer<?>>() |
| 59 | + .setName(new ResourceLocation(MOD_ID, "recipe_layer_serializers")) |
| 60 | + .setType(c(RecipeLayerSerializer.class)) |
| 61 | + .tagFolder("recipe_layer_serializers")); |
| 62 | + } |
34 | 63 |
|
35 | 64 | // ================================================================================================================ |
36 | 65 | // PROPERTIES |
@@ -79,58 +108,47 @@ public class Registration { |
79 | 108 | // ================================================================================================================ |
80 | 109 | // MINIATURIZATION RECIPES |
81 | 110 | // ================================================================================================================ |
82 | | -// public static final RegistryObject<MiniaturizationRecipe> SIMPLE_RECIPE = MINIATURIZATION_RECIPES.register("simple", () -> |
83 | | -// { |
84 | | -// MiniaturizationRecipe rec = new MiniaturizationRecipe(); |
85 | | -// |
86 | | -// Set<BlockPos> glassColl = new HashSet<>(); |
87 | | -// Set<BlockPos> handleColl = new HashSet<>(); |
88 | | -// |
89 | | -// BlockPos[] glass = new BlockPos[]{ |
90 | | -// new BlockPos(3, 0, 0), |
91 | | -// new BlockPos(4, 0, 0), |
92 | | -// new BlockPos(2, 0, 1), |
93 | | -// new BlockPos(5, 0, 1), |
94 | | -// new BlockPos(2, 0, 2), |
95 | | -// new BlockPos(5, 0, 2), |
96 | | -// new BlockPos(3, 0, 3), |
97 | | -// new BlockPos(4, 0, 3) |
98 | | -// }; |
99 | | -// |
100 | | -// BlockPos[] handle = new BlockPos[]{ |
101 | | -// new BlockPos(2, 0, 3), |
102 | | -// new BlockPos(1, 0, 4), |
103 | | -// new BlockPos(0, 0, 5) |
104 | | -// }; |
105 | | -// |
106 | | -// Collections.addAll(glassColl, glass); |
107 | | -// Collections.addAll(handleColl, handle); |
108 | | -// |
109 | | -// MixedComponentRecipeLayer mixed = new MixedComponentRecipeLayer(); |
110 | | -// mixed.addMultiple("S", handleColl); |
111 | | -// mixed.addMultiple("G", glassColl); |
112 | | -// |
113 | | -// rec.setLayers(new IRecipeLayer[]{mixed}); |
114 | | -// |
115 | | -// rec.catalyst = Items.ANVIL; |
116 | | -// rec.outputs = new ItemStack[]{ |
117 | | -// new ItemStack(Items.CRYING_OBSIDIAN, 11) |
118 | | -// }; |
119 | | -// |
120 | | -// rec.addComponent("S", Blocks.STONE.getDefaultState()); |
121 | | -// rec.addComponent("G", Blocks.GLASS.getDefaultState()); |
122 | | -// |
123 | | -// return rec; |
124 | | -// }); |
| 111 | + public static final RegistryObject<IRecipeSerializer<MiniaturizationRecipe>> MINIATURIZATION_SERIALIZER = RECIPES.register("miniaturization", MiniaturizationRecipeSerializer::new); |
| 112 | + |
| 113 | + public static final ResourceLocation MINIATURIZATION_RECIPE_TYPE_ID = new ResourceLocation(MOD_ID, "miniaturization_recipe"); |
| 114 | + |
| 115 | + public static final BaseRecipeType<MiniaturizationRecipe> MINIATURIZATION_RECIPE_TYPE = new BaseRecipeType<>(MINIATURIZATION_RECIPE_TYPE_ID); |
| 116 | + |
| 117 | + // ================================================================================================================ |
| 118 | + // RECIPE LAYER SERIALIZERS |
| 119 | + // ================================================================================================================ |
| 120 | + public static final RegistryObject<RecipeLayerSerializer<FilledComponentRecipeLayer>> FILLED_LAYER_SERIALIZER = |
| 121 | + RECIPE_LAYERS.register("filled", FilledLayerSerializer::new); |
| 122 | + |
| 123 | + public static final RegistryObject<RecipeLayerSerializer<HollowComponentRecipeLayer>> HOLLOW_LAYER_SERIALIZER = |
| 124 | + RECIPE_LAYERS.register("hollow", HollowLayerSerializer::new); |
| 125 | + |
| 126 | + public static final RegistryObject<RecipeLayerSerializer<MixedComponentRecipeLayer>> MIXED_LAYER_SERIALIZER = |
| 127 | + RECIPE_LAYERS.register("mixed", MixedLayerSerializer::new); |
125 | 128 |
|
126 | 129 | // ================================================================================================================ |
127 | 130 | // INITIALIZATION |
128 | 131 | // ================================================================================================================ |
| 132 | + private static <T> Class<T> c(Class<?> cls) { return (Class<T>)cls; } |
| 133 | + |
129 | 134 | public static void init() { |
130 | 135 | IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); |
131 | 136 |
|
132 | 137 | BLOCKS.register(eventBus); |
133 | 138 | ITEMS.register(eventBus); |
134 | 139 | TILE_ENTITIES.register(eventBus); |
| 140 | + RECIPES.register(eventBus); |
| 141 | + |
| 142 | + // Recipe Types (Forge Registry setup does not call this yet) |
| 143 | + MINIATURIZATION_RECIPE_TYPE.register(); |
| 144 | + |
| 145 | + RECIPE_LAYERS.register(eventBus); |
135 | 146 | } |
| 147 | + |
| 148 | + @SubscribeEvent |
| 149 | + public static void onRegistration(RegistryEvent.Register<RecipeLayerSerializer<?>> evt) { |
| 150 | + RECIPE_SERIALIZERS = evt.getRegistry(); |
| 151 | + } |
| 152 | + |
| 153 | + |
136 | 154 | } |
0 commit comments