Search in sources :

Example 1 with AssemblyRecipe

use of buildcraft.api.recipes.AssemblyRecipe in project BuildCraft by BuildCraft.

the class TileAssemblyTable method activateNextRecipe.

private void activateNextRecipe() {
    AssemblyInstruction activeRecipe = getActiveRecipe();
    if (activeRecipe != null) {
        int index = 0;
        int activeIndex = 0;
        boolean isActiveLast = false;
        long enoughCount = recipesStates.values().stream().filter(state -> state == EnumAssemblyRecipeState.SAVED_ENOUGH || state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE).count();
        if (enoughCount <= 1) {
            return;
        }
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
                isActiveLast = false;
            }
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH;
                entry.setValue(state);
                activeIndex = index;
                isActiveLast = true;
            }
            index++;
        }
        index = 0;
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            AssemblyRecipe recipe = entry.getKey().recipe;
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH && recipe != activeRecipe.recipe && (index > activeIndex || isActiveLast)) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
                entry.setValue(state);
                break;
            }
            index++;
        }
    }
}
Also used : EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) Constants(net.minecraftforge.common.util.Constants) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) MessageManager(buildcraft.lib.net.MessageManager) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) InventoryUtil(buildcraft.lib.misc.InventoryUtil) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) Iterator(java.util.Iterator) IdAllocator(buildcraft.lib.misc.data.IdAllocator) ItemHandlerManager(buildcraft.lib.tile.item.ItemHandlerManager) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) TileBC_Neptune(buildcraft.lib.tile.TileBC_Neptune) IOException(java.io.IOException) LocaleUtil(buildcraft.lib.misc.LocaleUtil) List(java.util.List) TreeMap(java.util.TreeMap) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) AssemblyRecipeRegistry(buildcraft.lib.recipe.AssemblyRecipeRegistry) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) SortedMap(java.util.SortedMap) AdvancementUtil(buildcraft.lib.misc.AdvancementUtil) EnumPipePart(buildcraft.api.core.EnumPipePart) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 2 with AssemblyRecipe

use of buildcraft.api.recipes.AssemblyRecipe in project BuildCraft by BuildCraft.

the class TileAssemblyTable method updateRecipes.

private void updateRecipes() {
    // TODO: rework this to not iterate over every recipe every tick
    int count = recipesStates.size();
    for (AssemblyRecipe recipe : AssemblyRecipeRegistry.REGISTRY.values()) {
        Set<ItemStack> outputs = recipe.getOutputs(inv.stacks);
        for (ItemStack out : outputs) {
            boolean found = false;
            for (AssemblyInstruction instruction : recipesStates.keySet()) {
                if (instruction.recipe == recipe && out == instruction.output) {
                    found = true;
                    break;
                }
            }
            AssemblyInstruction instruction = new AssemblyInstruction(recipe, out);
            if (!found && !recipesStates.containsKey(instruction)) {
                recipesStates.put(instruction, EnumAssemblyRecipeState.POSSIBLE);
            }
        }
    }
    boolean findActive = false;
    for (Iterator<Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState>> iterator = recipesStates.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry = iterator.next();
        AssemblyInstruction instruction = entry.getKey();
        EnumAssemblyRecipeState state = entry.getValue();
        boolean enough = extract(inv, instruction.recipe.getInputsFor(instruction.output), true, false);
        if (state == EnumAssemblyRecipeState.POSSIBLE) {
            if (!enough) {
                iterator.remove();
            }
        } else {
            if (enough) {
                if (state == EnumAssemblyRecipeState.SAVED) {
                    state = EnumAssemblyRecipeState.SAVED_ENOUGH;
                }
            } else {
                if (state != EnumAssemblyRecipeState.SAVED) {
                    state = EnumAssemblyRecipeState.SAVED;
                }
            }
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
            findActive = true;
        }
        entry.setValue(state);
    }
    if (!findActive) {
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
                entry.setValue(state);
                break;
            }
        }
    }
    if (count != recipesStates.size()) {
        sendNetworkGuiUpdate(NET_GUI_DATA);
    }
}
Also used : AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 3 with AssemblyRecipe

use of buildcraft.api.recipes.AssemblyRecipe in project BuildCraft by BuildCraft.

the class BCTransportRecipes method registerRecipes.

