Skip to content

Commit

Permalink
Dynamically generate creative scroll tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotgiggle committed Dec 22, 2024
1 parent 0c37d15 commit 658a06c
Showing 1 changed file with 21 additions and 44 deletions.
65 changes: 21 additions & 44 deletions Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.petrak.hexcasting.common.lib;

import at.petrak.hexcasting.api.misc.MediaConstants;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.common.items.ItemJewelerHammer;
import at.petrak.hexcasting.common.items.ItemLens;
import at.petrak.hexcasting.common.items.ItemLoreFragment;
Expand All @@ -14,6 +17,8 @@
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.common.base.Suppliers;
import net.minecraft.Util;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.food.FoodProperties;
Expand All @@ -35,6 +40,7 @@ public static void registerItems(BiConsumer<Item, ResourceLocation> r) {
}

public static void registerItemCreativeTab(CreativeModeTab.Output r, CreativeModeTab tab) {
if (tab == HexCreativeTabs.SCROLLS) generateScrollEntries();
for (var item : ITEM_TABS.getOrDefault(tab, List.of())) {
item.register(r);
}
Expand Down Expand Up @@ -112,50 +118,6 @@ public static void registerItemCreativeTab(CreativeModeTab.Output r, CreativeMod
MediaConstants.QUENCHED_BLOCK_UNIT * 64,
MediaConstants.QUENCHED_BLOCK_UNIT * 64), HexCreativeTabs.MAIN);

public static final Supplier<ItemStack> SCROLL_LIGHTNING = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:lightning"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_FLIGHT = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:flight"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_CREATE_LAVA = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:create_lava"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_GREATER_TELEPORT = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:teleport/great"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_GREATER_SENTINEL = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:sentinel/create/great"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_DISPEL_RAIN = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:dispel_rain"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_SUMMON_RAIN = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:summon_rain"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_FLAY_MIND = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:brainsweep"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_CRAFT_PHIAL = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:craft/battery"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_WHITE_ZENITH = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:potion/regeneration"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_BLUE_ZENITH = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:potion/night_vision"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_BLACK_ZENITH = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:potion/absorption"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_RED_ZENITH = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:potion/haste"), HexCreativeTabs.SCROLLS);
public static final Supplier<ItemStack> SCROLL_GREEN_ZENITH = addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
"hexcasting:potion/strength"), HexCreativeTabs.SCROLLS);


public static final EnumMap<DyeColor, ItemDyePigment> DYE_PIGMENTS = Util.make(() -> {
var out = new EnumMap<DyeColor, ItemDyePigment>(DyeColor.class);
for (var dye : DyeColor.values()) {
Expand Down Expand Up @@ -199,6 +161,21 @@ public static Item.Properties unstackable() {
return props().stacksTo(1);
}

private static void generateScrollEntries() {
var keyList = new ArrayList<ResourceKey<ActionRegistryEntry>>();
Registry<ActionRegistryEntry> regi = IXplatAbstractions.INSTANCE.getActionRegistry();
for (var key : regi.registryKeySet())
if (HexUtils.isOfTag(regi, key, HexTags.Actions.PER_WORLD_PATTERN))
keyList.add(key);
keyList.sort( (a, b) -> a.location().compareTo(b.location()) );
for (var key : keyList) {
addToTab(() -> ItemScroll.withPerWorldPattern(
new ItemStack(HexItems.SCROLL_LARGE),
key.location().toString()
),HexCreativeTabs.SCROLLS);
}
}

private static <T extends Item> T make(ResourceLocation id, T item, @Nullable CreativeModeTab tab) {
var old = ITEMS.put(id, item);
if (old != null) {
Expand Down

0 comments on commit 658a06c

Please sign in to comment.