|
1 | 1 | package com.tcm.MineTale.registry; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
3 | 5 | import java.util.function.Function; |
4 | 6 |
|
5 | 7 | import com.tcm.MineTale.MineTale; |
| 8 | +import com.tcm.MineTale.item.ModCreativeTab; |
6 | 9 |
|
| 10 | +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; |
7 | 11 | import net.minecraft.core.Registry; |
8 | 12 | import net.minecraft.core.registries.BuiltInRegistries; |
9 | 13 | import net.minecraft.core.registries.Registries; |
10 | 14 | import net.minecraft.resources.Identifier; |
11 | 15 | import net.minecraft.resources.ResourceKey; |
| 16 | +import net.minecraft.world.food.FoodProperties; |
12 | 17 | import net.minecraft.world.item.Item; |
13 | 18 |
|
14 | 19 | public class ModItems { |
15 | 20 |
|
| 21 | + private static final List<Item> REGISTERED_ITEMS = new ArrayList<>(); |
| 22 | + |
16 | 23 | public static void initialize() { |
17 | 24 | System.out.println("Registered Mod Items for " + MineTale.MOD_ID); |
| 25 | + ItemGroupEvents.modifyEntriesEvent(ModCreativeTab.MINETALE_CREATIVE_TAB_KEY).register(entries -> { |
| 26 | + REGISTERED_ITEMS.forEach(entries::accept); |
| 27 | + }); |
18 | 28 | } |
| 29 | + |
| 30 | + // --- NATURAL MATERIALS & GATHERABLES --- |
| 31 | + public static final Item PLANT_FIBER = register("plant_fiber", Item::new, new Item.Properties()); |
| 32 | + public static final Item TREE_SAP = register("tree_sap", Item::new, new Item.Properties()); |
| 33 | + public static final Item SAP_GLOB = register("sap_glob", Item::new, new Item.Properties()); |
| 34 | + public static final Item RUBBLE = register("rubble", Item::new, new Item.Properties()); |
| 35 | + public static final Item TREE_BARK = register("tree_bark", Item::new, new Item.Properties()); |
| 36 | + public static final Item MOSS = register("moss", Item::new, new Item.Properties()); |
| 37 | + public static final Item BLUE_CRYSTAL_SHARDS = register("blue_crystal_shards", Item::new, new Item.Properties()); |
| 38 | + public static final Item GREEN_CRYSTAL_SHARDS = register("green_crystal_shards", Item::new, new Item.Properties()); |
| 39 | + public static final Item YELLOW_CRYSTAL_SHARDS = register("yellow_crystal_shards", Item::new, new Item.Properties()); |
| 40 | + |
| 41 | + // --- MINERALS & REFINED METALS (Unique to Hytale) --- |
| 42 | + public static final Item THORIUM_INGOT = register("thorium_ingot", Item::new, new Item.Properties()); |
| 43 | + public static final Item COBALT_INGOT = register("cobalt_ingot", Item::new, new Item.Properties()); |
| 44 | + public static final Item ADAMANTITE_INGOT = register("adamantite_ingot", Item::new, new Item.Properties()); |
| 45 | + public static final Item MITHRIL_INGOT = register("mithril_ingot", Item::new, new Item.Properties()); |
| 46 | + public static final Item BRONZE_INGOT = register("bronze_ingot", Item::new, new Item.Properties()); |
| 47 | + public static final Item STEEL_INGOT = register("steel_ingot", Item::new, new Item.Properties()); |
| 48 | + |
| 49 | + // --- MOB DROPS, HIDES & LEATHERS --- |
| 50 | + public static final Item LIGHT_HIDE = register("light_hide", Item::new, new Item.Properties()); |
| 51 | + public static final Item MEDIUM_HIDE = register("medium_hide", Item::new, new Item.Properties()); |
| 52 | + public static final Item HEAVY_HIDE = register("heavy_hide", Item::new, new Item.Properties()); |
| 53 | + public static final Item SOFT_HIDE = register("soft_hide", Item::new, new Item.Properties()); |
| 54 | + public static final Item PRISMATIC_HIDE = register("prismatic_hide", Item::new, new Item.Properties()); |
| 55 | + |
| 56 | + public static final Item LIGHT_LEATHER = register("light_leather", Item::new, new Item.Properties()); |
| 57 | + public static final Item MEDIUM_LEATHER = register("medium_leather", Item::new, new Item.Properties()); |
| 58 | + public static final Item HEAVY_LEATHER = register("heavy_leather", Item::new, new Item.Properties()); |
| 59 | + public static final Item STORM_LEATHER = register("storm_leather", Item::new, new Item.Properties()); |
| 60 | + public static final Item PRISMATIC_LEATHER = register("prismatic_leather", Item::new, new Item.Properties()); |
19 | 61 |
|
| 62 | + public static final Item FERAN_RIB = register("feran_rib", Item::new, new Item.Properties()); |
| 63 | + public static final Item STURDY_CHITIN = register("sturdy_chitin", Item::new, new Item.Properties()); |
| 64 | + public static final Item VENOM_SAC = register("venom_sac", Item::new, new Item.Properties()); |
| 65 | + public static final Item BONE_FRAGMENT = register("bone_fragment", Item::new, new Item.Properties()); |
| 66 | + |
| 67 | + // --- FABRICS & TEXTILES --- |
| 68 | + public static final Item LINEN_SCRAPS = register("linen_scraps", Item::new, new Item.Properties()); |
| 69 | + public static final Item BOLT_OF_LINEN = register("bolt_of_linen", Item::new, new Item.Properties()); |
| 70 | + public static final Item SHADOWEAVE_SCRAPS = register("shadoweave_scraps", Item::new, new Item.Properties()); |
| 71 | + public static final Item CINDERCLOTH_SCRAPS = register("cindercloth_scraps", Item::new, new Item.Properties()); |
| 72 | + public static final Item BOLT_OF_WOOL = register("bolt_of_wool", Item::new, new Item.Properties()); |
| 73 | + public static final Item YELLOW_CLOTH = register("yellow_cloth", Item::new, new Item.Properties()); |
| 74 | + |
| 75 | + // --- SEEDS & FARMING (Bags and Bulbs) --- |
| 76 | + public static final Item LETTUCE = register("lettuce", Item::new, new Item.Properties().food( |
| 77 | + new FoodProperties.Builder().nutrition(2).saturationModifier(0.3f).build() |
| 78 | + )); |
| 79 | + public static final Item CHILLI_SEED_BAG = register("chilli_seed_bag", Item::new, new Item.Properties()); |
| 80 | + public static final Item CHILLI_SEED_BAG_ETERNAL = register("chilli_seed_bag_eternal", Item::new, new Item.Properties()); |
| 81 | + public static final Item SUNFLOWER_SEED_BAG = register("sunflower_seed_bag", Item::new, new Item.Properties()); |
| 82 | + public static final Item CORN_SEED_BAG = register("corn_seed_bag", Item::new, new Item.Properties()); |
| 83 | + public static final Item COTTON_SEED_BAG = register("cotton_seed_bag", Item::new, new Item.Properties()); |
| 84 | + public static final Item RICE_SEED_BAG = register("rice_seed_bag", Item::new, new Item.Properties()); |
| 85 | + public static final Item ONION_BULB = register("onion_bulb", Item::new, new Item.Properties()); |
| 86 | + |
| 87 | + // --- MAGICAL & ALCHEMICAL --- |
| 88 | + public static final Item ESSENCE_OF_LIFE = register("essence_of_life", Item::new, new Item.Properties()); |
| 89 | + public static final Item ESSENCE_OF_FIRE = register("essence_of_fire", Item::new, new Item.Properties()); |
| 90 | + public static final Item ESSENCE_OF_ICE = register("essence_of_ice", Item::new, new Item.Properties()); |
| 91 | + public static final Item ESSENCE_OF_THE_VOID = register("essence_of_the_void", Item::new, new Item.Properties()); |
| 92 | + public static final Item VOID_HEART = register("void_heart", Item::new, new Item.Properties()); |
| 93 | + |
| 94 | + // --- FLORA COMPONENTS (Non-placeable petals) --- |
| 95 | + public static final Item RED_PETALS = register("red_petals", Item::new, new Item.Properties()); |
| 96 | + public static final Item YELLOW_PETALS = register("yellow_petals", Item::new, new Item.Properties()); |
| 97 | + public static final Item GREEN_PETALS = register("green_petals", Item::new, new Item.Properties()); |
| 98 | + public static final Item WHITE_PETALS = register("white_petals", Item::new, new Item.Properties()); |
| 99 | + public static final Item AZURE_PETALS = register("azure_petals", Item::new, new Item.Properties()); |
| 100 | + public static final Item STORM_PETALS = register("storm_petals", Item::new, new Item.Properties()); |
| 101 | + public static final Item BLOOD_PETALS = register("blood_petals", Item::new, new Item.Properties()); |
| 102 | + public static final Item CYAN_PETALS = register("cyan_petals", Item::new, new Item.Properties()); |
| 103 | + |
| 104 | + // --- REGISTRATION LOGIC --- |
20 | 105 | public static <GenericItem extends Item> GenericItem register(String name, Function<Item.Properties, GenericItem> itemFactory, Item.Properties settings) { |
21 | | - // Create the item key. |
22 | 106 | ResourceKey<Item> itemKey = ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(MineTale.MOD_ID, name)); |
23 | | - |
24 | | - // Create the item instance. |
25 | 107 | GenericItem item = itemFactory.apply(settings.setId(itemKey)); |
26 | | - |
27 | | - // Register the item. |
28 | 108 | Registry.register(BuiltInRegistries.ITEM, itemKey, item); |
29 | 109 |
|
| 110 | + // 4. ADD TO CREATIVE TAB AUTOMATICALLY |
| 111 | + REGISTERED_ITEMS.add(item); |
| 112 | + |
30 | 113 | return item; |
31 | 114 | } |
32 | 115 | } |
0 commit comments