2929import org .spongepowered .api .data .Transaction ;
3030import org .spongepowered .api .data .persistence .DataContainer ;
3131import org .spongepowered .api .data .persistence .Queries ;
32+ import org .spongepowered .api .world .BlockChangeFlag ;
33+ import org .spongepowered .api .world .BlockChangeFlags ;
3234
35+ import java .lang .ref .WeakReference ;
3336import java .util .List ;
3437import java .util .Objects ;
3538import java .util .StringJoiner ;
@@ -47,6 +50,9 @@ public final class BlockTransaction extends Transaction<BlockSnapshot> {
4750
4851 private final Operation operation ;
4952
53+ private @ Nullable WeakReference <BlockSnapshot > custom ;
54+ private @ Nullable BlockChangeFlag customFlag ;
55+
5056 public BlockTransaction (final BlockSnapshot original , final BlockSnapshot defaultReplacement ,
5157 final Operation operation
5258 ) {
@@ -66,6 +72,37 @@ public Operation operation() {
6672 return this .operation ;
6773 }
6874
75+ /**
76+ * Sets the custom snapshot. If setting <code>null</code>, this will
77+ * reset to use the {@link #defaultReplacement()} snapshot.
78+ *
79+ * @param custom The custom snapshot
80+ * @param flag TThe various change flags controlling some interactions
81+ */
82+ public void setCustom (final @ Nullable BlockSnapshot custom , final BlockChangeFlag flag ) {
83+ this .setCustom (custom );
84+ if (custom != null ) {
85+ this .custom = new WeakReference <>(custom );
86+ this .customFlag = flag ;
87+ } else {
88+ this .custom = null ;
89+ this .customFlag = null ;
90+ }
91+ }
92+
93+ /**
94+ * Gets the {@link BlockChangeFlag flag} that is used to place
95+ * the custom {@link BlockSnapshot}.
96+ *
97+ * @return The flag
98+ */
99+ public BlockChangeFlag customFlag () {
100+ if (this .custom ().isEmpty () || this .custom == null || this .custom .get () != this .custom ().get ()) {
101+ return BlockChangeFlags .DEFAULT_PLACEMENT ;
102+ }
103+ return this .customFlag ;
104+ }
105+
69106 @ Override
70107 public int hashCode () {
71108 return Objects .hash (super .hashCode (), this .operation );
0 commit comments