Apotheosis

Apotheosis

70M Downloads

[1.19.2 - 6.3.5]: getStateForPlacement call in tooltips

SiverDX opened this issue ยท 2 comments

commented

Stack dump as an example call history for the shrink method:

java.lang.Exception: Stack trace
	at java.base/java.lang.Thread.dumpStack(Unknown Source)
	at TRANSFORMER/[email protected]/net.minecraft.world.item.ItemStack.handler$dpj000$test(ItemStack.java:4093)
	at TRANSFORMER/[email protected]/net.minecraft.world.item.ItemStack.m_41774_(ItemStack.java)
	at TRANSFORMER/[email protected]/satisfyu.vinery.block.stem.PaleStemBlock.m_5573_(PaleStemBlock.java:58)
	at TRANSFORMER/[email protected]/shadows.apotheosis.ench.EnchModuleClient.tooltips(EnchModuleClient.java:58)
	at TRANSFORMER/[email protected]/shadows.apotheosis.ench.__EnchModuleClient_tooltips_ItemTooltipEvent.invoke(.dynamic)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.EventBus.post(EventBus.java:315)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.EventBus.post(EventBus.java:296)
	at TRANSFORMER/[email protected]/net.minecraftforge.event.ForgeEventFactory.onItemTooltip(ForgeEventFactory.java:259)
	at TRANSFORMER/[email protected]/net.minecraft.world.item.ItemStack.m_41651_(ItemStack.java:782)
	at TRANSFORMER/[email protected]+1.19.2+forge/dev.emi.emi.api.stack.ItemEmiStack.getTooltipText(ItemEmiStack.java:151)
	at TRANSFORMER/[email protected]+1.19.2+forge/dev.emi.emi.search.EmiSearch.bake(EmiSearch.java:59)
	at TRANSFORMER/[email protected]+1.19.2+forge/dev.emi.emi.runtime.EmiReloadManager$ReloadWorker.run(EmiReloadManager.java:203)
	at java.base/java.lang.Thread.run(Unknown Source)

I'm not sure if this is on the mods, Apotheosis or EMI but calling getStateForPlacement in the tooltip method doesn't seem safe

https://github.com/satisfyu/Vinery/blob/1b8f3c44b44c78330abd4fc340bcf6b11c2698e5/common/src/main/java/satisfyu/vinery/block/stem/PaleStemBlock.java#L49
Shrinks your main hand item when the call happens

Other mods spam you with warning messages that there is not enough place to place the block (Furnish / Dragon Survival)

commented

Resolving the enchanting stat tooltips requires getting a state from the blockstate, which involves calling getStateForPlacement, which should not have side effects. Those mods should be performing such actions in other methods (such as useOn).

commented

added a workaround for now, don't really expect multiple mods to change their logic

    @Inject(method = "tooltips", at = @At("HEAD"), cancellable = true, remap = false)
    public void skipBlacklisted(final ItemTooltipEvent event, final CallbackInfo callback) {
        Item item = event.getItemStack().getItem();

        if (item instanceof BlockItem blockItem) {
            Block block = blockItem.getBlock();

            if (block.builtInRegistryHolder().is(ModItemTagProvider.APOTHEOSIS_ENCHANT_STAT_BLACKLIST)) {
                callback.cancel();
            }
        }
    }