From e6530a50966c2cc3501bef6ab5947c0ea53481c0 Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Sat, 3 Aug 2024 12:15:49 +0200 Subject: [PATCH] fix: possible workaround for shift-crafting not calling onCraftedBy Closes #1179 --- .../item/spirit/BookOfBindingBoundItem.java | 20 ++++++++++++- .../occultism/registry/OccultismItems.java | 29 ++++++++++--------- .../occultism/util/ItemNBTUtil.java | 9 ++++++ .../klikli_dev/occultism/util/TextUtil.java | 1 + 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/klikli_dev/occultism/common/item/spirit/BookOfBindingBoundItem.java b/src/main/java/com/klikli_dev/occultism/common/item/spirit/BookOfBindingBoundItem.java index 06ac34770..6ee468970 100644 --- a/src/main/java/com/klikli_dev/occultism/common/item/spirit/BookOfBindingBoundItem.java +++ b/src/main/java/com/klikli_dev/occultism/common/item/spirit/BookOfBindingBoundItem.java @@ -30,6 +30,10 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.fml.LogicalSide; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.fml.util.thread.EffectiveSide; import javax.annotation.Nullable; import java.util.List; @@ -49,9 +53,23 @@ public void appendHoverText(ItemStack pStack, TooltipContext pContext, List new Item(defaultProperties())); public static final DeferredItem TABOO_BOOK = ITEMS.register("taboo_book", () -> new Item(defaultProperties())); + //Books of Binding public static final DeferredItem BOOK_OF_BINDING_EMPTY = ITEMS.register( "book_of_binding_empty", () -> new BookOfBindingItem(defaultProperties().stacksTo(1))); public static final DeferredItem BOOK_OF_BINDING_FOLIOT = ITEMS.register( "book_of_binding_foliot", () -> new BookOfBindingItem(defaultProperties().stacksTo(1))); public static final DeferredItem BOOK_OF_BINDING_BOUND_FOLIOT = ITEMS.register( - "book_of_binding_bound_foliot", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"))); + "book_of_binding_bound_foliot", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN))); public static final DeferredItem BOOK_OF_BINDING_DJINNI = ITEMS.register( "book_of_binding_djinni", () -> new BookOfBindingItem(defaultProperties().stacksTo(1))); public static final DeferredItem BOOK_OF_BINDING_BOUND_DJINNI = ITEMS.register( - "book_of_binding_bound_djinni", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"))); + "book_of_binding_bound_djinni", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN))); public static final DeferredItem BOOK_OF_BINDING_AFRIT = ITEMS.register( "book_of_binding_afrit", () -> new BookOfBindingItem(defaultProperties().stacksTo(1))); public static final DeferredItem BOOK_OF_BINDING_BOUND_AFRIT = ITEMS.register( - "book_of_binding_bound_afrit", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"))); + "book_of_binding_bound_afrit", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN))); public static final DeferredItem BOOK_OF_BINDING_MARID = ITEMS.register( "book_of_binding_marid", () -> new BookOfBindingItem(defaultProperties().stacksTo(1))); public static final DeferredItem BOOK_OF_BINDING_BOUND_MARID = ITEMS.register( - "book_of_binding_bound_marid", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"))); + "book_of_binding_bound_marid", () -> new BookOfBindingBoundItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN))); //Books of Calling //Foliot public static final DeferredItem BOOK_OF_CALLING_FOLIOT_LUMBERJACK = ITEMS.register("book_of_calling_foliot_lumberjack", - () -> new BookOfCallingLumberjackItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + () -> new BookOfCallingLumberjackItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), TranslationKeys.BOOK_OF_CALLING_GENERIC + "_foliot")); public static final DeferredItem BOOK_OF_CALLING_FOLIOT_TRANSPORT_ITEMS = ITEMS.register("book_of_calling_foliot_transport_items", - () -> new BookOfCallingTransportItems(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + () -> new BookOfCallingTransportItems(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), TranslationKeys.BOOK_OF_CALLING_GENERIC + "_foliot")); public static final DeferredItem BOOK_OF_CALLING_FOLIOT_CLEANER = ITEMS.register("book_of_calling_foliot_cleaner", - () -> new BookOfCallingCleanerItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + () -> new BookOfCallingCleanerItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), TranslationKeys.BOOK_OF_CALLING_GENERIC + "_foliot")); //Djinn public static final DeferredItem BOOK_OF_CALLING_DJINNI_MANAGE_MACHINE = ITEMS.register("book_of_calling_djinni_manage_machine", - () -> new BookOfCallingManageMachineItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + () -> new BookOfCallingManageMachineItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), TranslationKeys.BOOK_OF_CALLING_GENERIC + "_djinni")); //Armor @@ -278,30 +279,30 @@ public class OccultismItems { public static final DeferredItem MINER_DEBUG_UNSPECIALIZED = ITEMS.register("miner_debug_unspecialized", () -> new MinerSpiritItem(defaultProperties() - .component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)") + .component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN) .durability(10000), () -> 100, () -> 10, () -> 10000)); public static final DeferredItem MINER_FOLIOT_UNSPECIALIZED = ITEMS.register("miner_foliot_unspecialized", () -> new MinerSpiritItem(defaultProperties() - .component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)") + .component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN) .durability(1000), Occultism.SERVER_CONFIG.dimensionalMineshaft.minerFoliotUnspecialized.maxMiningTime, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerFoliotUnspecialized.rollsPerOperation, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerFoliotUnspecialized.durability)); public static final DeferredItem MINER_DJINNI_ORES = ITEMS.register("miner_djinni_ores", () -> new MinerSpiritItem(defaultProperties().durability(400) - .component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + .component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), Occultism.SERVER_CONFIG.dimensionalMineshaft.minerDjinniOres.maxMiningTime, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerDjinniOres.rollsPerOperation, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerDjinniOres.durability)); public static final DeferredItem MINER_AFRIT_DEEPS = ITEMS.register("miner_afrit_deeps", () -> new MinerSpiritItem(defaultProperties().durability(800) - .component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + .component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), Occultism.SERVER_CONFIG.dimensionalMineshaft.minerAfritDeeps.maxMiningTime, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerAfritDeeps.rollsPerOperation, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerAfritDeeps.durability)); public static final DeferredItem MINER_MARID_MASTER = ITEMS.register("miner_marid_master", () -> new MinerSpiritItem(defaultProperties().durability(1600) - .component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)"), + .component(OccultismDataComponents.SPIRIT_NAME, TextUtil.SPIRIT_NAME_NOT_YET_KNOWN), Occultism.SERVER_CONFIG.dimensionalMineshaft.minerMaridMaster.maxMiningTime, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerMaridMaster.rollsPerOperation, Occultism.SERVER_CONFIG.dimensionalMineshaft.minerMaridMaster.durability)); diff --git a/src/main/java/com/klikli_dev/occultism/util/ItemNBTUtil.java b/src/main/java/com/klikli_dev/occultism/util/ItemNBTUtil.java index 6287ab461..b5997dad8 100644 --- a/src/main/java/com/klikli_dev/occultism/util/ItemNBTUtil.java +++ b/src/main/java/com/klikli_dev/occultism/util/ItemNBTUtil.java @@ -57,6 +57,15 @@ public static void updateItemNBTFromEntity(ItemStack stack, SpiritEntity entity) } + public static void generateBoundSpiritNameIfNone(ItemStack stack) { + if (!stack.has(OccultismDataComponents.SPIRIT_NAME) || + stack.get(OccultismDataComponents.SPIRIT_NAME).isEmpty() || + stack.get(OccultismDataComponents.SPIRIT_NAME).equals(TextUtil.SPIRIT_NAME_NOT_YET_KNOWN) + ) { + generateBoundSpiritName(stack); + } + } + public static void generateBoundSpiritName(ItemStack stack) { setBoundSpiritName(stack, TextUtil.generateName()); } diff --git a/src/main/java/com/klikli_dev/occultism/util/TextUtil.java b/src/main/java/com/klikli_dev/occultism/util/TextUtil.java index d62d057f5..ec41f93da 100644 --- a/src/main/java/com/klikli_dev/occultism/util/TextUtil.java +++ b/src/main/java/com/klikli_dev/occultism/util/TextUtil.java @@ -44,6 +44,7 @@ public class TextUtil { + public static final String SPIRIT_NAME_NOT_YET_KNOWN = "(Not yet known)"; private static final Map MOD_NAME_TO_ID = new HashMap<>(); //KliKli: Obvious :)