Search in sources :

Example 11 with Material

use of gregtech.api.unification.material.type.Material 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 12 with Material

use of gregtech.api.unification.material.type.Material 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 13 with Material

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

the class MetaFluids method init.

public static void init() {
    Materials.Water.setMaterialFluid(FluidRegistry.WATER);
    Materials.Ice.setMaterialFluid(FluidRegistry.WATER);
    Materials.Lava.setMaterialFluid(FluidRegistry.LAVA);
    FluidRegistry.registerFluid(DISTILLED_WATER);
    Materials.DistilledWater.setMaterialFluid(DISTILLED_WATER);
    FluidRegistry.addBucketForFluid(DISTILLED_WATER);
    fluidSprites.add(AUTO_GENERATED_FLUID_TEXTURE);
    // TODO TWEAK VALUES
    registerFluid(Materials.Air, FluidType.GAS, 295, true);
    registerFluid(Materials.Oxygen, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Hydrogen, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Deuterium, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Tritium, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Helium, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Argon, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Radon, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Fluorine, FluidType.LIQUID, 53, true);
    registerFluid(Materials.Titaniumtetrachloride, FluidType.LIQUID, 2200, true);
    registerFluid(Materials.Helium3, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Methane, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Nitrogen, FluidType.LIQUID, 295, true);
    registerFluid(Materials.NitrogenDioxide, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Steam, FluidType.GAS, 295, true);
    registerFluid(Materials.OilHeavy, FluidType.LIQUID, 295, true);
    registerFluid(Materials.OilMedium, FluidType.LIQUID, 295, true);
    registerFluid(Materials.OilLight, FluidType.LIQUID, 295, true);
    registerFluid(Materials.HydrogenSulfide, FluidType.GAS, 295, true);
    registerFluid(Materials.SulfuricGas, FluidType.GAS, 295, true);
    registerFluid(Materials.Gas, FluidType.GAS, 295, true);
    registerFluid(Materials.SulfuricNaphtha, FluidType.LIQUID, 295, true);
    registerFluid(Materials.SulfuricLightFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.SulfuricHeavyFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Naphtha, FluidType.LIQUID, 295, true);
    registerFluid(Materials.LightFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.HeavyFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.LPG, FluidType.LIQUID, 295, true);
    registerFluid(Materials.CrackedLightFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.CrackedHeavyFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.UUAmplifier, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Chlorine, FluidType.GAS, 295, true);
    registerFluid(Materials.Mercury, FluidType.LIQUID, 295, true);
    registerFluid(Materials.NitroFuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.SodiumPersulfate, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Glyceryl, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Lubricant, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Creosote, FluidType.LIQUID, 295, true);
    registerFluid(Materials.SeedOil, FluidType.LIQUID, 295, true);
    registerFluid(Materials.FishOil, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Oil, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Fuel, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Honey, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Biomass, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Ethanol, FluidType.LIQUID, 295, true);
    registerFluid(Materials.SulfuricAcid, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Milk, FluidType.LIQUID, 290, true);
    registerFluid(Materials.McGuffium239, FluidType.LIQUID, 295, true);
    registerFluid(Materials.Glue, FluidType.LIQUID, 295, true);
    registerFluid(Materials.FryingOilHot, FluidType.LIQUID, 400, true);
    for (Material material : Material.MATERIAL_REGISTRY) {
        if (!(material instanceof FluidMaterial))
            continue;
        FluidMaterial fluidMaterial = (FluidMaterial) material;
        if (fluidMaterial.shouldGenerateFluid() && fluidMaterial.getMaterialFluid() == null) {
            int temperature = fluidMaterial.getFluidTemperature();
            FluidType fluidType = fluidMaterial.hasFlag(MatFlags.STATE_GAS) ? FluidType.GAS : FluidType.LIQUID;
            registerFluid(fluidMaterial, fluidType, temperature, false);
        }
        if (fluidMaterial.shouldGeneratePlasma() && fluidMaterial.getMaterialPlasma() == null) {
            registerFluid(fluidMaterial, FluidType.PLASMA, 30000, false);
        }
    }
}
Also used : FluidMaterial(gregtech.api.unification.material.type.FluidMaterial) FluidMaterial(gregtech.api.unification.material.type.FluidMaterial) Material(gregtech.api.unification.material.type.Material)

