Duplication Issue with Wrench and Forge's EntityPlaceEvent
maxanier opened this issue ยท 3 comments
There seems to be a general dupe issue with the block dismantling mechanic of the wrench.
I think it is not per se a bug in Create, but definitively something that should be considered/discussed.
This might be a duplicate of #1467 , however, I am not sure, and since this problem may affect many other mods, I decided to open a separate issue.
Description
In my mod I want to prevent the player from placing blocks (under certain conditions). So I cancel the EntityPlaceEvent
event. This works as intended.
However, this is causing a item dupe with Create (TeamLapen/Vampirism#1011). Create's Wrench allows dismantling some blocks (e.g. a cogwheel). Shift-rightclicking the block while destroy it and place it in the player's inventory.
When I cancel the EntityPlaceEvent
though, the block is not broken, yet the item is placed in the inventory anyways.
Here is why:
On serverside when rightclicking a block with an item ForgeHooks#onPlaceItemIntoWorld
is called. This starts caching any block changes. Then Item#useOn
is called. Create's wrench uses this to destroy the block and place a item in the inventory.
Afterwards, the Forge code checks for any captured block changes, notices one (create block -> air) and fires the EntityPlaceEvent
. I cancel that event and Forge restores the block snapshot. Thereby, the destroyed block is restored but the item remains in the player's inventory.
A workaround is to check if the new block in EntityPlaceEvent
is air on my side (so basically a block break, not a block place).
However, similar issues may occur with other mods. At least in my opinion, it is not obvious that the EntityPlaceEvent
is fired when a block is removed or a it could cause a dupe.
Possible workarounds
Maybe the dismantling code could be moved to Item#onUseFirst
or moved to the block's interact method.
The fix proposed in #2141 does not solve this issue (did not test, but since the block is only restored after the onUse
method is complete, the isAir
check will likely always succeed.
Links
WrenchItem:
Block is destroyed here:
ForgeHooks#onPlaceItemIntoWorld https://github.com/MinecraftForge/MinecraftForge/blob/ae7609979e8781aab5c20628b7c08a9b185ce1ef/src/main/java/net/minecraftforge/common/ForgeHooks.java#L624
Most of duplication glitches like this were in 1.12.2 version.
with:
- Botania
Aggregator of life using on spawner, spawner remains and aggregator with.
Wand of forest using at force relay, relay just dropped and remains. - Bloodmagic
Ritual dismantler using on rituals, ritual deconstructed without wasting stones. - Astral Sorcery
Conversion wand doesn't replace block but it dropped.
I checked it all in 1.16.5 and result:
- Botania
all doesn't work. - Blood magic
Dismantler deleted. - Astral sorcery
Works.
Also you can use boxes from Botania to store and duplicate all items.
There are more items can duplicate from other mods.
Usually this is interacting items that can break blocks using right click or something.
This issue has been marked as stale because it has been inactive for 3 weeks. It will be closed if it remains inactive for another 3 weeks.