Search in sources :

Example 1 with FluidType

use of gregtech.api.fluids.fluidType.FluidType in project GregTech by GregTechCEu.

the class MaterialPropertyExpansion method addFluid.

@ZenMethod
public static void addFluid(Material m, @Optional FluidType fluidType, @Optional boolean hasBlock) {
    if (checkFrozen("add a Fluid to a material"))
        return;
    FluidType type = validateFluidTypeNoPlasma(fluidType == null ? null : fluidType.getName());
    if (m.hasProperty(PropertyKey.FLUID)) {
        m.getProperty(PropertyKey.FLUID).setIsGas(type == FluidTypes.GAS);
        m.getProperty(PropertyKey.FLUID).setHasBlock(hasBlock);
    } else
        m.setProperty(PropertyKey.FLUID, new FluidProperty(type, hasBlock));
}
Also used : FluidType(gregtech.api.fluids.fluidType.FluidType) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 2 with FluidType

use of gregtech.api.fluids.fluidType.FluidType in project GregTech by GregTechCEu.

the class MaterialPropertyExpansion method addFluid.

@ZenMethod
public static void addFluid(Material m, @Optional String fluidTypeName, @Optional boolean hasBlock) {
    if (checkFrozen("add a Fluid to a material"))
        return;
    FluidType type = validateFluidTypeNoPlasma(fluidTypeName);
    if (m.hasProperty(PropertyKey.FLUID)) {
        m.getProperty(PropertyKey.FLUID).setIsGas(type == FluidTypes.GAS);
        m.getProperty(PropertyKey.FLUID).setHasBlock(hasBlock);
    } else
        m.setProperty(PropertyKey.FLUID, new FluidProperty(type, hasBlock));
}
Also used : FluidType(gregtech.api.fluids.fluidType.FluidType) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 3 with FluidType

use of gregtech.api.fluids.fluidType.FluidType 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)

Aggregations

FluidType (gregtech.api.fluids.fluidType.FluidType)3 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)2 GTValues (gregtech.api.GTValues)1 GregTechAPI (gregtech.api.GregTechAPI)1 FluidTypes (gregtech.api.fluids.fluidType.FluidTypes)1 Material (gregtech.api.unification.material.Material)1 Materials (gregtech.api.unification.material.Materials)1 MaterialIconSet (gregtech.api.unification.material.info.MaterialIconSet)1 MaterialIconType (gregtech.api.unification.material.info.MaterialIconType)1 FluidProperty (gregtech.api.unification.material.properties.FluidProperty)1 PlasmaProperty (gregtech.api.unification.material.properties.PlasmaProperty)1 PropertyKey (gregtech.api.unification.material.properties.PropertyKey)1 FluidTooltipUtil (gregtech.api.util.FluidTooltipUtil)1 GTUtility (gregtech.api.util.GTUtility)1 LocalizationUtils (gregtech.api.util.LocalizationUtils)1 MetaBlocks (gregtech.common.blocks.MetaBlocks)1 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)1 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1