All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yungnickyoung.minecraft.yungsapi.module.CreativeModeTabModuleFabric Maven / Gradle / Ivy

The newest version!
package com.yungnickyoung.minecraft.yungsapi.module;

import com.yungnickyoung.minecraft.yungsapi.api.autoregister.AutoRegisterCreativeTab;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegisterField;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegistrationManager;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.class_1761;
import net.minecraft.class_2378;
import net.minecraft.class_7923;

/**
 * Initialization of creative mode tabs.
 */
public class CreativeModeTabModuleFabric {
    public static void processEntries() {
        AutoRegistrationManager.CREATIVE_MODE_TABS.stream()
                .filter(data -> !data.processed())
                .forEach(CreativeModeTabModuleFabric::initialize);
    }

    private static void initialize(AutoRegisterField data) {
        // Extract data
        AutoRegisterCreativeTab autoRegisterCreativeTab = (AutoRegisterCreativeTab) data.object();

        // Create tab
        class_1761.class_7913 creativeModeTabBuilder = FabricItemGroup.builder()
                .method_47321(autoRegisterCreativeTab.getDisplayName())
                .method_47320(autoRegisterCreativeTab.getIconItemStackSupplier())
                .method_47317(autoRegisterCreativeTab.getDisplayItemsGenerator())
                .method_47319(autoRegisterCreativeTab.getBackgroundTexture());
        if (!autoRegisterCreativeTab.canScroll()) {
            creativeModeTabBuilder.method_47323();
        }
        if (!autoRegisterCreativeTab.showTitle()) {
            creativeModeTabBuilder.method_47322();
        }
        if (autoRegisterCreativeTab.alignedRight()) {
            creativeModeTabBuilder.method_47315();
        }

        class_1761 creativeModeTab = creativeModeTabBuilder.method_47324();

        // Register tab
        class_2378.method_10230(class_7923.field_44687, data.name(), creativeModeTab);

        // Update supplier to retrieve tab
        autoRegisterCreativeTab.setSupplier(() -> creativeModeTab);

        data.markProcessed();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy