Search in sources :

Example 26 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class RecyclingRecipes method registerRecyclingRecipes.

public static void registerRecyclingRecipes(ItemStack input, List<MaterialStack> components, boolean ignoreArcSmelting, @Nullable OrePrefix prefix) {
    // Gather the valid Materials for use in recycling recipes.
    // - Filter out Materials that cannot create a Dust
    // - Filter out Materials that do not equate to at least 1 Nugget worth of Material.
    // - Sort Materials on a descending material amount
    List<MaterialStack> materials = components.stream().filter(stack -> stack.material.hasProperty(PropertyKey.DUST)).filter(stack -> stack.amount >= M / 9).sorted(Comparator.comparingLong(ms -> -ms.amount)).collect(Collectors.toList());
    // Exit if no Materials matching the above requirements exist.
    if (materials.isEmpty())
        return;
    // Calculate the voltage multiplier based on if a Material has a Blast Property
    int voltageMultiplier = calculateVoltageMultiplier(components);
    if (prefix != OrePrefix.dust) {
        registerMaceratorRecycling(input, components, voltageMultiplier);
    }
    if (prefix != null) {
        registerExtractorRecycling(input, components, voltageMultiplier, prefix);
    }
    if (ignoreArcSmelting)
        return;
    if (components.size() == 1) {
        Material m = components.get(0).material;
        // skip non-ingot materials
        if (!m.hasProperty(PropertyKey.INGOT)) {
            return;
        }
        // Skip Ingot -> Ingot Arc Recipes
        if (OreDictUnifier.getPrefix(input) == OrePrefix.ingot && m.getProperty(PropertyKey.INGOT).getArcSmeltInto() == m) {
            return;
        }
    }
    registerArcRecycling(input, components, prefix);
}
Also used : OreDictUnifier(gregtech.api.unification.OreDictUnifier) java.util(java.util) M(gregtech.api.GTValues.M) L(gregtech.api.GTValues.L) Materials(gregtech.api.unification.material.Materials) BlastProperty(gregtech.api.unification.material.properties.BlastProperty) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Function(java.util.function.Function) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) Material(gregtech.api.unification.material.Material) OrePrefix(gregtech.api.unification.ore.OrePrefix) RecipeMaps(gregtech.api.recipes.RecipeMaps) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MaterialFlags(gregtech.api.unification.material.info.MaterialFlags) PropertyKey(gregtech.api.unification.material.properties.PropertyKey) Tuple(net.minecraft.util.Tuple) Collectors(java.util.stream.Collectors) MaterialStack(gregtech.api.unification.stack.MaterialStack) GTValues(gregtech.api.GTValues) RecipeBuilder(gregtech.api.recipes.RecipeBuilder) Entry(java.util.Map.Entry) GTUtility(gregtech.api.util.GTUtility) MaterialStack(gregtech.api.unification.stack.MaterialStack) Material(gregtech.api.unification.material.Material)

Example 27 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class RecyclingRecipes method finalizeOutputs.

