Adapted CreativeTabs

This commit is contained in:
Frank 2023-05-24 23:23:03 +02:00
parent 35cea3bcc2
commit 349c82bc00
2 changed files with 79 additions and 6 deletions

View file

@ -61,7 +61,7 @@ public class BetterEnd implements ModInitializer {
.forEach(BetterEndPlugin::register); .forEach(BetterEndPlugin::register);
Integrations.init(); Integrations.init();
Configs.saveConfigs(); Configs.saveConfigs();
CreativeTabs.ensureStaticallyLoaded(); CreativeTabs.register();
if (GeneratorOptions.useNewGenerator()) { if (GeneratorOptions.useNewGenerator()) {
BiomeDecider.registerHighPriorityDecider(makeID("end_land"), new EndLandBiomeDecider()); BiomeDecider.registerHighPriorityDecider(makeID("end_land"), new EndLandBiomeDecider());
@ -78,7 +78,7 @@ public class BetterEnd implements ModInitializer {
EndStructures.addBiomeStructures(biomeID, biome); EndStructures.addBiomeStructures(biomeID, biome);
} }
}); });
//TODO: 1.20 Re-enable when Trinkets is back //TODO: 1.20 Re-enable when Trinkets is back
// if (RUNS_TRINKETS) { // if (RUNS_TRINKETS) {
// org.betterx.betterend.integration.trinkets.Elytra.register(); // org.betterx.betterend.integration.trinkets.Elytra.register();

View file

@ -1,9 +1,17 @@
package org.betterx.betterend.tab; package org.betterx.betterend.tab;
import org.betterx.bclib.behaviours.interfaces.*;
import org.betterx.betterend.BetterEnd; import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.registry.EndBlocks; import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndItems; import org.betterx.betterend.registry.EndItems;
import org.betterx.worlds.together.tag.v3.CommonBlockTags;
import org.betterx.worlds.together.tag.v3.CommonItemTags;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -14,27 +22,92 @@ import java.util.stream.Collectors;
public class CreativeTabs { public class CreativeTabs {
public static final CreativeModeTab TAB_BLOCKS; public static final CreativeModeTab TAB_BLOCKS;
public static final CreativeModeTab TAB_ITEMS; public static final CreativeModeTab TAB_ITEMS;
public static final CreativeModeTab TAB_PLANTS;
public static void ensureStaticallyLoaded() { public static final ResourceKey<CreativeModeTab> TAB_ITEMS_KEY = ResourceKey.create(
// NO-OP Registries.CREATIVE_MODE_TAB,
BetterEnd.makeID("item_tab")
);
public static final ResourceKey<CreativeModeTab> TAB_BLOCKS_KEY = ResourceKey.create(
Registries.CREATIVE_MODE_TAB,
BetterEnd.makeID("block_tab")
);
public static final ResourceKey<CreativeModeTab> TAB_PLANTS_KEY = ResourceKey.create(
Registries.CREATIVE_MODE_TAB,
BetterEnd.makeID("plant_tab")
);
public static void register() {
Registry.register(
BuiltInRegistries.CREATIVE_MODE_TAB,
TAB_ITEMS_KEY,
TAB_ITEMS
);
Registry.register(
BuiltInRegistries.CREATIVE_MODE_TAB,
TAB_BLOCKS_KEY,
TAB_BLOCKS
);
Registry.register(
BuiltInRegistries.CREATIVE_MODE_TAB,
TAB_PLANTS_KEY,
TAB_PLANTS
);
} }
static { static {
TAB_BLOCKS = FabricItemGroup TAB_BLOCKS = FabricItemGroup
.builder(BetterEnd.makeID("end_blocks")) .builder()
.icon(() -> new ItemStack(EndBlocks.END_MYCELIUM)) .icon(() -> new ItemStack(EndBlocks.END_MYCELIUM))
.title(Component.translatable("itemGroup.betterend.blocks"))
.displayItems((featureFlagSet, output) -> output.acceptAll(EndBlocks.getModBlockItems() .displayItems((featureFlagSet, output) -> output.acceptAll(EndBlocks.getModBlockItems()
.stream() .stream()
.map(ItemStack::new) .map(ItemStack::new)
.collect(Collectors.toList()))) .collect(Collectors.toList())))
.build(); .build();
TAB_ITEMS = FabricItemGroup TAB_ITEMS = FabricItemGroup
.builder(BetterEnd.makeID("end_items")) .builder()
.title(Component.translatable("itemGroup.betterend.items"))
.icon(() -> new ItemStack(EndItems.ETERNAL_CRYSTAL)) .icon(() -> new ItemStack(EndItems.ETERNAL_CRYSTAL))
.displayItems((featureFlagSet, output) -> output.acceptAll(EndItems.getModItems() .displayItems((featureFlagSet, output) -> output.acceptAll(EndItems.getModItems()
.stream() .stream()
.map(ItemStack::new) .map(ItemStack::new)
.collect(Collectors.toList()))) .collect(Collectors.toList())))
.build(); .build();
TAB_PLANTS = FabricItemGroup
.builder()
.title(Component.translatable("itemGroup.betterend.plants"))
.icon(() -> new ItemStack(EndBlocks.FILALUX_LANTERN))
.displayItems((featureFlagSet, output) -> {
output.acceptAll(EndItems.getModItems()
.stream()
.map(ItemStack::new)
.filter(s -> s.is(CommonItemTags.COMPOSTABLE)
|| s.is(CommonItemTags.LEAVES)
|| s.is(CommonItemTags.SAPLINGS)
|| s.is(CommonItemTags.SEEDS))
.collect(Collectors.toList()));
output.acceptAll(EndBlocks.getModBlocks()
.stream()
.filter(b -> b instanceof BehaviourVine
|| b instanceof BehaviourLeaves
|| b instanceof BehaviourPlant
|| b instanceof BehaviourWaterPlant
|| b instanceof BehaviourSeed
|| b instanceof BehaviourSapling
|| b instanceof BehaviourCompostable
|| b.defaultBlockState().is(CommonBlockTags.WATER_PLANT)
|| b.defaultBlockState().is(CommonBlockTags.PLANT)
|| b.defaultBlockState().is(CommonBlockTags.SEEDS)
|| b.defaultBlockState().is(CommonBlockTags.SAPLINGS)
|| b.defaultBlockState().is(CommonBlockTags.LEAVES))
.map(ItemStack::new)
.collect(Collectors.toList()));
})
.build();
} }
} }