Posted October 31, 20204 yr Hello! I implemented an itemstack capability, that is working fine in survival (at least I haven't noticed anything yet). But I noticed some weird behaviour with enchanted books itemstacks and the creative inventory. I try my best to explain how the bug appears. First of I use ItemTooltipEvent to make the information of the capability visible. This does work at first. For example the turtle shell has default values, which can be seen here: Another example is the Chestplate, which does not have any default values (well it does, but they won't get displayed, because they are not 'special' like water or thunder from the turtle shell) Now the enchanted book also has different values, but this time the source is the enchantment. So the values on the book are also correct Now we are getting close to the bug. If I now move the mouse back to the chestplate, it suddendly has the same values as the enchanted book. So at some point the capability of the chestplate got filled with the data from the enchanted book. Also weird is, that when I hover back over the turtle shell, the data is still the same as before (the correct behaviour). Only the itemstacks, that hasn't had any default data, have the same information as the enchanted book. I'm absolutly buffled how this happens and I can only reset it by restarting the whole game. Switching game file or switching game mode to survival and back to creative does nothing. So yeah... I really hope someone here know what to do, cause I don't. My repository: https://github.com/Tavi007/ElementalCombat addToolTipEvent: https://github.com/Tavi007/ElementalCombat/blob/224466912125ac0dcbcd6bf1f8de72261de6b174/src/main/java/Tavi007/ElementalCombat/events/RenderEvents.java#L43 Edited October 31, 20204 yr by Tavi007
October 31, 20204 yr Author 56 minutes ago, diesieben07 said: Because this is the first time the event fires for this stack, areEnchantmentChangesApplied is false, so applyEnchantmentChanges is called. applyEnchantmentChanges finds that newEnchantments is empty (because the golden chestplate is not enchanted) and so simply does nothing but set areEnchantmentChangesApplied to true. styleFactor and elementFactor still point to the same singleton HashMap instances from the empty ItemCombatProperties. These maps have been filled with the enchantments for the enchanted book in the previous step and still contain this same data. Thank you! This is where the itemstack got the wrong value from. I just have to change styleMap and elementMap in the attachCapabiltiesEvent to new instances and the bug is gone. @SubscribeEvent(priority = EventPriority.LOWEST) public static void attachCapabilitiesItem(final AttachCapabilitiesEvent<ItemStack> event) { ItemCombatProperties itemProperties = ElementalCombatAPI.getDefaultProperties(event.getObject()); //default values HashMap<String, Integer> styleMap = new HashMap<String, Integer>(itemProperties.getDefenseStyle()); HashMap<String, Integer> elementMap = new HashMap<String, Integer>(itemProperties.getDefenseElement()); final DefenseData defData = new DefenseData(styleMap, elementMap); event.addCapability(ID, createProvider(defData)); } 56 minutes ago, diesieben07 said: I cannot comprehend why you copy the enchantment data and have this elaborate "diffing" algorithm instead of simply computing whatever data you need from the enchantments on the fly. My mod is supposed to be used as API, so I don't have full control over the capability data. I can't just set the data to default values + enchantment values, because the DefenseData is the sum of the default values + enchantment values + some changes from some other mod. So I have to work with differences and apply the change, whenever they happen. Edited October 31, 20204 yr by Tavi007
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.