Skip to content

Commit

Permalink
fix: creative tab now works
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaTheDinkus committed Aug 26, 2023
1 parent 8e5df75 commit 8452a76
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/github/mixinors/astromine/AMCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void onInitialize() {
AMWorlds.init();
AMFeatures.init();
AMStructureTypes.init();
AMItemGroups.init();
AMItems.init();
AMBlocks.init();
AMScreenHandlers.init();
Expand All @@ -86,7 +87,6 @@ public void onInitialize() {
AMCriteria.init();
AMToolMaterials.init();
AMOres.init();
AMItemGroups.init();
AMNetworking.init();
AMLookups.init();
AMBodies.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.github.mixinors.astromine.common.block.storage.TankBlock;
import com.github.mixinors.astromine.common.block.utility.*;
import dev.architectury.registry.registries.RegistrySupplier;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.item.BlockItem;
Expand Down Expand Up @@ -358,12 +359,13 @@ public static <T extends Block> RegistrySupplier<T> register(String name, Suppli
public static <T extends Block> RegistrySupplier<T> register(String name, Supplier<T> block, Function<T, BlockItem> item) {
var b = register(AMCommon.id(name), block);
if (item != null) {
AMCommon.registry(RegistryKeys.ITEM).register(b.getId(), () -> {
var t = b.get();
var blockItem = item.apply(t);
var t = b.get();
var blockItem = item.apply(t);
var newItem = AMCommon.registry(RegistryKeys.ITEM).register(b.getId(), () -> {
Item.BLOCK_ITEMS.put(t, blockItem);
return blockItem;
});
AMItemGroups.addToDefault(newItem.get());
}
return b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,38 @@

package com.github.mixinors.astromine.registry.common;

import com.github.mixinors.astromine.AMCommon;
import dev.architectury.registry.CreativeTabRegistry;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;

import java.util.function.Supplier;

public class AMItemGroups {
public static final ItemGroup ASTROMINE = register("astromine", AMItems.ITEM);
public static final RegistryKey<ItemGroup> ASTROMINE_KEY = RegistryKey.of(RegistryKeys.ITEM_GROUP, AMCommon.id("astromine"));
public static final ItemGroup ASTROMINE = register(ASTROMINE_KEY, CreativeTabRegistry.create(Text.of("itemGroup.astromine.general"), () -> new ItemStack(AMItems.ITEM.get())));

public static void init() {
}

public static ItemGroup register(String id, Supplier<? extends ItemConvertible> icon) {
return CreativeTabRegistry.create(Text.of("itemGroup.astromine." + id), () -> new ItemStack(icon.get()));
public static void addToItemGroup(RegistryKey<ItemGroup> group, Item item) {
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
}

public static void addToDefault(Item item) {
ItemGroupEvents.modifyEntriesEvent(ASTROMINE_KEY).register(entries -> entries.add(item));
}

public static ItemGroup register(RegistryKey<ItemGroup> key, ItemGroup itemGroup) {
return Registry.register(Registries.ITEM_GROUP, key, itemGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.github.mixinors.astromine.common.rocket.RocketThrusterPart;
import com.github.mixinors.astromine.common.util.data.tier.Tier;
import dev.architectury.registry.registries.RegistrySupplier;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.*;
Expand All @@ -55,9 +56,9 @@
import java.util.function.Supplier;

public class AMItems {
public static final RegistrySupplier<Item> ENERGY = register("energy", () -> new Item(new Item.Settings()));
public static final RegistrySupplier<Item> FLUID = register("fluid", () -> new Item(new Item.Settings()));
public static final RegistrySupplier<Item> ITEM = register("item", () -> new Item(new Item.Settings()));
public static final RegistrySupplier<Item> ENERGY = registerNoGroup("energy", () -> new Item(new Item.Settings()));
public static final RegistrySupplier<Item> FLUID = registerNoGroup("fluid", () -> new Item(new Item.Settings()));
public static final RegistrySupplier<Item> ITEM = registerNoGroup("item", () -> new Item(new Item.Settings()));

public static final RegistrySupplier<Item> MANUAL = register("manual", () -> new ManualItem(getSettings().maxCount(1)));

Expand Down Expand Up @@ -462,6 +463,29 @@ public static <T extends Item> RegistrySupplier<T> register(String name, Supplie
* @return Item instance registered
*/
public static <T extends Item> RegistrySupplier<T> register(Identifier name, Supplier<T> item) {
RegistrySupplier<T> i = AMCommon.registry(RegistryKeys.ITEM).register(name, item);
AMItemGroups.addToDefault(i.get());

return i;
}

/**
* @param name Name of item instance to be registered
* @param item Item instance to be registered
*
* @return Item instance registered
*/
public static <T extends Item> RegistrySupplier<T> registerNoGroup(String name, Supplier<T> item) {
return registerNoGroup(AMCommon.id(name), item);
}

/**
* @param name Identifier of item instance to be registered
* @param item Item instance to be registered
*
* @return Item instance registered
*/
public static <T extends Item> RegistrySupplier<T> registerNoGroup(Identifier name, Supplier<T> item) {
return AMCommon.registry(RegistryKeys.ITEM).register(name, item);
}

Expand Down

0 comments on commit 8452a76

Please sign in to comment.