Duplication issue with /give command and custom item entity in Item class
Minecraft Version: 1.21.1 (Probably more affected)
NeoForge Version: 21.1.93 Logs: No logs Code:
- https://github.com/Tiviacz1337/Travelers-Backpack/blob/1.21-neoforge/src/main/java/com/tiviacz/travelersbackpack/items/TravelersBackpackItem.java#L212-L259
Notes for easier reproduction:
- hasCustomEntity(ItemStack stack) -> change return hasCustomData(stack) to return true
Steps to Reproduce:
- execute /give <playerName> travelersbackpack:bat command
- 1 Copy of item lands in player inventory, second copy is created and is being thrown in world
Description of issue: When a modded item implements the hasCustomEntity method and the createEntity method to create a custom entity when added to the world, it causes the entity to duplicate when the /give command is used
This is a very old bug, see MinecraftForge/MinecraftForge#7785 and the issues it links. See also MinecraftForge/MinecraftForge#2349 which was reported fixed.
So workarounds are needed? The second issue has the solution proposed but it seems like it was never introduced. Then reported that bug does not occur in 1.13, but it happens now.