private static List<ItemStack> finalizeOutputs(List<MaterialStack> materials, int maxOutputs, Function<MaterialStack, ItemStack> toItemStackMapper) {
    // Map of ItemStack, Long to properly sort by the true material amount for outputs
    List<Tuple<ItemStack, MaterialStack>> outputs = new ArrayList<>();
    for (MaterialStack ms : materials) {
        ItemStack stack = toItemStackMapper.apply(ms);
        if (stack == ItemStack.EMPTY)
            continue;
        if (stack.getCount() > 64) {
            UnificationEntry entry = OreDictUnifier.getUnificationEntry(stack);
            if (entry != null) {
                // should always be true
                OrePrefix prefix = entry.orePrefix;
                // so simply split the stacks and continue.
                if (prefix == OrePrefix.block || prefix == OrePrefix.dust) {
                    splitStacks(outputs, stack, entry);
                } else {
                    // Attempt to split and to shrink the stack, and choose the option that creates the
                    // "larger" single stack, in terms of raw material amount.
                    List<Tuple<ItemStack, MaterialStack>> split = new ArrayList<>();
                    List<Tuple<ItemStack, MaterialStack>> shrink = new ArrayList<>();
                    splitStacks(split, stack, entry);
                    shrinkStacks(shrink, stack, entry);
                    if (split.get(0).getSecond().amount > shrink.get(0).getSecond().amount) {
                        outputs.addAll(split);
                    } else
                        outputs.addAll(shrink);
                }
            }
        } else
            outputs.add(new Tuple<>(stack, ms));
    }
    // Sort the List by total material amount descending.
    outputs.sort(Comparator.comparingLong(e -> -e.getSecond().amount));
    // Sort "duplicate" outputs to the end.
    // For example, if there are blocks of Steel and nuggets of Steel, and the nuggets
    // are preventing some other output from occupying one of the final slots of the machine,
    // cut the nuggets out to favor the newer item instead of having 2 slots occupied by Steel.
    // 
    // There is probably a better way to do this.
    Map<MaterialStack, ItemStack> temp = new HashMap<>();
    for (Tuple<ItemStack, MaterialStack> t : outputs) {
        boolean isInMap = false;
        for (MaterialStack ms : temp.keySet()) {
            if (ms.material == t.getSecond().material) {
                isInMap = true;
                break;
            }
        }
        if (!isInMap)
            temp.put(t.getSecond(), t.getFirst());
    }
    temp.putAll(outputs.stream().filter(t -> !temp.containsKey(t.getSecond())).collect(Collectors.toMap(Tuple::getSecond, Tuple::getFirst)));
    // Filter Ash to the very end of the list, after all others
    List<ItemStack> ashStacks = temp.entrySet().stream().filter(e -> isAshMaterial(e.getKey())).sorted(Comparator.comparingLong(e -> -e.getKey().amount)).map(Entry::getValue).collect(Collectors.toList());
    List<ItemStack> returnValues = temp.entrySet().stream().sorted(Comparator.comparingLong(e -> -e.getKey().amount)).filter(e -> !isAshMaterial(e.getKey())).limit(maxOutputs).map(Entry::getValue).collect(Collectors.toList());
    for (int i = 0; i < ashStacks.size() && returnValues.size() < maxOutputs; i++) {
        returnValues.add(ashStacks.get(i));
    }
    return returnValues;
}
Also used : OreDictUnifier(gregtech.api.unification.OreDictUnifier) java.util(java.util) M(gregtech.api.GTValues.M) L(gregtech.api.GTValues.L) Materials(gregtech.api.unification.material.Materials) BlastProperty(gregtech.api.unification.material.properties.BlastProperty) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Function(java.util.function.Function) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) Material(gregtech.api.unification.material.Material) OrePrefix(gregtech.api.unification.ore.OrePrefix) RecipeMaps(gregtech.api.recipes.RecipeMaps) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MaterialFlags(gregtech.api.unification.material.info.MaterialFlags) PropertyKey(gregtech.api.unification.material.properties.PropertyKey) Tuple(net.minecraft.util.Tuple) Collectors(java.util.stream.Collectors) MaterialStack(gregtech.api.unification.stack.MaterialStack) GTValues(gregtech.api.GTValues) RecipeBuilder(gregtech.api.recipes.RecipeBuilder) Entry(java.util.Map.Entry) GTUtility(gregtech.api.util.GTUtility) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) OrePrefix(gregtech.api.unification.ore.OrePrefix) MaterialStack(gregtech.api.unification.stack.MaterialStack) ItemStack(net.minecraft.item.ItemStack) Tuple(net.minecraft.util.Tuple)

Example 28 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class BrewingRecipes method init.

