Search in sources :

Example 16 with SimpleItemStack

use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.

the class OreDictUnifier method onItemRegistration.

@SubscribeEvent
public static void onItemRegistration(OreDictionary.OreRegisterEvent event) {
    SimpleItemStack simpleItemStack = new SimpleItemStack(event.getOre());
    String oreName = event.getName();
    // cache this registration by name
    stackOreDictName.computeIfAbsent(simpleItemStack, k -> new HashSet<>()).add(oreName);
    // and try to transform registration name into OrePrefix + Material pair
    OrePrefix orePrefix = OrePrefix.getPrefix(oreName);
    Material material = null;
    if (orePrefix == null) {
        // split ore dict name to parts
        // oreBasalticMineralSand -> ore, Basaltic, Mineral, Sand
        ArrayList<String> splits = new ArrayList<>();
        StringBuilder builder = new StringBuilder();
        for (char character : oreName.toCharArray()) {
            if (Character.isUpperCase(character)) {
                if (builder.length() > 0) {
                    splits.add(builder.toString());
                    builder = new StringBuilder().append(character);
                } else
                    splits.add(Character.toString(character));
            } else
                builder.append(character);
        }
        if (builder.length() > 0) {
            splits.add(builder.toString());
        }
        // try to combine in different manners
        // oreBasaltic MineralSand , ore BasalticMineralSand
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < splits.size(); i++) {
            buffer.append(splits.get(i));
            // ore -> OrePrefix.ore
            OrePrefix maybePrefix = OrePrefix.getPrefix(buffer.toString());
            // BasalticMineralSand
            String possibleMaterialName = Joiner.on("").join(splits.subList(i + 1, splits.size()));
            // basaltic_mineral_sand
            String underscoreName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, possibleMaterialName);
            // Materials.BasalticSand
            Material possibleMaterial = Material.MATERIAL_REGISTRY.getObject(underscoreName);
            if (maybePrefix != null && possibleMaterial != null) {
                orePrefix = maybePrefix;
                material = possibleMaterial;
                break;
            }
        }
    }
    // finally register item
    if (orePrefix != null && (material != null || orePrefix.isSelfReferencing)) {
        UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
        stackUnificationInfo.put(simpleItemStack, unificationEntry);
        stackUnificationItems.computeIfAbsent(unificationEntry, p -> new ArrayList<>()).add(simpleItemStack);
        orePrefix.processOreRegistration(material);
    }
}
Also used : java.util(java.util) CaseFormat(com.google.common.base.CaseFormat) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) M(gregtech.api.GTValues.M) GemMaterial(gregtech.api.unification.material.type.GemMaterial) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) MaterialStack(gregtech.api.unification.stack.MaterialStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) ImmutableList(com.google.common.collect.ImmutableList) OreDictionary(net.minecraftforge.oredict.OreDictionary) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) OrePrefix(gregtech.api.unification.ore.OrePrefix) DustMaterial(gregtech.api.unification.material.type.DustMaterial) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) OrePrefix(gregtech.api.unification.ore.OrePrefix) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) GemMaterial(gregtech.api.unification.material.type.GemMaterial) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) DustMaterial(gregtech.api.unification.material.type.DustMaterial) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 17 with SimpleItemStack

use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.

the class OreDictUnifier method getByProducts.

@Nullable
public static ImmutableList<MaterialStack> getByProducts(ItemStack itemStack) {
    if (itemStack.isEmpty())
        return null;
    SimpleItemStack simpleItemStack = new SimpleItemStack(itemStack);
    UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
    if (entry != null && entry.material != null)
        return ImmutableList.of(new MaterialStack(entry.material, entry.orePrefix.materialAmount), entry.orePrefix.secondaryMaterial);
    ItemMaterialInfo info = materialUnificationInfo.get(simpleItemStack);
    return info == null ? null : info.byProducts;
}
Also used : ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) MaterialStack(gregtech.api.unification.stack.MaterialStack) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) Nullable(javax.annotation.Nullable)

Example 18 with SimpleItemStack

use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.

the class OreDictUnifier method get.

public static ItemStack get(OrePrefix orePrefix, Material material, int stackSize) {
    UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
    if (!stackUnificationItems.containsKey(unificationEntry) || !unificationEntry.orePrefix.isUnificationEnabled)
        return ItemStack.EMPTY;
    ArrayList<SimpleItemStack> keys = stackUnificationItems.get(unificationEntry);
    keys.sort(Comparator.comparing(a -> a.item.delegate.name().getResourceDomain()));
    return keys.size() > 0 ? keys.get(0).asItemStack(stackSize) : ItemStack.EMPTY;
}
Also used : java.util(java.util) CaseFormat(com.google.common.base.CaseFormat) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) M(gregtech.api.GTValues.M) GemMaterial(gregtech.api.unification.material.type.GemMaterial) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) MaterialStack(gregtech.api.unification.stack.MaterialStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) ImmutableList(com.google.common.collect.ImmutableList) OreDictionary(net.minecraftforge.oredict.OreDictionary) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) OrePrefix(gregtech.api.unification.ore.OrePrefix) DustMaterial(gregtech.api.unification.material.type.DustMaterial) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack)

Example 19 with SimpleItemStack

use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.

the class OreDictUnifier method getPrefix.

@Nullable
public static OrePrefix getPrefix(ItemStack itemStack) {
    if (itemStack.isEmpty())
        return null;
    SimpleItemStack simpleItemStack = new SimpleItemStack(itemStack);
    UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
    if (entry != null)
        return entry.orePrefix;
    return null;
}
Also used : UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) Nullable(javax.annotation.Nullable)

Example 20 with SimpleItemStack

use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.

the class OreDictUnifier method getMaterial.

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

Aggregations

SimpleItemStack (gregtech.api.unification.stack.SimpleItemStack)28 ItemStack (net.minecraft.item.ItemStack)25 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)11 DustMaterial (gregtech.api.unification.material.type.DustMaterial)9 SolidMaterial (gregtech.api.unification.material.type.SolidMaterial)8 GemMaterial (gregtech.api.unification.material.type.GemMaterial)6 MaterialStack (gregtech.api.unification.stack.MaterialStack)6 Nullable (javax.annotation.Nullable)6 MetalMaterial (gregtech.api.unification.material.type.MetalMaterial)5 ItemMaterialInfo (gregtech.api.unification.stack.ItemMaterialInfo)5 OrePrefix (gregtech.api.unification.ore.OrePrefix)4 CaseFormat (com.google.common.base.CaseFormat)3 Joiner (com.google.common.base.Joiner)3 ImmutableList (com.google.common.collect.ImmutableList)3 M (gregtech.api.GTValues.M)3 FluidMaterial (gregtech.api.unification.material.type.FluidMaterial)3 Material (gregtech.api.unification.material.type.Material)3 java.util (java.util)3 MinecraftForge (net.minecraftforge.common.MinecraftForge)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3