Search in sources :

Example 66 with Material

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

the class MetaFluids method registerFluid.

@Nonnull
public static Fluid registerFluid(@Nonnull Material material, @Nonnull FluidType fluidType, int temperature, boolean generateBlock) {
    String materialName = material.toString();
    String fluidName = fluidType.getNameForMaterial(material);
    Fluid fluid = FluidRegistry.getFluid(fluidName);
    // check if fluid is registered from elsewhere under an alternative name
    if (fluid == null && alternativeFluidNames.containsKey(fluidName)) {
        String altName = alternativeFluidNames.get(fluidName);
        fluid = FluidRegistry.getFluid(altName);
    }
    // if the material is still not registered by this point, register it
    if (fluid == null) {
        // determine texture for use
        ResourceLocation textureLocation = fluidTextureMap.computeIfAbsent(material, key -> {
            Map<FluidType, ResourceLocation> map = new Object2ObjectOpenHashMap<>();
            if (fluidType.equals(FluidTypes.PLASMA))
                map.put(fluidType, AUTO_GENERATED_PLASMA_TEXTURE);
            else
                map.put(fluidType, MaterialIconType.fluid.getBlockPath(material.getMaterialIconSet()));
            return map;
        }).computeIfAbsent(fluidType, key -> {
            Map<FluidType, ResourceLocation> map = fluidTextureMap.get(material);
            if (fluidType.equals(FluidTypes.PLASMA))
                map.put(fluidType, AUTO_GENERATED_PLASMA_TEXTURE);
            else
                map.put(fluidType, MaterialIconType.fluid.getBlockPath(material.getMaterialIconSet()));
            return map.get(fluidType);
        });
        // create the new fluid
        fluid = new MaterialFluid(fluidName, material, fluidType, textureLocation);
        fluid.setTemperature(temperature);
        if (material.hasFluidColor())
            fluid.setColor(GTUtility.convertRGBtoOpaqueRGBA_MC(material.getMaterialRGB()));
        else
            fluid.setColor(0xFFFFFFFF);
        // set properties and register
        FluidType.setFluidProperties(fluidType, fluid);
        ((MaterialFluid) fluid).registerFluidTooltip();
        FluidRegistry.registerFluid(fluid);
    }
    // add buckets for each fluid
    FluidRegistry.addBucketForFluid(fluid);
    // generate fluid blocks if the material has one, and the current state being handled is not plasma
    if (generateBlock && fluid.getBlock() == null && fluidType != FluidTypes.PLASMA) {
        BlockFluidBase fluidBlock = new BlockFluidClassic(fluid, net.minecraft.block.material.Material.WATER);
        fluidBlock.setRegistryName("fluid." + materialName);
        MetaBlocks.FLUID_BLOCKS.add(fluidBlock);
    }
    fluidToMaterialMappings.put(fluid.getName(), material);
    return fluid;
}
Also used : MaterialIconType(gregtech.api.unification.material.info.MaterialIconType) BlockFluidClassic(net.minecraftforge.fluids.BlockFluidClassic) FluidProperty(gregtech.api.unification.material.properties.FluidProperty) MetaBlocks(gregtech.common.blocks.MetaBlocks) MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) Materials(gregtech.api.unification.material.Materials) PlasmaProperty(gregtech.api.unification.material.properties.PlasmaProperty) ArrayList(java.util.ArrayList) LocalizationUtils(gregtech.api.util.LocalizationUtils) GregTechAPI(gregtech.api.GregTechAPI) FluidType(gregtech.api.fluids.fluidType.FluidType) FluidTooltipUtil(gregtech.api.util.FluidTooltipUtil) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) Fluid(net.minecraftforge.fluids.Fluid) Material(gregtech.api.unification.material.Material) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) FluidTypes(gregtech.api.fluids.fluidType.FluidTypes) TextFormatting(net.minecraft.util.text.TextFormatting) PropertyKey(gregtech.api.unification.material.properties.PropertyKey) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Set(java.util.Set) List(java.util.List) GTValues(gregtech.api.GTValues) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) ResourceLocation(net.minecraft.util.ResourceLocation) GTUtility(gregtech.api.util.GTUtility) FluidType(gregtech.api.fluids.fluidType.FluidType) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) BlockFluidClassic(net.minecraftforge.fluids.BlockFluidClassic) Fluid(net.minecraftforge.fluids.Fluid) ResourceLocation(net.minecraft.util.ResourceLocation) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Nonnull(javax.annotation.Nonnull)

Example 67 with Material

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

the class BlockMaterialPipe method createProperties.

@Override
public NodeDataType createProperties(IPipeTile<PipeType, NodeDataType> pipeTile) {
    PipeType pipeType = pipeTile.getPipeType();
    Material material = ((IMaterialPipeTile<PipeType, NodeDataType>) pipeTile).getPipeMaterial();
    if (pipeType == null || material == null) {
        return getFallbackType();
    }
    return createProperties(pipeType, material);
}
Also used : IPipeType(gregtech.api.pipenet.block.IPipeType) Material(gregtech.api.unification.material.Material)

Example 68 with Material

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

the class OreDictUnifier method onItemRegistration.