@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
    addPipeRecipe(BCTransportItems.pipeItemWood, "plankWood");
    addPipeRecipe(BCTransportItems.pipeItemCobble, "cobblestone");
    addPipeRecipe(BCTransportItems.pipeItemStone, "stone");
    addPipeRecipe(BCTransportItems.pipeItemQuartz, "blockQuartz");
    addPipeRecipe(BCTransportItems.pipeItemIron, "ingotIron");
    addPipeRecipe(BCTransportItems.pipeItemGold, "ingotGold");
    addPipeRecipe(BCTransportItems.pipeItemClay, Blocks.CLAY);
    addPipeRecipe(BCTransportItems.pipeItemSandstone, new ItemStack(Blocks.SANDSTONE, 1, OreDictionary.WILDCARD_VALUE));
    addPipeRecipe(BCTransportItems.pipeItemVoid, new ItemStack(Items.DYE, 1, EnumDyeColor.BLACK.getDyeDamage()), "dustRedstone");
    addPipeRecipe(BCTransportItems.pipeItemObsidian, Blocks.OBSIDIAN);
    addPipeRecipe(BCTransportItems.pipeItemDiamond, Items.DIAMOND);
    addPipeRecipe(BCTransportItems.pipeItemLapis, Blocks.LAPIS_BLOCK);
    addPipeRecipe(BCTransportItems.pipeItemDaizuli, Blocks.LAPIS_BLOCK, Items.DIAMOND);
    addPipeRecipe(BCTransportItems.pipeItemDiaWood, "plankWood", Items.DIAMOND);
    addPipeRecipe(BCTransportItems.pipeItemStripes, "gearGold");
    addPipeUpgradeRecipe(BCTransportItems.pipeItemDiaWood, BCTransportItems.pipeItemEmzuli, Blocks.LAPIS_BLOCK);
    Item waterproof = BCTransportItems.waterproof;
    if (waterproof == null) {
        waterproof = Items.SLIME_BALL;
    }
    addPipeUpgradeRecipe(BCTransportItems.pipeItemWood, BCTransportItems.pipeFluidWood, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemCobble, BCTransportItems.pipeFluidCobble, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemStone, BCTransportItems.pipeFluidStone, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemQuartz, BCTransportItems.pipeFluidQuartz, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemIron, BCTransportItems.pipeFluidIron, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemGold, BCTransportItems.pipeFluidGold, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemClay, BCTransportItems.pipeFluidClay, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemSandstone, BCTransportItems.pipeFluidSandstone, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemVoid, BCTransportItems.pipeFluidVoid, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemObsidian, BCTransportItems.pipeFluidObsidian, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemDiamond, BCTransportItems.pipeFluidDiamond, waterproof);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemDiaWood, BCTransportItems.pipeFluidDiaWood, waterproof);
    String upgrade = "dustRedstone";
    addPipeUpgradeRecipe(BCTransportItems.pipeItemWood, BCTransportItems.pipePowerWood, upgrade);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemCobble, BCTransportItems.pipePowerCobble, upgrade);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemStone, BCTransportItems.pipePowerStone, upgrade);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemQuartz, BCTransportItems.pipePowerQuartz, upgrade);
    // addPipeUpgradeRecipe(BCTransportItems.pipeItemIron, BCTransportItems.pipePowerIron, upgrade);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemGold, BCTransportItems.pipePowerGold, upgrade);
    addPipeUpgradeRecipe(BCTransportItems.pipeItemSandstone, BCTransportItems.pipePowerSandstone, upgrade);
    // addPipeUpgradeRecipe(BCTransportItems.pipeItemDiamond, BCTransportItems.pipePowerDiamond, upgrade);
    if (BCTransportItems.plugGate != null) {
        // You can craft some of the basic gate types in a normal crafting table
        RecipeBuilderShaped builder = new RecipeBuilderShaped();
        builder.add(" m ");
        builder.add("mrm");
        builder.add(" b ");
        builder.map('r', "dustRedstone");
        builder.map('b', BCTransportItems.plugBlocker, Blocks.COBBLESTONE);
        // Base craftable types
        builder.map('m', Items.BRICK);
        makeGateRecipe(builder, EnumGateMaterial.CLAY_BRICK, EnumGateModifier.NO_MODIFIER);
        builder.map('m', "ingotIron");
        makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER);
        builder.map('m', Items.NETHERBRICK);
        makeGateRecipe(builder, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.NO_MODIFIER);
        // Iron modifier addition
        GateVariant variant = new GateVariant(EnumGateLogic.AND, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER);
        ItemStack ironGateBase = BCTransportItems.plugGate.getStack(variant);
        builder = new RecipeBuilderShaped();
        builder.add(" m ");
        builder.add("mgm");
        builder.add(" m ");
        builder.map('g', ironGateBase);
        builder.map('m', new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()));
        makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.LAPIS);
        builder.map('m', Items.QUARTZ);
        makeGateRecipe(builder, EnumGateMaterial.IRON, EnumGateModifier.QUARTZ);
        // TODO: Create a recipe class for this instead!
        for (EnumGateMaterial material : EnumGateMaterial.VALUES) {
            if (material == EnumGateMaterial.CLAY_BRICK) {
                continue;
            }
            for (EnumGateModifier modifier : EnumGateModifier.VALUES) {
                GateVariant varAnd = new GateVariant(EnumGateLogic.AND, material, modifier);
                ItemStack resultAnd = BCTransportItems.plugGate.getStack(varAnd);
                GateVariant varOr = new GateVariant(EnumGateLogic.OR, material, modifier);
                ItemStack resultOr = BCTransportItems.plugGate.getStack(varOr);
                String regNamePrefix = resultOr.getItem().getRegistryName() + "_" + modifier + "_" + material;
                ForgeRegistries.RECIPES.register(new ShapedOreRecipe(resultOr.getItem().getRegistryName(), resultAnd, "i", 'i', new IngredientNBTBC(resultOr)).setRegistryName(regNamePrefix + "_or"));
                ForgeRegistries.RECIPES.register(new ShapedOreRecipe(resultAnd.getItem().getRegistryName(), resultOr, "i", 'i', new IngredientNBTBC(resultAnd)).setRegistryName(regNamePrefix + "_and"));
            }
        }
    }
    if (BCTransportItems.plugPulsar != null) {
        ItemStack output = new ItemStack(BCTransportItems.plugPulsar);
        ItemStack redstoneEngine;
        if (BCCoreBlocks.engine != null) {
            redstoneEngine = BCCoreBlocks.engine.getStack(EnumEngineType.WOOD);
        } else {
            redstoneEngine = new ItemStack(Blocks.REDSTONE_BLOCK);
        }
        if (SILICON_TABLE_ASSEMBLY != null) {
            Set<IngredientStack> input = new HashSet<>();
            input.add(new IngredientStack(Ingredient.fromStacks(redstoneEngine)));
            input.add(new IngredientStack(CraftingHelper.getIngredient("ingotIron"), 2));
            AssemblyRecipe recipe = new AssemblyRecipeBasic("plug_pulsar", 1000 * MjAPI.MJ, input, output);
            AssemblyRecipeRegistry.register(recipe);
        }
    }
    if (BCTransportItems.plugGate != null) {
        IngredientStack lapis = IngredientStack.of("gemLapis");
        makeGateAssembly(20_000, EnumGateMaterial.IRON, EnumGateModifier.NO_MODIFIER, EnumRedstoneChipset.IRON);
        makeGateAssembly(40_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.NO_MODIFIER, EnumRedstoneChipset.IRON, IngredientStack.of(new ItemStack(Blocks.NETHER_BRICK)));
        makeGateAssembly(80_000, EnumGateMaterial.GOLD, EnumGateModifier.NO_MODIFIER, EnumRedstoneChipset.GOLD);
        makeGateModifierAssembly(40_000, EnumGateMaterial.IRON, EnumGateModifier.LAPIS, lapis);
        makeGateModifierAssembly(60_000, EnumGateMaterial.IRON, EnumGateModifier.QUARTZ, IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
        makeGateModifierAssembly(80_000, EnumGateMaterial.IRON, EnumGateModifier.DIAMOND, IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
        makeGateModifierAssembly(80_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.LAPIS, lapis);
        makeGateModifierAssembly(100_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.QUARTZ, IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
        makeGateModifierAssembly(120_000, EnumGateMaterial.NETHER_BRICK, EnumGateModifier.DIAMOND, IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
        makeGateModifierAssembly(100_000, EnumGateMaterial.GOLD, EnumGateModifier.LAPIS, lapis);
        makeGateModifierAssembly(140_000, EnumGateMaterial.GOLD, EnumGateModifier.QUARTZ, IngredientStack.of(EnumRedstoneChipset.QUARTZ.getStack()));
        makeGateModifierAssembly(180_000, EnumGateMaterial.GOLD, EnumGateModifier.DIAMOND, IngredientStack.of(EnumRedstoneChipset.DIAMOND.getStack()));
    }
    if (BCTransportItems.plugLightSensor != null) {
        AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("light-sensor", 500 * MjAPI.MJ, ImmutableSet.of(IngredientStack.of(Blocks.DAYLIGHT_DETECTOR)), new ItemStack(BCTransportItems.plugLightSensor)));
    }
    if (BCTransportItems.plugFacade != null) {
        AssemblyRecipeRegistry.register(FacadeAssemblyRecipes.INSTANCE);
        ForgeRegistries.RECIPES.register(FacadeSwapRecipe.INSTANCE);
    }
    if (BCTransportItems.wire != null) {
        for (EnumDyeColor color : ColourUtil.COLOURS) {
            String name = String.format("wire-%s", color.getUnlocalizedName());
            ImmutableSet<IngredientStack> input = ImmutableSet.of(IngredientStack.of("dustRedstone"), IngredientStack.of(ColourUtil.getDyeName(color)));
            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 10_000 * MjAPI.MJ, input, new ItemStack(BCTransportItems.wire, 8, color.getMetadata())));
        }
    }
    if (BCTransportItems.plugLens != null) {
        for (EnumDyeColor colour : ColourUtil.COLOURS) {
            String name = String.format("lens-regular-%s", colour.getUnlocalizedName());
            IngredientStack stainedGlass = IngredientStack.of("blockGlass" + ColourUtil.getName(colour));
            ImmutableSet<IngredientStack> input = ImmutableSet.of(stainedGlass);
            ItemStack output = BCTransportItems.plugLens.getStack(colour, false);
            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 500 * MjAPI.MJ, input, output));
            name = String.format("lens-filter-%s", colour.getUnlocalizedName());
            output = BCTransportItems.plugLens.getStack(colour, true);
            input = ImmutableSet.of(stainedGlass, IngredientStack.of(new ItemStack(Blocks.IRON_BARS)));
            AssemblyRecipeRegistry.register(new AssemblyRecipeBasic(name, 500 * MjAPI.MJ, input, output));
        }
        IngredientStack glass = IngredientStack.of("blockGlass");
        ImmutableSet<IngredientStack> input = ImmutableSet.of(glass);
        ItemStack output = BCTransportItems.plugLens.getStack(null, false);
        AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("lens-regular", 500 * MjAPI.MJ, input, output));
        output = BCTransportItems.plugLens.getStack(null, true);
        input = ImmutableSet.of(glass, IngredientStack.of(new ItemStack(Blocks.IRON_BARS)));
        AssemblyRecipeRegistry.register(new AssemblyRecipeBasic("lens-filter", 500 * MjAPI.MJ, input, output));
    }
}
Also used : ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) GateVariant(buildcraft.transport.gate.GateVariant) EnumDyeColor(net.minecraft.item.EnumDyeColor) Item(net.minecraft.item.Item) AssemblyRecipeBasic(buildcraft.api.recipes.AssemblyRecipeBasic) EnumGateMaterial(buildcraft.transport.gate.EnumGateMaterial) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) RecipeBuilderShaped(buildcraft.lib.recipe.RecipeBuilderShaped) ItemStack(net.minecraft.item.ItemStack) IngredientStack(buildcraft.api.recipes.IngredientStack) EnumGateModifier(buildcraft.transport.gate.EnumGateModifier) IngredientNBTBC(buildcraft.lib.recipe.IngredientNBTBC) HashSet(java.util.HashSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with AssemblyRecipe

use of buildcraft.api.recipes.AssemblyRecipe in project BuildCraft by BuildCraft.

the class BCSiliconRecipes method addChipsetAssembly.

private static void addChipsetAssembly(int multiplier, String additional, EnumRedstoneChipset type) {
    ItemStack output = type.getStack();
    ImmutableSet.Builder<IngredientStack> inputs = ImmutableSet.builder();
    inputs.add(new IngredientStack(CraftingHelper.getIngredient("dustRedstone")));
    if (additional != null) {
        inputs.add(new IngredientStack(CraftingHelper.getIngredient(additional)));
    }
    String name = String.format("chipset-%s", type);
    AssemblyRecipe recp = new AssemblyRecipeBasic(name, multiplier * 10_000L * MjAPI.MJ, inputs.build(), output);
    AssemblyRecipeRegistry.REGISTRY.put(recp.getRegistryName(), recp);
}
Also used : AssemblyRecipeBasic(buildcraft.api.recipes.AssemblyRecipeBasic) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) ImmutableSet(com.google.common.collect.ImmutableSet) ItemStack(net.minecraft.item.ItemStack) IngredientStack(buildcraft.api.recipes.IngredientStack)

Aggregations

AssemblyRecipe (buildcraft.api.recipes.AssemblyRecipe)4 ItemStack (net.minecraft.item.ItemStack)4 AssemblyRecipeBasic (buildcraft.api.recipes.AssemblyRecipeBasic)2 IngredientStack (buildcraft.api.recipes.IngredientStack)2 EnumAssemblyRecipeState (buildcraft.silicon.EnumAssemblyRecipeState)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 AdvancementUtil (buildcraft.lib.misc.AdvancementUtil)1 InventoryUtil (buildcraft.lib.misc.InventoryUtil)1 LocaleUtil (buildcraft.lib.misc.LocaleUtil)1 IdAllocator (buildcraft.lib.misc.data.IdAllocator)1 MessageManager (buildcraft.lib.net.MessageManager)1 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)1 AssemblyRecipeRegistry (buildcraft.lib.recipe.AssemblyRecipeRegistry)1 IngredientNBTBC (buildcraft.lib.recipe.IngredientNBTBC)1 RecipeBuilderShaped (buildcraft.lib.recipe.RecipeBuilderShaped)1 TileBC_Neptune (buildcraft.lib.tile.TileBC_Neptune)1 ItemHandlerManager (buildcraft.lib.tile.item.ItemHandlerManager)1