Example 14 with Material

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

the class MetaBlocks method createOreBlock.

private static void createOreBlock(DustMaterial material, StoneType[] stoneTypes, int index) {
    BlockOre block = new BlockOre(material, stoneTypes);
    block.setRegistryName("ore_" + material + "_" + index);
    for (StoneType stoneType : stoneTypes) {
        GregTechAPI.oreBlockTable.computeIfAbsent(material, m -> new HashMap<>()).put(stoneType, block);
    }
    ORES.add(block);
}
Also used : java.util(java.util) GraniteVariant(gregtech.common.blocks.BlockGranite.GraniteVariant) Item(net.minecraft.item.Item) MetaTileEntities(gregtech.common.metatileentities.MetaTileEntities) MetaTileEntityRenderer(gregtech.api.render.MetaTileEntityRenderer) Materials(gregtech.api.unification.material.Materials) StoneType(gregtech.api.unification.ore.StoneType) Material(gregtech.api.unification.material.type.Material) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) StoneTypes(gregtech.api.unification.ore.StoneTypes) IProperty(net.minecraft.block.properties.IProperty) GregTechAPI(gregtech.api.GregTechAPI) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) ChiselingVariant(gregtech.common.blocks.StoneBlock.ChiselingVariant) OrePrefix(gregtech.api.unification.ore.OrePrefix) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) ClientProxy(gregtech.common.ClientProxy) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) IBlockState(net.minecraft.block.state.IBlockState) DustMaterial(gregtech.api.unification.material.type.DustMaterial) MineralVariant(gregtech.common.blocks.BlockMineral.MineralVariant) BlockMachine(gregtech.api.block.machines.BlockMachine) StoneType(gregtech.api.unification.ore.StoneType)

Example 15 with Material

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

the class MetaBlocks method createCompressedBlock.

private static void createCompressedBlock(Material[] materials, int index) {
    BlockCompressed block = new BlockCompressed(materials);
    block.setRegistryName("compressed_" + index);
    for (Material material : materials) {
        if (material instanceof DustMaterial)
            COMPRESSED.put((DustMaterial) material, block);
    }
}
Also used : Material(gregtech.api.unification.material.type.Material) DustMaterial(gregtech.api.unification.material.type.DustMaterial) DustMaterial(gregtech.api.unification.material.type.DustMaterial)

Aggregations

Material (gregtech.api.unification.material.type.Material)17 OrePrefix (gregtech.api.unification.ore.OrePrefix)11 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 DustMaterial (gregtech.api.unification.material.type.DustMaterial)5 MarkerMaterial (gregtech.api.unification.material.type.MarkerMaterial)5 java.util (java.util)4 Nullable (javax.annotation.Nullable)4 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)4 ItemStack (net.minecraft.item.ItemStack)4 GregTechAPI (gregtech.api.GregTechAPI)3 Materials (gregtech.api.unification.material.Materials)3 SolidMaterial (gregtech.api.unification.material.type.SolidMaterial)3 SimpleItemStack (gregtech.api.unification.stack.SimpleItemStack)3 IBlockState (net.minecraft.block.state.IBlockState)3 CaseFormat (com.google.common.base.CaseFormat)2 Joiner (com.google.common.base.Joiner)2 ImmutableList (com.google.common.collect.ImmutableList)2 Streams (com.google.common.collect.Streams)2 M (gregtech.api.GTValues.M)2 BlockMachine (gregtech.api.block.machines.BlockMachine)2