Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weird item mutation bug with EffHealth #6586

Merged
merged 17 commits into from May 1, 2024

Conversation

Fusezion
Copy link
Contributor

Description

This PR aims to fix a weird mutation bug that would happen on items when using repair {_item1} and {_item2} causing item2 to mutate into item1. This pr also adds itemtype support into ItemUtils#setDamage and ItemUtils#getDamage since it was cleaner this way.

The part that caused this bug in the first place was the damageables.change() usage. After removing it everything seems to still work as it did before.

I spent far too long on this and ended up needing to clean up the class a bit along with remove some weird behavior skript was doing internally. If you have any questions feel free to ask. If you have any suggestions for more test please let me know as I'm not great at writing test with good explanations.

From testing currently I saw no breaking changes in parity and everything works as it was before except slots. While I was not 100% sure about them working prior I wanna say they most likely did however after some changes the parity broke forcing me into a slot check.

Here is a quick before and after to showcase the issue
image
image


Target Minecraft Versions: any
Requirements: none
Related Issues: none

@Fusezion
Copy link
Contributor Author

I would of put the new test into a regression however I didn't have a pr nor an issue for this and it was easier to just add it into the existing EffHealth.sk file

@sovdeeth sovdeeth added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Apr 19, 2024
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick review

@Fusezion Fusezion requested a review from Moderocky April 24, 2024 21:27
Comment on lines +92 to +94
} else {
ItemUtils.setDamage(itemType, (int) Math2.fit(0, (ItemUtils.getDamage(itemType) + (isHealing ? -amount : amount)), itemType.getMaterial().getMaxDurability()));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to 1.20.5 changes this is now technically bugable due to custom durability component. Forgot all about that.
In addition Damageable ItemMeta is available on all items as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is worth delaying this addition, or should we get it in 2.6.5 and worry about the 1.20.5 changes later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over it, is appears spigot has just thrown the the #setMaxDamage method into Damageable, I can quickly see how a test build of this interacts but as paper still has no stable release only betas I likely cannot push it for awhile longer.

Copy link
Contributor Author

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't wanna load up intellij for skript rn

@Moderocky Moderocky added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Apr 27, 2024
@Moderocky Moderocky added the 2.8 Targeting a 2.8.X version release label May 1, 2024
@APickledWalrus APickledWalrus merged commit cf199c0 into SkriptLang:dev/patch May 1, 2024
5 checks passed
@Fusezion Fusezion deleted the bug/repair-effect branch May 1, 2024 23:58
@rudde0
Copy link

rudde0 commented May 5, 2024

Sometimes I'm dealing the items with the asynchronous way and the server crashing after this PR with a stack trace below.

[13:58:34] [Craft Scheduler Thread - 538 - MundoSK-Async/ERROR]: #!#! Current item: repair leggings of (the attacked entity >> ch.njol.skript.classes.data.DefaultConverters$$Lambda/0x00007f12f9d44d00@237ee6d3: ConverterInfo{from=interface org.bukkit.entity.Entity,to=interface org.bukkit.entity.LivingEntity,converter=ch.njol.skript.classes.data.DefaultConverters$$Lambda/0x00007f12f9d44d00@237ee6d3,flags=0}) by [[long:4]]
[13:58:34] [Craft Scheduler Thread - 551 - MundoSK-Async/ERROR]: #!#! Current item: repair leggings of (the attacked entity >> ch.njol.skript.classes.data.DefaultConverters$$Lambda/0x00007f12f9d44d00@237ee6d3: ConverterInfo{from=interface org.bukkit.entity.Entity,to=interface org.bukkit.entity.LivingEntity,converter=ch.njol.skript.classes.data.DefaultConverters$$Lambda/0x00007f12f9d44d00@237ee6d3,flags=0}) by [[long:4]]
[13:58:34] [Craft Scheduler Thread - 538 - MundoSK-Async/ERROR]: #!#! Current trigger: damage of player (damage of [[entitydata:player]]) (a_2_Survival_Rules/damageHandlers.sk, line 760)
[13:58:34] [pool-26-thread-1/WARN]: Exception in thread "pool-26-thread-1" java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectArrayList.get(int)" because "this.wrapped" is null
[13:58:34] [pool-26-thread-1/WARN]: 	at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap$MapIterator.nextEntry(Object2ObjectOpenHashMap.java:637)
[13:58:34] [pool-26-thread-1/WARN]: 	at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap$KeyIterator.next(Object2ObjectOpenHashMap.java:1038)
[13:58:34] [pool-26-thread-1/WARN]: 	at org.bukkit.craftbukkit.v1_20_R3.inventory.CraftMetaItem.<init>(CraftMetaItem.java:441)
[13:58:34] [pool-26-thread-1/WARN]: 	at org.bukkit.craftbukkit.v1_20_R3.inventory.CraftMetaArmor.<init>(CraftMetaArmor.java:65)
[13:58:34] [pool-26-thread-1/WARN]: 	at org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack.getItemMeta(CraftItemStack.java:372)
[13:58:34] [pool-26-thread-1/WARN]: 	at org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack.getItemMeta(CraftItemStack.java:324)
[13:58:34] [pool-26-thread-1/WARN]: 	at org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack.getItemMeta(CraftItemStack.java:316)
[13:58:34] [pool-26-thread-1/WARN]: 	at Vulcan-2.8.6.jar//me.frep.vulcan.spigot.Vulcan_Sh.Vulcan_ZJ(Vulcan_Sh.java:884)
[13:58:34] [pool-26-thread-1/WARN]: 	at Vulcan-2.8.6.jar//me.frep.vulcan.spigot.Vulcan_A_.Vulcan_d(Vulcan_A_.java:43)
[13:58:34] [pool-26-thread-1/WARN]: 	at Vulcan-2.8.6.jar//me.frep.vulcan.spigot.Vulcan_BZ.lambda$onPacketPlayReceive$0(Vulcan_BZ.java:49)
[13:58:34] [pool-26-thread-1/WARN]: 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[13:58:34] [pool-26-thread-1/WARN]: 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[13:58:34] [pool-26-thread-1/WARN]: 	at java.base/java.lang.Thread.run(Thread.java:1583)
[13:58:34] [Server thread/WARN]: [Skript] Task #92 for Skript v2.8.5 generated an exception
java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectArrayList.get(int)" because "this.wrapped" is null
	at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap$MapIterator.nextEntry(Object2ObjectOpenHashMap.java:637) ~[fastutil-8.5.12.jar:?]
	at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap$FastEntryIterator.next(Object2ObjectOpenHashMap.java:752) ~[fastutil-8.5.12.jar:?]
	at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap$FastEntryIterator.next(Object2ObjectOpenHashMap.java:747) ~[fastutil-8.5.12.jar:?]
	at net.minecraft.nbt.CompoundTag.copy(CompoundTag.java:500) ~[?:?]
	at net.minecraft.world.item.ItemStack.copy(ItemStack.java:786) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.world.item.ItemStack.copy(ItemStack.java:774) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.world.inventory.AbstractContainerMenu.sendAllDataToRemote(AbstractContainerMenu.java:192) ~[?:?]
	at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.updateInventory(CraftPlayer.java:1451) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at ch.njol.skript.bukkitutil.PlayerUtils$1.run(PlayerUtils.java:58) ~[Skript-2.8.5.jar:?]
	at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:482) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1679) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:487) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1558) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1246) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:323) ~[purpur-1.20.4.jar:git-Purpur-2176]
	at java.lang.Thread.run(Thread.java:1583) ~[?:?]

I tried to revert this pr and the issue is gone.

Also damage held item by 3 always setting tool's damage to (max)-3. Doesn't do (current)-3.

@Fusezion
Copy link
Contributor Author

Fusezion commented May 5, 2024

Doing anything async especially in bukkit is unsafe, in addition this really isn't the place to report an issue if a pr broke something. You can create an issue however based off the stacktrace I don't see much there that expresses it's caused by this change.

The only skript related error is PlayerUtils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.8 Targeting a 2.8.X version release bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants