package thetadev.constructionwand.items; import net.minecraft.client.Minecraft; import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.Tiers; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.RegistryObject; import thetadev.constructionwand.ConstructionWand; import thetadev.constructionwand.basics.option.WandOptions; import thetadev.constructionwand.crafting.RecipeWandUpgrade; import thetadev.constructionwand.items.core.ItemCoreAngel; import thetadev.constructionwand.items.core.ItemCoreDestruction; import thetadev.constructionwand.items.wand.ItemWand; import thetadev.constructionwand.items.wand.ItemWandBasic; import thetadev.constructionwand.items.wand.ItemWandInfinity; @Mod.EventBusSubscriber(modid = ConstructionWand.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModItems { public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ConstructionWand.MODID); // Wands public static final RegistryObject WAND_STONE = ITEMS.register("stone_wand", () -> new ItemWandBasic(propWand(), Tiers.STONE)); public static final RegistryObject WAND_IRON = ITEMS.register("iron_wand", () -> new ItemWandBasic(propWand(), Tiers.IRON)); public static final RegistryObject WAND_DIAMOND = ITEMS.register("diamond_wand", () -> new ItemWandBasic(propWand(), Tiers.DIAMOND)); public static final RegistryObject WAND_INFINITY = ITEMS.register("infinity_wand", () -> new ItemWandInfinity(propWand())); // Cores public static final RegistryObject CORE_ANGEL = ITEMS.register("core_angel", () -> new ItemCoreAngel(propUpgrade())); public static final RegistryObject CORE_DESTRUCTION = ITEMS.register("core_destruction", () -> new ItemCoreDestruction(propUpgrade())); // Collections public static final RegistryObject[] WANDS = new RegistryObject[] {WAND_STONE, WAND_IRON, WAND_DIAMOND, WAND_INFINITY}; public static final RegistryObject[] CORES = new RegistryObject[] {CORE_ANGEL, CORE_DESTRUCTION}; public static Item.Properties propWand() { return new Item.Properties().tab(CreativeModeTab.TAB_TOOLS); } private static Item.Properties propUpgrade() { return new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(1); } @SubscribeEvent public static void registerRecipeSerializers(RegistryEvent.Register> event) { IForgeRegistry> r = event.getRegistry(); register(r, "wand_upgrade", RecipeWandUpgrade.SERIALIZER); } @OnlyIn(Dist.CLIENT) public static void registerModelProperties() { for(RegistryObject itemSupplier : WANDS) { Item item = itemSupplier.get(); ItemProperties.register( item, ConstructionWand.loc("using_core"), (stack, world, entity, n) -> entity == null || !(stack.getItem() instanceof ItemWand) ? 0 : new WandOptions(stack).cores.get().getColor() > -1 ? 1 : 0 ); } } @OnlyIn(Dist.CLIENT) public static void registerItemColors() { ItemColors colors = Minecraft.getInstance().getItemColors(); for(RegistryObject itemSupplier : WANDS) { Item item = itemSupplier.get(); colors.register((stack, layer) -> (layer == 1 && stack.getItem() instanceof ItemWand) ? new WandOptions(stack).cores.get().getColor() : -1, item); } } private static > void register(IForgeRegistry reg, String name, IForgeRegistryEntry thing) { reg.register(thing.setRegistryName(ConstructionWand.loc(name))); } }