breakinblocks / Plonk

A Minecraft mod that lets you place items down anywhere https://www.curseforge.com/minecraft/mc-mods/plonk https://modrinth.com/mod/plonk
MIT License
3 stars 4 forks source link

Investigate dupe bug in someone else's claims #9

Closed BlueAgent closed 3 years ago

BlueAgent commented 3 years ago

Related: https://github.com/MinecraftForge/MinecraftForge/issues/7609

Described here: https://github.com/NillerMedDild/Enigmatica6/issues/957

The way Plonk works is it replaces the held stack with an ItemBlock that has the held stack stored inside it. Then it attempts to place said block down. If successful it's done, if not it'll reset the held stack back to how it was before.

~~On further investigation it seems that using ItemStack#onItemUse is not sufficient. I think switching to simulating the player right clicking would be better?~~

BlueAgent commented 3 years ago

Doesn't seem to happen on 1.7.10 or 1.12.2. Interesting.

BlueAgent commented 3 years ago

Okay, I can actually reproduce this without Plonk installed: Have a basic mod that just cancels the block placement event Spawn in a chest item stack that contains 64 diamond blocks with the command:

/give <username> chest{BlockEntityTag:{Items:[{Slot:0,id:diamond_block,Count:64}]}}

Then try placing it down. It will dupe. Seems like Block#onReplaced gets called when restoring block snapshots is the reason why.

This doesn't happen with FTBChunks when using a chest but does still happen with Plonk. The reason why is FTBChunks additionally cancels the right click / interaction events which happen before the block place event.

Work around for now is to check interaction first, might also have to check for both the default position and the shifted one as well.

BlueAgent commented 3 years ago

Seems like in past versions, item drops were prevented during snapshot restoration to stop dupes. But this was removed in the update to 1.14.2. I think I will go with this workaround for now.

BlueAgent commented 3 years ago

Fixed in Plonk v9.0.7 (mc 1.16.5). It's compatible with 1.16.x.