@SubscribeEvent
public static void onItemRegistration(OreRegisterEvent event) {
    ItemAndMetadata simpleItemStack = new ItemAndMetadata(event.getOre());
    String oreName = event.getName();
    // cache this registration by name
    stackOreDictName.computeIfAbsent(simpleItemStack, k -> new HashSet<>()).add(oreName);
    List<ItemStack> itemStackListForOreDictName = oreDictNameStacks.computeIfAbsent(oreName, k -> new ArrayList<>());
    addAndSort(itemStackListForOreDictName, event.getOre().copy(), getItemStackComparator());
    // 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 = GTUtility.toLowerCaseUnderscore(possibleMaterialName);
            // Materials.BasalticSand
            Material possibleMaterial = GregTechAPI.MATERIAL_REGISTRY.getObject(underscoreName);
            if (possibleMaterial == null) {
                // if we didn't found real material, try using marker material registry
                possibleMaterial = markerMaterialRegistry.get(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);
        ArrayList<ItemAndMetadata> itemListForUnifiedEntry = stackUnificationItems.computeIfAbsent(unificationEntry, p -> new ArrayList<>());
        addAndSort(itemListForUnifiedEntry, simpleItemStack, getSimpleItemStackComparator());
        if (!unificationEntry.orePrefix.isMarkerPrefix()) {
            stackUnificationInfo.put(simpleItemStack, unificationEntry);
        }
        orePrefix.processOreRegistration(material);
    }
}
Also used : java.util(java.util) M(gregtech.api.GTValues.M) Function(java.util.function.Function) ConfigHolder(gregtech.common.ConfigHolder) ItemStack(net.minecraft.item.ItemStack) GregTechAPI(gregtech.api.GregTechAPI) Block(net.minecraft.block.Block) OreDictionary(net.minecraftforge.oredict.OreDictionary) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Material(gregtech.api.unification.material.Material) OrePrefix(gregtech.api.unification.ore.OrePrefix) NonNullList(net.minecraft.util.NonNullList) SimpleEntry(java.util.AbstractMap.SimpleEntry) Nullable(javax.annotation.Nullable) OreRegisterEvent(net.minecraftforge.oredict.OreDictionary.OreRegisterEvent) gregtech.api.unification.stack(gregtech.api.unification.stack) CaseFormat(com.google.common.base.CaseFormat) PropertyKey(gregtech.api.unification.material.properties.PropertyKey) Collectors(java.util.stream.Collectors) CustomModPriorityComparator(gregtech.api.util.CustomModPriorityComparator) MinecraftForge(net.minecraftforge.common.MinecraftForge) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) Entry(java.util.Map.Entry) GTUtility(gregtech.api.util.GTUtility) Joiner(com.google.common.base.Joiner) OrePrefix(gregtech.api.unification.ore.OrePrefix) Material(gregtech.api.unification.material.Material) MarkerMaterial(gregtech.api.unification.material.MarkerMaterial) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 69 with Material

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

the class CableRenderer method getParticleTexture.

@Override
public Pair<TextureAtlasSprite, Integer> getParticleTexture(IPipeTile<?, ?> pipeTile) {
    if (pipeTile == null) {
        return Pair.of(TextureUtils.getMissingSprite(), 0xFFFFFF);
    }
    IPipeType<?> pipeType = pipeTile.getPipeType();
    if (!(pipeType instanceof Insulation)) {
        return Pair.of(TextureUtils.getMissingSprite(), 0xFFFFFF);
    }
    Material material = pipeTile instanceof TileEntityMaterialPipeBase ? ((TileEntityMaterialPipeBase<?, ?>) pipeTile).getPipeMaterial() : null;
    TextureAtlasSprite atlasSprite;
    int particleColor;
    int insulationLevel = ((Insulation) pipeType).insulationLevel;
    if (insulationLevel == -1) {
        atlasSprite = wireTexture;
        particleColor = material == null ? 0xFFFFFF : material.getMaterialRGB();
    } else {
        atlasSprite = insulationTextures[5];
        particleColor = pipeTile.getPaintingColor();
    }
    return Pair.of(atlasSprite, particleColor);
}
Also used : Insulation(gregtech.common.pipelike.cable.Insulation) TileEntityMaterialPipeBase(gregtech.api.pipenet.block.material.TileEntityMaterialPipeBase) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Material(gregtech.api.unification.material.Material)

Example 70 with Material

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

the class CompressedBlockBakedModel 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(((BlockCompressed) 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.block.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
        }
        quads.add(materialFaceQuad);
        particle.set(materialFaceQuad.getSprite());
    } else {
        ItemStack stack = CompressedBlockItemOverride.INSTANCE.stack.get();
        if (!stack.isEmpty()) {
            BlockCompressed compressed = (BlockCompressed) ((ItemBlock) stack.getItem()).getBlock();
            IBlockState compressedState = compressed.getDefaultState().withProperty(compressed.variantProperty, compressed.variantProperty.getAllowedValues().get(stack.getMetadata()));
            for (EnumFacing face : EnumFacing.VALUES) {
                quads.addAll(getQuads(compressedState, face, rand));
            }
        }
    }
    return quads;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCompressed(gregtech.common.blocks.BlockCompressed) 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) 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