Fix structure clear removing instead of restoring blocks #1107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In current 1.8 PGM, structures were recently re-implemented, but have a significant behavior change in respect to legacy PGM.
In 1.11 PGM, clearing a dynamic structure did not mean filling it with air, instead, it meant restoring the original blocks before the structure was placed by the dynamic. See https://github.com/OvercastNetwork/Plugins/blob/master/PGM/src/main/java/tc/oc/pgm/structure/DynamicDefinition.java#L118, it clears by
placing
aclearImage
, the clear image was made when the Dynamic was initialized.This poses a subtle required change in paradigm, as at the moment we only store one world snapshot, intended to store all the very-original blocks. However, because structures can clear their own blocks so they're air by default, a dynamic's removal has to place blocks from a different world snapshot (one after structures have cleared). In legacy PGM this was a non-issue as it worked with immutable BlockImages, in here, we work with ChunkSnapshots.
The change makes it so some of the logic previously in SnapshotMatchModule is moved over to a new WorldSnapshot abstraction, which holds a view of the world at a certain time, the SnapshotMatchModule works with one "default" world snapshot used for most operations, and then, DynamicStructures will use a different one, created after clears have occurred.
As an additional optimization, if no structures clear themselves, then it will use the same world snapshot and won't create an extra one.
Lastly, the Structures now create a FiniteBlockRegion if they avoid air, which is a region that includes all non-air-blocks, that way places-and-removes no longer need to check for original block, if it's in the region then it should replace. This was needed because a dynamic's removal depends on if the original structure includes the block, not on if it's air in its current world snapshot (the one after structures may have potentially cleared).
This was brought up by @CrazyisCreeps on discord, and i have not yet ran tests on this PGM build, so i'll leave it as draft until we have some confirmation about if this fixes the issue or not.
Edit: it has now been tested and validated.