Infinite loop when attaching a capability based on enchantability
Patrigan opened this issue ยท 1 comments
Minecraft Version
1.16.5
What happened?
Code between yours and mine is triggering an infinite loop. I have a capability that attaches itself to any item that can be enchanted, your VeinminigEnchantment creates a new ItemStack whenever it tests if it can enchant an item, which in turn will cause forge to check for capabilities again (every time an itemstack is created).
I suggest you change that test to no longer create a new ItemStack, as any mod that wants to attach a capbility based on enchantability will break with your mod.
Code in question:
` private static boolean canEnchantItem(Item item) {
for (String entry : VeinMiningConfig.Enchantment.items) {
if (PREDICATE_MAP.getOrDefault(entry, k -> false).test(new ItemStack(item))) {
return true;
} else if (item.getRegistryName() != null &&
item.getRegistryName().toString().equals(entry)) {
return true;
}
}
return false;
}Infinite loop:
at net.minecraftforge.common.extensions.IForgeItemStack.getToolTypes(IForgeItemStack.java:113) ~[?:?] {re:mixin,re:computing_frames,re:classloading,pl:mixin:APP:apotheosis.mixins.json:MixinIForgeItemStack,pl:mixin:A}
at top.theillusivec4.veinmining.veinmining.VeinMiningEnchantment.lambda$static$0(VeinMiningEnchantment.java:44) ~[?:property(class java.lang.String, provider(?))] {re:classloading}
at top.theillusivec4.veinmining.veinmining.VeinMiningEnchantment$$Lambda$3008/320130241.test(Unknown Source) ~[?:?] {}
at top.theillusivec4.veinmining.veinmining.VeinMiningEnchantment.canEnchantItem(VeinMiningEnchantment.java:64) ~[?:property(class java.lang.String, provider(?))] {re:classloading}
at top.theillusivec4.veinmining.veinmining.VeinMiningEnchantment$$Lambda$3005/461895629.test(Unknown Source) ~[?:?] {}
at net.minecraft.enchantment.EnchantmentType.func_77557_a(EnchantmentType.java:99) ~[?:?] {re:mixin,pl:runtime_enum_extender:A,re:classloading,pl:runtime_enum_extender:A}
at com.infamous.dungeons_libraries.items.ItemEvents.lambda$canBeEnchanted$0(ItemEvents.java:26) ~[?:1.16.5-0.0.3-beta] {re:classloading}
at com.infamous.dungeons_libraries.items.ItemEvents$$Lambda$27451/1489234944.test(Unknown Source) ~[?:?] {}
at java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90) ~[?:1.8.0_51] {}
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) ~[?:1.8.0_51] {}
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) ~[?:1.8.0_51] {}
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:529) ~[?:1.8.0_51] {}
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:516) ~[?:1.8.0_51] {}
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502) ~[?:1.8.0_51] {}
at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230) ~[?:1.8.0_51] {}
at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196) ~[?:1.8.0_51] {}
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_51] {}
at java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:449) ~[?:1.8.0_51] {}
at com.infamous.dungeons_libraries.items.ItemEvents.canBeEnchanted(ItemEvents.java:26) ~[?:1.16.5-0.0.3-beta] {re:classloading}
at com.infamous.dungeons_libraries.items.ItemEvents.onAttachItemStackCapabilities(ItemEvents.java:20) ~[?:1.16.5-0.0.3-beta] {re:classloading}
at net.minecraftforge.eventbus.ASMEventHandler_289_ItemEvents_onAttachItemStackCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[?:?] {}
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.eventbus.EventBus$$Lambda$3468/1877226071.invoke(Unknown Source) ~[?:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:597) ~[?:?] {re:mixin,re:classloading}
at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:591) ~[?:?] {re:mixin,re:classloading}
at net.minecraftforge.common.capabilities.CapabilityProvider.doGatherCapabilities(CapabilityProvider.java:83) ~[?:?] {re:computing_frames,re:mixin,re:classloading}
at net.minecraftforge.common.capabilities.CapabilityProvider.getCapabilities(CapabilityProvider.java:91) ~[?:?] {re:computing_frames,re:mixin,re:classloading}
at net.minecraftforge.common.capabilities.CapabilityProvider.getCapability(CapabilityProvider.java:173) ~[?:?] {re:computing_frames,re:mixin,re:classloading}
at blusunrize.immersiveengineering.common.items.BuzzsawItem.getSawblade(BuzzsawItem.java:166) ~[?:?] {re:classloading}
at blusunrize.immersiveengineering.common.items.BuzzsawItem.getHead(BuzzsawItem.java:159) ~[?:?] {re:classloading}
at blusunrize.immersiveengineering.common.items.BuzzsawItem.getToolTypes(BuzzsawItem.java:316) ~[?:?] {re:classloading}`
How do you trigger this bug?
- Just have any new item
Loader
Forge
Loader Version
forge 36.2.20
Mod Version
Vein Mining 1.16.5-0.14
Relevant Log Outputs
see above, should be sufficient.