public static void init() {
    for (Material material : new Material[] { Talc, Soapstone, Redstone }) {
        BREWING_RECIPES.recipeBuilder().input(dust, material).fluidInputs(Oil.getFluid(1000)).fluidOutputs(Lubricant.getFluid(1000)).duration(128).EUt(4).buildAndRegister();
        BREWING_RECIPES.recipeBuilder().input(dust, material).fluidInputs(Creosote.getFluid(1000)).fluidOutputs(Lubricant.getFluid(1000)).duration(128).EUt(4).buildAndRegister();
        BREWING_RECIPES.recipeBuilder().input(dust, material).fluidInputs(SeedOil.getFluid(1000)).fluidOutputs(Lubricant.getFluid(1000)).duration(128).EUt(4).buildAndRegister();
    }
    // Biomass
    BREWING_RECIPES.recipeBuilder().duration(800).EUt(3).input("treeSapling", 1).fluidInputs(Water.getFluid(100)).fluidOutputs(Biomass.getFluid(100)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.POTATO)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.CARROT)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.CACTUS)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.REEDS)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.BROWN_MUSHROOM)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Blocks.RED_MUSHROOM)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().duration(160).EUt(3).inputs(new ItemStack(Items.BEETROOT)).fluidInputs(Water.getFluid(20)).fluidOutputs(Biomass.getFluid(20)).buildAndRegister();
    BREWING_RECIPES.recipeBuilder().EUt(4).duration(128).input(BIO_CHAFF).fluidInputs(Water.getFluid(750)).fluidOutputs(Biomass.getFluid(750)).buildAndRegister();
}
Also used : Material(gregtech.api.unification.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 29 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolRecipeHandler method registerSoftHammerRecipes.

private static void registerSoftHammerRecipes() {
    Material[] softHammerMaterials = new Material[] { Materials.Wood, Materials.Rubber, Materials.Polyethylene, Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole };
    for (int i = 0; i < softHammerMaterials.length; i++) {
        Material material = softHammerMaterials[i];
        ItemStack itemStack = MetaItems.SOFT_HAMMER.getStackForm();
        if (ModHandler.isMaterialWood(material)) {
            MetaItems.SOFT_HAMMER.setToolData(itemStack, material, 48, 1, 4.0f, 1.0f);
            ModHandler.addMirroredShapedRecipe(String.format("soft_hammer_%s", material), itemStack, "XX ", "XXS", "XX ", 'X', new UnificationEntry(OrePrefix.plank, material), 'S', new UnificationEntry(OrePrefix.stick, Materials.Wood));
        } else {
            MetaItems.SOFT_HAMMER.setToolData(itemStack, material, 128 * (1 << i), 1, 4.0f, 1.0f);
            ModHandler.addMirroredShapedRecipe(String.format("soft_hammer_%s", material), itemStack, "XX ", "XXS", "XX ", 'X', new UnificationEntry(OrePrefix.ingot, material), 'S', new UnificationEntry(OrePrefix.stick, Materials.Wood));
        }
    }
}
Also used : UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 30 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolRecipeHandler method processSimpleToolHead.

public static void processSimpleToolHead(OrePrefix toolPrefix, Material material, MetaToolValueItem toolItem, boolean mirrored, Object... recipe) {
    Material handleMaterial = Materials.Wood;
    ModHandler.addShapelessRecipe(String.format("%s_%s_%s", toolPrefix.name(), material, handleMaterial), toolItem.getStackForm(material), new UnificationEntry(toolPrefix, material), new UnificationEntry(OrePrefix.stick, handleMaterial));
    if (material.hasProperty(PropertyKey.INGOT) && material.hasFlag(GENERATE_PLATE)) {
        addSimpleToolRecipe(toolPrefix, material, toolItem, new UnificationEntry(OrePrefix.plate, material), new UnificationEntry(OrePrefix.ingot, material), mirrored, recipe);
    } else if (material.hasProperty(GEM)) {
        addSimpleToolRecipe(toolPrefix, material, toolItem, new UnificationEntry(OrePrefix.gem, material), new UnificationEntry(OrePrefix.gem, material), mirrored, recipe);
    }
}
Also used : UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.Material)

Aggregations

Material (gregtech.api.unification.material.Material)76 ItemStack (net.minecraft.item.ItemStack)31 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)19 OrePrefix (gregtech.api.unification.ore.OrePrefix)13 MaterialStack (gregtech.api.unification.stack.MaterialStack)12 Nonnull (javax.annotation.Nonnull)10 PropertyKey (gregtech.api.unification.material.properties.PropertyKey)9 Block (net.minecraft.block.Block)8 IBlockState (net.minecraft.block.state.IBlockState)8 GTValues (gregtech.api.GTValues)7 Collectors (java.util.stream.Collectors)7 Nullable (javax.annotation.Nullable)7 Materials (gregtech.api.unification.material.Materials)6 DustProperty (gregtech.api.unification.material.properties.DustProperty)6 ToolProperty (gregtech.api.unification.material.properties.ToolProperty)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 GregTechAPI (gregtech.api.GregTechAPI)5 OreDictUnifier (gregtech.api.unification.OreDictUnifier)5 MarkerMaterial (gregtech.api.unification.material.MarkerMaterial)5 ItemMaterialInfo (gregtech.api.unification.stack.ItemMaterialInfo)5