PageRenderTime 77ms CodeModel.GetById 11ms app.highlight 60ms RepoModel.GetById 2ms app.codeStats 0ms

/common/buildcraft/transport/BCTransportRecipes.java

https://github.com/2xsaiko/BuildCraft
Java | 348 lines | 281 code | 55 blank | 12 comment | 38 complexity | 950957b99b2cf91533d6adfe037905a1 MD5 | raw file
  1/*
  2 * Copyright (c) 2017 SpaceToad and the BuildCraft team
  3 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
  4 * distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/
  5 */
  6
  7package buildcraft.transport;
  8
  9import java.util.HashSet;
 10import java.util.Set;
 11
 12import com.google.common.collect.ImmutableSet;
 13
 14import net.minecraft.block.Block;
 15import net.minecraft.init.Blocks;
 16import net.minecraft.init.Items;
 17import net.minecraft.item.EnumDyeColor;
 18import net.minecraft.item.Item;
 19import net.minecraft.item.ItemStack;
 20import net.minecraft.item.crafting.IRecipe;
 21import net.minecraft.item.crafting.Ingredient;
 22import net.minecraft.item.crafting.ShapelessRecipes;
 23import net.minecraft.util.NonNullList;
 24import net.minecraft.util.ResourceLocation;
 25
 26import net.minecraftforge.common.crafting.CraftingHelper;
 27import net.minecraftforge.event.RegistryEvent;
 28import net.minecraftforge.fml.common.Mod;
 29import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 30import net.minecraftforge.fml.common.registry.ForgeRegistries;
 31import net.minecraftforge.fml.common.registry.GameRegistry;
 32import net.minecraftforge.oredict.OreDictionary;
 33import net.minecraftforge.oredict.ShapedOreRecipe;
 34import net.minecraftforge.oredict.ShapelessOreRecipe;
 35
 36import buildcraft.api.enums.EnumEngineType;
 37import buildcraft.api.enums.EnumRedstoneChipset;
 38import buildcraft.api.mj.MjAPI;
 39import buildcraft.api.recipes.AssemblyRecipe;
 40import buildcraft.api.recipes.AssemblyRecipeBasic;
 41import buildcraft.api.recipes.IngredientStack;
 42
 43import buildcraft.lib.misc.ColourUtil;
 44import buildcraft.lib.recipe.AssemblyRecipeRegistry;
 45import buildcraft.lib.recipe.IngredientNBTBC;
 46import buildcraft.lib.recipe.RecipeBuilderShaped;
 47
 48import buildcraft.core.BCCoreBlocks;
 49import buildcraft.transport.gate.EnumGateLogic;
 50import buildcraft.transport.gate.EnumGateMaterial;
 51import buildcraft.transport.gate.EnumGateModifier;
 52import buildcraft.transport.gate.GateVariant;
 53import buildcraft.transport.item.ItemPipeHolder;
 54import buildcraft.transport.recipe.FacadeAssemblyRecipes;
 55import buildcraft.transport.recipe.FacadeSwapRecipe;
 56
 57@Mod.EventBusSubscriber(modid = BCTransport.MODID)
 58public class BCTransportRecipes {
 59    @GameRegistry.ObjectHolder("buildcraftsilicon:assembly_table")
 60    private static final Block SILICON_TABLE_ASSEMBLY = null;
 61
 62    @SubscribeEvent
 63    public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
 64        addPipeRecipe(BCTransportItems.pipeItemWood, "plankWood");
 65        addPipeRecipe(BCTransportItems.pipeItemCobble, "cobblestone");
 66        addPipeRecipe(BCTransportItems.pipeItemStone, "stone");
 67        addPipeRecipe(BCTransportItems.pipeItemQuartz, "blockQuartz");
 68        addPipeRecipe(BCTransportItems.pipeItemIron, "ingotIron");
 69        addPipeRecipe(BCTransportItems.pipeItemGold, "ingotGold");
 70        addPipeRecipe(BCTransportItems.pipeItemClay, Blocks.CLAY);
 71        addPipeRecipe(BCTransportItems.pipeItemSandstone,
 72            new ItemStack(Blocks.SANDSTONE, 1, OreDictionary.WILDCARD_VALUE));
 73        addPipeRecipe(BCTransportItems.pipeItemVoid, new ItemStack(Items.DYE, 1, EnumDyeColor.BLACK.getDyeDamage()),
 74            "dustRedstone");
 75        addPipeRecipe(BCTransportItems.pipeItemObsidian, Blocks.OBSIDIAN);
 76        addPipeRecipe(BCTransportItems.pipeItemDiamond, Items.DIAMOND);
 77        addPipeRecipe(BCTransportItems.pipeItemLapis, Blocks.LAPIS_BLOCK);
 78        addPipeRecipe(BCTransportItems.pipeItemDaizuli, Blocks.LAPIS_BLOCK, Items.DIAMOND);
 79        addPipeRecipe(BCTransportItems.pipeItemDiaWood, "plankWood", Items.DIAMOND);
 80
 81        Item waterproof = BCTransportItems.waterproof;
 82        if (waterproof == null) {
 83            waterproof = Items.SLIME_BALL;
 84        }
 85        addPipeUpgradeRecipe(BCTransportItems.pipeItemWood, BCTransportItems.pipeFluidWood, waterproof);
 86        addPipeUpgradeRecipe(BCTransportItems.pipeItemCobble, BCTransportItems.pipeFluidCobble, waterproof);
 87        addPipeUpgradeRecipe(BCTransportItems.pipeItemStone, BCTransportItems.pipeFluidStone, waterproof);
 88        addPipeUpgradeRecipe(BCTransportItems.pipeItemQuartz, BCTransportItems.pipeFluidQuartz, waterproof);
 89        addPipeUpgradeRecipe(BCTransportItems.pipeItemIron, BCTransportItems.pipeFluidIron, waterproof);
 90        addPipeUpgradeRecipe(BCTransportItems.pipeItemGold, BCTransportItems.pipeFluidGold, waterproof);
 91        addPipeUpgradeRecipe(BCTransportItems.pipeItemClay, BCTransportItems.pipeFluidClay, waterproof);
 92        addPipeUpgradeRecipe(BCTransportItems.pipeItemSandstone, BCTransportItems.pipeFluidSandstone, waterproof);
 93        addPipeUpgradeRecipe(BCTransportItems.pipeItemVoid, BCTransportItems.pipeFluidVoid, waterproof);
 94        addPipeUpgradeRecipe(BCTransportItems.pipeItemObsidian, BCTransportItems.pipeFluidObsidian, waterproof);
 95        addPipeUpgradeRecipe(BCTransportItems.pipeItemDiamond, BCTransportItems.pipeFluidDiamond, waterproof);
 96        addPipeUpgradeRecipe(BCTransportItems.pipeItemDiaWood, BCTransportItems.pipeFluidDiaWood, waterproof);
 97
 98        String upgrade = "dustRedstone";
 99        addPipeUpgradeRecipe(BCTransportItems.pipeItemWood, BCTransportItems.pipePowerWood, upgrade);
100        addPipeUpgradeRecipe(BCTransportItems.pipeItemCobble, BCTransportItems.pipePowerCobble, upgrade);
101        addPipeUpgradeRecipe(BCTransportItems.pipeItemStone, BCTransportItems.pipePowerStone, upgrade);
102        addPipeUpgradeRecipe(BCTransportItems.pipeItemQuartz, BCTransportItems.pipePowerQuartz, upgrade);
103//        addPipeUpgradeRecipe(BCTransportItems.pipeItemIron, BCTransportItems.pipePowerIron, upgrade);
104        addPipeUpgradeRecipe(BCTransportItems.pipeItemGold, BCTransportItems.pipePowerGold, upgrade);
105        addPipeUpgradeRecipe(BCTransportItems.pipeItemSandstone, BCTransportItems.pipePowerSandstone, upgrade);
106//        addPipeUpgradeRecipe(BCTransportItems.pipeItemDiamond, BCTransportItems.pipePowerDiamond, upgrade);
107        if (BCTransportItems.plugGate != null) {
108            // You can craft some of the basic gate types in a normal crafting table
109            RecipeBuilderShaped builder = new RecipeBuilderShaped();
110            builder.add(" m ");
111            builder.add("mrm");
112            builder.add(" b ");
113            builder.map('r', "dustRedstone");
114            builder.map('b', BCTransportItems.plugBlocker, Blocks.COBBLESTONE);
115
116            // Base craftable types
117
118            builder.map('m', Items.BRICK);
119            makeGateRecipe(builder, EnumGateMaterial.CLAY_BRICK, EnumGateModifier.NO_MODIFIER);
120
121            builder.map('m', "ingotIron");
122            makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER);
123
124            builder.map('m', Items.NETHERBRICK);
125            makeGateRecipe(builder, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.NO_MODIFIER);
126
127            // Iron modifier addition
128            GateVariant variant =
129                new GateVariant(EnumGateLogic.AND, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER);
130            ItemStack ironGateBase = BCTransportItems.plugGate.getStack(variant);
131            builder = new RecipeBuilderShaped();
132            builder.add(" m ");
133            builder.add("mgm");
134            builder.add(" m ");
135            builder.map('g', ironGateBase);
136
137            builder.map('m', new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()));
138            makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.LAPIS);
139
140            builder.map('m', Items.QUARTZ);
141            makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.QUARTZ);
142
143            // And Gate <-> Or Gate (shapeless)
144            // TODO: Create a recipe class for this instead!
145            for (EnumGateMaterial material : EnumGateMaterial.VALUES) {
146                if (material == EnumGateMaterial.CLAY_BRICK) {
147                    continue;
148                }
149                for (EnumGateModifier modifier : EnumGateModifier.VALUES) {
150                    GateVariant varAnd = new GateVariant(EnumGateLogic.AND, material, modifier);
151                    ItemStack resultAnd = BCTransportItems.plugGate.getStack(varAnd);
152
153                    GateVariant varOr = new GateVariant(EnumGateLogic.OR, material, modifier);
154                    ItemStack resultOr = BCTransportItems.plugGate.getStack(varOr);
155
156                    ForgeRegistries.RECIPES.register(new ShapedOreRecipe(resultOr.getItem().getRegistryName(), resultAnd, "i", 'i', new IngredientNBTBC(resultOr)).setRegistryName(resultOr.getItem().getRegistryName() + "_" + modifier + "_" + material + "_or"));
157                    ForgeRegistries.RECIPES.register(new ShapedOreRecipe(resultAnd.getItem().getRegistryName(), resultOr, "i", 'i', new IngredientNBTBC(resultAnd)).setRegistryName(resultAnd.getItem().getRegistryName() + "_" + modifier + "_" + material + "_and"));
158                }
159            }
160
161        }
162
163        if (BCTransportItems.plugPulsar != null) {
164            ItemStack output = new ItemStack(BCTransportItems.plugPulsar);
165
166            ItemStack redstoneEngine;
167            if (BCCoreBlocks.engine != null) {
168                redstoneEngine = BCCoreBlocks.engine.getStack(EnumEngineType.WOOD);
169            } else {
170                redstoneEngine = new ItemStack(Blocks.REDSTONE_BLOCK);
171            }
172
173            if (SILICON_TABLE_ASSEMBLY != null) {
174                Set<IngredientStack> input = new HashSet<>();
175                input.add(new IngredientStack(Ingredient.fromStacks(redstoneEngine)));
176                input.add(new IngredientStack(CraftingHelper.getIngredient("ingotIron"), 2));
177                AssemblyRecipe recipe = new AssemblyRecipeBasic("plug_pulsar", 1000 * MjAPI.MJ, input, output);
178                AssemblyRecipeRegistry.register(recipe);
179            }
180        }
181        if (BCTransportItems.plugGate != null) {
182            IngredientStack lapis = IngredientStack.of("gemLapis");
183            makeGateAssembly(20_000, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER, EnumRedstoneChipset.IRON);
184            makeGateAssembly(40_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.NO_MODIFIER,
185                EnumRedstoneChipset.IRON, IngredientStack.of(new ItemStack(Blocks.NETHER_BRICK)));
186            makeGateAssembly(80_000, EnumGateMaterial.GOLD, EnumGateModifier.NO_MODIFIER, EnumRedstoneChipset.GOLD);
187
188            makeGateModifierAssembly(40_000, EnumGateMaterial.IRON, EnumGateModifier.LAPIS, lapis);
189            makeGateModifierAssembly(60_000, EnumGateMaterial.IRON, EnumGateModifier.QUARTZ,
190                IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
191            makeGateModifierAssembly(80_000, EnumGateMaterial.IRON, EnumGateModifier.DIAMOND,
192                IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
193
194            makeGateModifierAssembly(80_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.LAPIS, lapis);
195            makeGateModifierAssembly(100_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.QUARTZ,
196                IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
197            makeGateModifierAssembly(120_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.DIAMOND,
198                IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
199
200            makeGateModifierAssembly(100_000, EnumGateMaterial.GOLD, EnumGateModifier.LAPIS, lapis);
201            makeGateModifierAssembly(140_000, EnumGateMaterial.GOLD, EnumGateModifier.QUARTZ,
202                IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
203            makeGateModifierAssembly(180_000, EnumGateMaterial.GOLD, EnumGateModifier.DIAMOND,
204                IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
205        }
206
207        if (BCTransportItems.plugLightSensor != null) {
208            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("light-sensor", 500 * MjAPI.MJ,
209                ImmutableSet.of(IngredientStack.of(Blocks.DAYLIGHT_DETECTOR)),
210                new ItemStack(BCTransportItems.plugLightSensor)));
211        }
212
213        if (BCTransportItems.plugFacade != null) {
214            AssemblyRecipeRegistry.register(FacadeAssemblyRecipes.INSTANCE);
215            ForgeRegistries.RECIPES.register(FacadeSwapRecipe.INSTANCE);
216        }
217
218        if (BCTransportItems.wire != null) {
219            for (EnumDyeColor color : ColourUtil.COLOURS) {
220                String name = String.format("wire-%s", color.getUnlocalizedName());
221                ImmutableSet<IngredientStack> input = ImmutableSet.of(IngredientStack.of("dustRedstone"),
222                    IngredientStack.of(ColourUtil.getDyeName(color)));
223                AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 10_000 * MjAPI.MJ, input,
224                    new ItemStack(BCTransportItems.wire, 8, color.getMetadata())));
225            }
226        }
227
228        if (BCTransportItems.plugLens != null) {
229            for (EnumDyeColor colour : ColourUtil.COLOURS) {
230                String name = String.format("lens-regular-%s", colour.getUnlocalizedName());
231                IngredientStack stainedGlass = IngredientStack.of("blockGlass" + ColourUtil.getName(colour));
232                ImmutableSet<IngredientStack> input = ImmutableSet.of(stainedGlass);
233                ItemStack output = BCTransportItems.plugLens.getStack(colour, false);
234                AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 500 * MjAPI.MJ, input, output));
235
236                name = String.format("lens-filter-%s", colour.getUnlocalizedName());
237                output = BCTransportItems.plugLens.getStack(colour, true);
238                input = ImmutableSet.of(stainedGlass, IngredientStack.of(new ItemStack(Blocks.IRON_BARS)));
239                AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 500 * MjAPI.MJ, input, output));
240            }
241
242            IngredientStack glass = IngredientStack.of("blockGlass");
243            ImmutableSet<IngredientStack> input = ImmutableSet.of(glass);
244            ItemStack output = BCTransportItems.plugLens.getStack(null, false);
245            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("lens-regular", 500 * MjAPI.MJ, input, output));
246
247            output = BCTransportItems.plugLens.getStack(null, true);
248            input = ImmutableSet.of(glass, IngredientStack.of(new ItemStack(Blocks.IRON_BARS)));
249            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("lens-filter", 500 * MjAPI.MJ, input, output));
250        }
251    }
252
253
254    private static void makeGateModifierAssembly(int multiplier, EnumGateMaterial material, EnumGateModifier modifier,
255                                                 IngredientStack... mods) {
256        for (EnumGateLogic logic : EnumGateLogic.VALUES) {
257            String name = String.format("gate-modifier-%s-%s-%s", logic, material, modifier);
258            ItemStack toUpgrade =
259                BCTransportItems.plugGate.getStack(new GateVariant(logic, material, EnumGateModifier.NO_MODIFIER));
260            ItemStack output = BCTransportItems.plugGate.getStack(new GateVariant(logic, material, modifier));
261            ImmutableSet<IngredientStack> input = new ImmutableSet.Builder<IngredientStack>()
262                .add(IngredientStack.of(toUpgrade)).add(mods).build();
263            AssemblyRecipeRegistry.register((new AssemblyRecipeBasic(name, MjAPI.MJ * multiplier, input, output)));
264        }
265    }
266
267
268    private static void makeGateAssembly(int multiplier, EnumGateMaterial material, EnumGateModifier modifier,
269                                         EnumRedstoneChipset chipset, IngredientStack... additional) {
270        ImmutableSet.Builder<IngredientStack> temp = ImmutableSet.builder();
271        temp.add(IngredientStack.of(chipset.getStack()));
272        temp.add(additional);
273        ImmutableSet<IngredientStack> input = temp.build();
274
275        String name = String.format("gate-and-%s-%s", material, modifier);
276        ItemStack output = BCTransportItems.plugGate.getStack(new GateVariant(EnumGateLogic.AND, material, modifier));
277        AssemblyRecipeRegistry.register((new AssemblyRecipeBasic(name, MjAPI.MJ * multiplier, input, output)));
278
279        name = String.format("gate-or-%s-%s", material, modifier);
280        output = BCTransportItems.plugGate.getStack(new GateVariant(EnumGateLogic.OR, material, modifier));
281        AssemblyRecipeRegistry.register((new AssemblyRecipeBasic(name, MjAPI.MJ * multiplier, input, output)));
282    }
283
284    private static void makeGateRecipe(RecipeBuilderShaped builder, EnumGateMaterial material,
285                                       EnumGateModifier modifier) {
286        GateVariant variant = new GateVariant(EnumGateLogic.AND, material, modifier);
287        builder.setResult(BCTransportItems.plugGate.getStack(variant));
288        builder.registerNbtAware();
289    }
290
291    private static void addPipeRecipe(ItemPipeHolder pipe, Object material) {
292        addPipeRecipe(pipe, material, material);
293    }
294
295    private static void addPipeRecipe(ItemPipeHolder pipe, Object left, Object right) {
296        if (pipe == null) {
297            return;
298        }
299        ItemStack result = new ItemStack(pipe, 8);
300        IRecipe recipe = new ShapedOreRecipe(pipe.getRegistryName(),
301            result, "lgr", 'l', left, 'r', right, 'g', "blockGlassColorless");
302        recipe.setRegistryName(new ResourceLocation(pipe.getRegistryName() + "_colorless"));
303        ForgeRegistries.RECIPES.register(recipe);
304
305        for (EnumDyeColor colour : EnumDyeColor.values()) {
306            ItemStack resultStack = new ItemStack(pipe, 8, colour.getMetadata() + 1);
307            IRecipe colorRecipe = new ShapedOreRecipe(pipe.getRegistryName(), resultStack,
308                "lgr", 'l', left, 'r', right, 'g', "blockGlass" + ColourUtil.getName(colour));
309            colorRecipe.setRegistryName(new ResourceLocation(pipe.getRegistryName() + "_" + colour));
310            ForgeRegistries.RECIPES.register(colorRecipe);
311        }
312
313
314    }
315
316    private static void addPipeUpgradeRecipe(ItemPipeHolder from, ItemPipeHolder to, Object additional) {
317        if (from == null || to == null) {
318            return;
319        }
320        if (additional == null) {
321            throw new NullPointerException("additional");
322        }
323
324        IRecipe returnRecipe = new ShapelessOreRecipe(from.getRegistryName(), new ItemStack(from), new ItemStack(to)).setRegistryName(new ResourceLocation(from.getRegistryName() + "_undo"));
325        ForgeRegistries.RECIPES.register(returnRecipe);
326
327        NonNullList<Ingredient> list = NonNullList.create();
328        list.add(Ingredient.fromItem(from));
329        list.add(CraftingHelper.getIngredient(additional));
330
331        IRecipe upgradeRecipe = new ShapelessRecipes(to.getRegistryName().getResourcePath(), new ItemStack(to), list).setRegistryName(new ResourceLocation(to.getRegistryName() + "_colorless"));
332        ForgeRegistries.RECIPES.register(upgradeRecipe);
333
334        for (EnumDyeColor colour : ColourUtil.COLOURS) {
335            ItemStack f = new ItemStack(from, 1, colour.getMetadata() + 1);
336            ItemStack t = new ItemStack(to, 1, colour.getMetadata() + 1);
337            IRecipe returnRecipeColored = new ShapelessOreRecipe(from.getRegistryName(), f, t).setRegistryName(new ResourceLocation(from.getRegistryName() + colour.getName() + "_undo"));
338            ForgeRegistries.RECIPES.register(returnRecipeColored);
339
340            NonNullList<Ingredient> colorList = NonNullList.create();
341            colorList.add(Ingredient.fromStacks(f));
342            colorList.add(CraftingHelper.getIngredient(additional));
343
344            IRecipe upgradeRecipeColored = new ShapelessOreRecipe(to.getRegistryName(), colorList, t).setRegistryName(new ResourceLocation(to.getRegistryName() + "_" + colour.getName()));
345            ForgeRegistries.RECIPES.register(upgradeRecipeColored);
346        }
347    }
348}