Jump to content

Recommended Posts

Posted (edited)

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:

1882135672_TurtleShell.png.209aaa7fa74c0e16757ffa462ca55ef0.png

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)

2114261519_Chestplatebefore.png.9cabe9e69219b4b8e376adb9856c66fd.png

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

1557549527_EnchantedBook.thumb.png.8f50f3fee09b772ccba8c0a1760715b8.png

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.38667134_Chestplateafter.thumb.png.73591936fd80b53f9b82816348921b7c.png

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 by Tavi007
Posted (edited)
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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.