com.yungnickyoung.minecraft.yungsapi.module.CreativeModeTabModuleNeoForge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of YungsApi Show documentation
Show all versions of YungsApi Show documentation
A common API for YUNG's Minecraft mods
The newest version!
package com.yungnickyoung.minecraft.yungsapi.module;
import com.yungnickyoung.minecraft.yungsapi.YungsApiNeoForge;
import com.yungnickyoung.minecraft.yungsapi.api.autoregister.AutoRegisterCreativeTab;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegisterField;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegistrationManager;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.CreativeModeTab;
import net.neoforged.neoforge.registries.RegisterEvent;
/**
* Initialization of creative mode tabs.
*/
public class CreativeModeTabModuleNeoForge {
public static void processEntries() {
YungsApiNeoForge.loadingContextEventBus.addListener(YungsApiNeoForge.buildAutoRegistrar(Registries.CREATIVE_MODE_TAB, AutoRegistrationManager.CREATIVE_MODE_TABS, CreativeModeTabModuleNeoForge::buildCreativeTab));
}
private static CreativeModeTab buildCreativeTab(AutoRegisterField data) {
// Extract data
AutoRegisterCreativeTab autoRegisterCreativeTab = (AutoRegisterCreativeTab) data.object();
// Create tab
CreativeModeTab.Builder creativeModeTabBuilder = CreativeModeTab.builder()
.title(autoRegisterCreativeTab.getDisplayName())
.icon(autoRegisterCreativeTab.getIconItemStackSupplier())
.displayItems(autoRegisterCreativeTab.getDisplayItemsGenerator())
.backgroundTexture(autoRegisterCreativeTab.getBackgroundTexture());
if (!autoRegisterCreativeTab.canScroll()) {
creativeModeTabBuilder.noScrollBar();
}
if (!autoRegisterCreativeTab.showTitle()) {
creativeModeTabBuilder.hideTitle();
}
if (autoRegisterCreativeTab.alignedRight()) {
creativeModeTabBuilder.alignedRight();
}
CreativeModeTab creativeModeTab = creativeModeTabBuilder.build();
// Update supplier to retrieve tab
autoRegisterCreativeTab.setSupplier(() -> creativeModeTab);
// Return for registering
return creativeModeTab;
}
}