• Recently Browsing

    No registered users viewing this page.

  • Posts

    • 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)); }   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 differences and apply the change, whenever they happen.
    • dont do that use https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/src/main/java/net/minecraftforge/common/capabilities/ICapabilityProvider.java#L41
    • Beethoven92, that's a valid point.
    • This is not something that can be debugged by just staring at some code, this needs to be checked in the debugger to see what is actually happening.
    • When the ItemStacks are created the following happens: This event handler fires. This method is called. This method is called. For the enchanted book it does not find anything in this map, so it returns this singleton instance. A new DefenseData instance is created and attached to the ItemStack. Its styleFactor and elementFactor maps are set to these two maps from the same singleton instance of ItemCombatProperties (both empty HashMap instances). The same happens for the golden chestplate.   You hover over the enchanted book. This event handler fires. It calls this method. Because this is the first time the event fires for this stack, areEnchantmentChangesApplied is false, so applyEnchantmentChanges is called and copies the enchantment data into the elementFactor and styleFactor maps. You hover over the golden chestplate. This event handler fires. It calls this method. 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. 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.
  • Topics

  • Who's Online (See full list)