Search in sources :

Example 6 with Material

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

the class ModHandler method getRecyclingIngredients.

public static ItemMaterialInfo getRecyclingIngredients(int outputCount, Object... recipe) {
    Map<Character, Integer> inputCountMap = new HashMap<>();
    Map<Material, Long> materialStacksExploded = new HashMap<>();
    int itr = 0;
    while (recipe[itr] instanceof String) {
        String s = (String) recipe[itr];
        for (char c : s.toCharArray()) {
            // skip tools
            if (getToolNameByCharacter(c) != null)
                continue;
            int count = inputCountMap.getOrDefault(c, 0);
            inputCountMap.put(c, count + 1);
        }
        itr++;
    }
    char lastChar = ' ';
    for (int i = itr; i < recipe.length; i++) {
        Object ingredient = recipe[i];
        // Track the current working ingredient symbol
        if (ingredient instanceof Character) {
            lastChar = (char) ingredient;
            continue;
        }
        // by an earlier method call parsing the recipe.
        if (lastChar == ' ')
            return null;
        ItemStack stack;
        if (ingredient instanceof MetaItem.MetaValueItem) {
            stack = ((MetaItem<?>.MetaValueItem) ingredient).getStackForm();
        } else if (ingredient instanceof UnificationEntry) {
            stack = OreDictUnifier.get((UnificationEntry) ingredient);
        } else if (ingredient instanceof ItemStack) {
            stack = (ItemStack) ingredient;
        } else if (ingredient instanceof Item) {
            stack = new ItemStack((Item) ingredient, 1);
        } else if (ingredient instanceof Block) {
            stack = new ItemStack((Block) ingredient, 1);
        } else if (ingredient instanceof String) {
            stack = OreDictUnifier.get((String) ingredient);
        } else
            // throw out bad entries
            continue;
        BiConsumer<MaterialStack, Character> func = (ms, c) -> {
            long amount = materialStacksExploded.getOrDefault(ms.material, 0L);
            materialStacksExploded.put(ms.material, (ms.amount * inputCountMap.get(c)) + amount);
        };
        // First try to get ItemMaterialInfo
        ItemMaterialInfo info = OreDictUnifier.getMaterialInfo(stack);
        if (info != null) {
            for (MaterialStack ms : info.getMaterials()) {
                if (!(ms.material instanceof MarkerMaterial))
                    func.accept(ms, lastChar);
            }
            continue;
        }
        // Then try to get a single Material (UnificationEntry needs this, for example)
        MaterialStack materialStack = OreDictUnifier.getMaterial(stack);
        if (materialStack != null && !(materialStack.material instanceof MarkerMaterial))
            func.accept(materialStack, lastChar);
        // Gather any secondary materials if this item has an OrePrefix
        OrePrefix prefix = OreDictUnifier.getPrefix(stack);
        if (prefix != null && !prefix.secondaryMaterials.isEmpty()) {
            for (MaterialStack ms : prefix.secondaryMaterials) {
                func.accept(ms, lastChar);
            }
        }
    }
    return new ItemMaterialInfo(materialStacksExploded.entrySet().stream().map(e -> new MaterialStack(e.getKey(), e.getValue() / outputCount)).sorted(Comparator.comparingLong(m -> -m.amount)).collect(Collectors.toList()));
}
Also used : Loader(net.minecraftforge.fml.common.Loader) ToolDictNames(gregtech.api.items.ToolDictNames) Item(net.minecraft.item.Item) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) Materials(gregtech.api.unification.material.Materials) FurnaceRecipes(net.minecraft.item.crafting.FurnaceRecipes) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) ConfigHolder(gregtech.common.ConfigHolder) Block(net.minecraft.block.Block) Pair(org.apache.commons.lang3.tuple.Pair) MetaItem(gregtech.api.items.metaitem.MetaItem) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) Fluid(net.minecraftforge.fluids.Fluid) NonNullList(net.minecraft.util.NonNullList) DummyRecipe(gregtech.api.recipes.recipes.DummyRecipe) Predicate(java.util.function.Predicate) PropertyKey(gregtech.api.unification.material.properties.PropertyKey) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) Collectors(java.util.stream.Collectors) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) FluidStack(net.minecraftforge.fluids.FluidStack) OreDictUnifier(gregtech.api.unification.OreDictUnifier) Ingredient(net.minecraft.item.crafting.Ingredient) java.util(java.util) ShapedOreEnergyTransferRecipe(gregtech.api.util.ShapedOreEnergyTransferRecipe) DummyContainer(gregtech.api.util.DummyContainer) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) LocalizationUtils(gregtech.api.util.LocalizationUtils) ItemStack(net.minecraft.item.ItemStack) MCFurnaceManager(crafttweaker.mc1120.furnace.MCFurnaceManager) BiConsumer(java.util.function.BiConsumer) Material(gregtech.api.unification.material.Material) OrePrefix(gregtech.api.unification.ore.OrePrefix) CreativeTabs(net.minecraft.creativetab.CreativeTabs) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ActionAddFurnaceRecipe(crafttweaker.mc1120.actions.ActionAddFurnaceRecipe) DummyWorld(gregtech.api.util.world.DummyWorld) IRecipe(net.minecraft.item.crafting.IRecipe) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) GTLog(gregtech.api.util.GTLog) World(net.minecraft.world.World) Field(java.lang.reflect.Field) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MaterialStack(gregtech.api.unification.stack.MaterialStack) GTValues(gregtech.api.GTValues) CraftingManager(net.minecraft.item.crafting.CraftingManager) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) MetaItem(gregtech.api.items.metaitem.MetaItem) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) OrePrefix(gregtech.api.unification.ore.OrePrefix) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) Material(gregtech.api.unification.material.Material) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) Item(net.minecraft.item.Item) MetaItem(gregtech.api.items.metaitem.MetaItem) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) MaterialStack(gregtech.api.unification.stack.MaterialStack) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 7 with Material

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

the class ItemBlockMaterialPipe method getItemStackDisplayName.

@Nonnull
@SuppressWarnings("unchecked")
@Override
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
    PipeType pipeType = blockPipe.getItemPipeType(stack);
    Material material = ((BlockMaterialPipe<PipeType, NodeDataType, ?>) blockPipe).getItemMaterial(stack);
    return material == null ? " " : pipeType.getOrePrefix().getLocalNameForItem(material);
}
Also used : Material(gregtech.api.unification.material.Material) Nonnull(javax.annotation.Nonnull)

Example 8 with Material

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

the class OreDictUnifier method getMaterial.

@Nullable
public static MaterialStack getMaterial(ItemStack itemStack) {
    if (itemStack.isEmpty())
        return null;
    ItemAndMetadata simpleItemStack = new ItemAndMetadata(itemStack);
    UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
    if (entry != null) {
        Material entryMaterial = entry.material;
        if (entryMaterial == null) {
            entryMaterial = entry.orePrefix.materialType;
        }
        if (entryMaterial != null) {
            return new MaterialStack(entryMaterial, entry.orePrefix.getMaterialAmount(entryMaterial));
        }
    }
    ItemMaterialInfo info = materialUnificationInfo.get(simpleItemStack);
    return info == null ? null : info.getMaterial().copy();
}
Also used : Material(gregtech.api.unification.material.Material) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) Nullable(javax.annotation.Nullable)

Example 9 with Material

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

the class OrePrefix method runGeneratedMaterialHandlers.

private void runGeneratedMaterialHandlers() {
    currentProcessingPrefix.set(this);
    for (Material registeredMaterial : generatedMaterials) {
        currentMaterial.set(registeredMaterial);
        for (IOreRegistrationHandler registrationHandler : oreProcessingHandlers) {
            registrationHandler.processMaterial(this, registeredMaterial);
        }
        currentMaterial.set(null);
    }
    // clear generated materials for next pass
    generatedMaterials.clear();
    currentProcessingPrefix.set(null);
}
Also used : Material(gregtech.api.unification.material.Material)

Example 10 with Material

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

the class FrameBakedModel method getQuads.

@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    List<BakedQuad> quads = new ArrayList<>();
    if (side == null)
        return quads;
    if (state != null) {
        Material material = state.getValue(((BlockFrame) state.getBlock()).variantProperty);
        Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet());
        if (materialFace == null) {
            materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>());
        }
        BakedQuad materialFaceQuad = materialFace.get(side);
        if (materialFaceQuad == null) {
            materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad(new Vector3f(0F, 0F, 0F), new Vector3f(16F, 16F, 16F), new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), ModelLoader.defaultTextureGetter().apply(MaterialIconType.frameGt.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
        }
        quads.add(materialFaceQuad);
        particle.set(materialFaceQuad.getSprite());
    } else {
        ItemStack stack = FrameModelItemOverride.INSTANCE.stack.get();
        if (!stack.isEmpty()) {
            BlockFrame frame = (BlockFrame) ((ItemBlock) stack.getItem()).getBlock();
            IBlockState frameState = frame.getDefaultState().withProperty(frame.variantProperty, frame.variantProperty.getAllowedValues().get(stack.getMetadata()));
            for (EnumFacing face : EnumFacing.VALUES) {
                quads.addAll(getQuads(frameState, face, rand));
            }
        }
    }
    return quads;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Material(gregtech.api.unification.material.Material) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Vector3f(org.lwjgl.util.vector.Vector3f) ItemStack(net.minecraft.item.ItemStack) BlockFrame(gregtech.common.blocks.BlockFrame) Nonnull(javax.annotation.Nonnull)

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