Skip to content

Commit 69d8543

Browse files
authored
fix: use a holder to allow "upgrading" LocalBV3Set to a full fat one (#3051)
1 parent 7a6d17d commit 69d8543

File tree

14 files changed

+335
-59
lines changed

14 files changed

+335
-59
lines changed

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterBrush.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public BlockVector3 getDirection(BlockVector3 pt) {
121121
@Deprecated(forRemoval = true, since = "2.9.2")
122122
public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws
123123
MaxChangedBlocksException {
124-
apply(editSession, (BlockVector3Set) placed, pt, p, size);
124+
apply(editSession, LocalBlockVectorSet.wrap(placed), pt, p, size);
125125
}
126126

127127
/**

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fastasyncworldedit.core.FaweCache;
44
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
55
import com.fastasyncworldedit.core.util.StringMan;
6+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
67
import com.fastasyncworldedit.core.wrappers.AsyncPlayer;
78
import com.fastasyncworldedit.core.wrappers.LocationMaskedPlayerWrapper;
89
import com.fastasyncworldedit.core.wrappers.SilentPlayerWrapper;
@@ -31,10 +32,22 @@ public ScatterCommand(int count, int distance, String command, boolean print) {
3132
}
3233

3334
@Override
35+
@Deprecated(forRemoval = true, since = "TODO")
3436
public void apply(
3537
EditSession editSession,
3638
LocalBlockVectorSet placed,
3739
BlockVector3 position,
40+
Pattern p,
41+
double size
42+
) throws MaxChangedBlocksException {
43+
apply(editSession, LocalBlockVectorSet.wrap(placed), position, p, size);
44+
}
45+
46+
@Override
47+
public void apply(
48+
EditSession editSession,
49+
BlockVector3Set placed,
50+
BlockVector3 position,
3851
Pattern pattern,
3952
double size
4053
) throws

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ScatterOverlayBrush.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
44
import com.fastasyncworldedit.core.math.MutableBlockVector3;
5+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
56
import com.sk89q.worldedit.EditSession;
67
import com.sk89q.worldedit.MaxChangedBlocksException;
78
import com.sk89q.worldedit.function.pattern.Pattern;
@@ -14,7 +15,25 @@ public ScatterOverlayBrush(int count, int distance) {
1415
}
1516

1617
@Override
17-
public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws
18+
@Deprecated(forRemoval = true, since = "TODO")
19+
public void apply(
20+
EditSession editSession,
21+
LocalBlockVectorSet placed,
22+
BlockVector3 position,
23+
Pattern p,
24+
double size
25+
) throws MaxChangedBlocksException {
26+
apply(editSession, LocalBlockVectorSet.wrap(placed), position, p, size);
27+
}
28+
29+
@Override
30+
public void apply(
31+
EditSession editSession,
32+
BlockVector3Set placed,
33+
BlockVector3 pt,
34+
Pattern p,
35+
double size
36+
) throws
1837
MaxChangedBlocksException {
1938
final int x = pt.x();
2039
final int y = pt.y();

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/ShatterBrush.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public ShatterBrush(int count) {
2323
}
2424

2525
@Override
26+
@Deprecated(forRemoval = true, since = "TODO")
2627
public void apply(
2728
final EditSession editSession,
2829
final BlockVector3Set placed,
@@ -51,7 +52,7 @@ public void finish(
5152
LocalBlockVectorSet set = new LocalBlockVectorSet();
5253
set.add(pos);
5354
frontiers[i] = set;
54-
frontiersVisited[i] = set.clone();
55+
frontiersVisited[i] = set.copy();
5556
i++;
5657
}
5758
// Mask

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/SplatterBrush.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fastasyncworldedit.core.function.mask.SplatterBrushMask;
44
import com.fastasyncworldedit.core.function.mask.SurfaceMask;
55
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
6+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
67
import com.sk89q.worldedit.EditSession;
78
import com.sk89q.worldedit.MaxChangedBlocksException;
89
import com.sk89q.worldedit.function.operation.Operations;
@@ -25,12 +26,24 @@ public SplatterBrush(int count, int distance, boolean solid) {
2526
}
2627

2728
@Override
29+
@Deprecated(forRemoval = true, since = "TODO")
2830
public void apply(
2931
final EditSession editSession,
3032
final LocalBlockVectorSet placed,
3133
final BlockVector3 position,
3234
Pattern p,
3335
double size
36+
) throws MaxChangedBlocksException {
37+
apply(editSession, LocalBlockVectorSet.wrap(placed), position, p, size);
38+
}
39+
40+
@Override
41+
public void apply(
42+
final EditSession editSession,
43+
final BlockVector3Set placed,
44+
final BlockVector3 position,
45+
Pattern p,
46+
double size
3447
) throws MaxChangedBlocksException {
3548
final Pattern finalPattern;
3649
if (solid) {

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/SurfaceSpline.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
55
import com.fastasyncworldedit.core.math.MutableBlockVector3;
66
import com.fastasyncworldedit.core.util.MathMan;
7+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
78
import com.sk89q.worldedit.EditSession;
89
import com.sk89q.worldedit.MaxChangedBlocksException;
910
import com.sk89q.worldedit.command.tool.brush.Brush;
@@ -66,7 +67,7 @@ public void build(EditSession editSession, BlockVector3 pos, Pattern pattern, do
6667
MutableBlockVector3 mutable = MutableBlockVector3.at(0, 0, 0);
6768
interpol.setNodes(nodes);
6869
final double splinelength = interpol.arcLength(0, 1);
69-
LocalBlockVectorSet vset = new LocalBlockVectorSet();
70+
BlockVector3Set vset = LocalBlockVectorSet.wrapped();
7071
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
7172
final Vector3 tipv = interpol.getPosition(loop);
7273
final int tipx = MathMan.roundInt(tipv.x());
@@ -85,7 +86,7 @@ public void build(EditSession editSession, BlockVector3 pos, Pattern pattern, do
8586
}
8687
if (radius != 0) {
8788
double radius2 = radius * radius;
88-
LocalBlockVectorSet newSet = new LocalBlockVectorSet();
89+
BlockVector3Set newSet = LocalBlockVectorSet.wrapped();
8990
final int ceilrad = (int) Math.ceil(radius);
9091
for (BlockVector3 v : vset) {
9192
final int tipx = v.x();

worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/sweep/ClipboardSpline.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
44
import com.fastasyncworldedit.core.math.transform.RoundedTransform;
5+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
56
import com.sk89q.worldedit.EditSession;
67
import com.sk89q.worldedit.MaxChangedBlocksException;
78
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@@ -28,7 +29,7 @@ public class ClipboardSpline extends Spline {
2829

2930
private BlockVector3 center;
3031
private final BlockVector3 centerOffset;
31-
private final LocalBlockVectorSet buffer;
32+
private final BlockVector3Set buffer;
3233

3334
/**
3435
* Constructor without position-correction. Use this constructor for an interpolation
@@ -87,7 +88,7 @@ public ClipboardSpline(
8788
this.centerOffset = center.subtract(center.round());
8889
this.center = center.subtract(centerOffset);
8990
this.transform = transform;
90-
this.buffer = new LocalBlockVectorSet();
91+
this.buffer = LocalBlockVectorSet.wrapped();
9192
}
9293

9394
@Override

worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/CachedMask.java

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ public CachedMask(Mask mask) {
2727
* @param local If the area will be small
2828
* @since 2.4.0
2929
*/
30+
@Deprecated(forRemoval = true, since = "TODO")
3031
public CachedMask(Mask mask, boolean local) {
3132
super(mask);
3233
hasExtent = mask instanceof AbstractExtentMask;
3334
if (local) {
34-
cache_checked = new LocalBlockVectorSet();
35-
cache_results = new LocalBlockVectorSet();
35+
cache_checked = LocalBlockVectorSet.wrapped();
36+
cache_results = LocalBlockVectorSet.wrapped();
3637
} else {
3738
cache_checked = new BlockVectorSet();
3839
cache_results = new BlockVectorSet();
@@ -63,25 +64,15 @@ public boolean test(BlockVector3 vector) {
6364
int x = vector.x();
6465
int y = vector.y();
6566
int z = vector.z();
66-
try {
67-
boolean check = cache_checked.add(x, y, z);
68-
if (!check) {
69-
return cache_results.contains(x, y, z);
70-
}
71-
boolean result = getMask().test(vector);
72-
if (result) {
73-
cache_results.add(x, y, z);
74-
}
75-
return result;
76-
} catch (UnsupportedOperationException ignored) {
77-
boolean result = getMask().test(vector);
78-
resetCache();
79-
cache_checked.add(x, y, z);
80-
if (result) {
81-
cache_results.add(x, y, z);
82-
}
83-
return result;
67+
boolean check = cache_checked.add(x, y, z);
68+
if (!check) {
69+
return cache_results.contains(x, y, z);
8470
}
71+
boolean result = getMask().test(vector);
72+
if (result) {
73+
cache_results.add(x, y, z);
74+
}
75+
return result;
8576
}
8677

8778
public boolean test(@Nullable Extent extent, BlockVector3 vector) {
@@ -92,25 +83,15 @@ public boolean test(@Nullable Extent extent, BlockVector3 vector) {
9283
int y = vector.y();
9384
int z = vector.z();
9485
AbstractExtentMask mask = (AbstractExtentMask) getMask();
95-
try {
96-
boolean check = cache_checked.add(x, y, z);
97-
if (!check) {
98-
return cache_results.contains(x, y, z);
99-
}
100-
boolean result = mask.test(extent, vector);
101-
if (result) {
102-
cache_results.add(x, y, z);
103-
}
104-
return result;
105-
} catch (UnsupportedOperationException ignored) {
106-
boolean result = mask.test(extent, vector);
107-
resetCache();
108-
cache_checked.add(x, y, z);
109-
if (result) {
110-
cache_results.add(x, y, z);
111-
}
112-
return result;
86+
boolean check = cache_checked.add(x, y, z);
87+
if (!check) {
88+
return cache_results.contains(x, y, z);
89+
}
90+
boolean result = mask.test(extent, vector);
91+
if (result) {
92+
cache_results.add(x, y, z);
11393
}
94+
return result;
11495
}
11596

11697
@Override

worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/SplatterBrushMask.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fastasyncworldedit.core.function.mask;
22

33
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
4+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
45
import com.sk89q.worldedit.EditSession;
56
import com.sk89q.worldedit.extent.Extent;
67
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
@@ -14,14 +15,38 @@ public class SplatterBrushMask extends AbstractExtentMask {
1415
private final BlockVector3 position;
1516
private final int size2;
1617
private final Mask surface;
17-
private final LocalBlockVectorSet placed;
18+
private final BlockVector3Set placed;
1819

20+
/**
21+
* @deprecated in favour of {@link SplatterBrushMask#SplatterBrushMask(EditSession, BlockVector3, int, Mask, BlockVector3Set)}
22+
*/
23+
@Deprecated(forRemoval = true, since = "TODO")
1924
public SplatterBrushMask(
2025
EditSession editSession,
2126
BlockVector3 position,
2227
int size2,
2328
Mask surface,
2429
LocalBlockVectorSet placed
30+
) {
31+
this(editSession, position, size2, surface, LocalBlockVectorSet.wrap(placed));
32+
}
33+
34+
/**
35+
* Create a new instance
36+
*
37+
* @param editSession Editsession to use
38+
* @param position position applied to
39+
* @param size2 radius squared
40+
* @param surface surface mask
41+
* @param placed {@link BlockVector3Set} of placed blocks
42+
* @since TODO
43+
*/
44+
public SplatterBrushMask(
45+
EditSession editSession,
46+
BlockVector3 position,
47+
int size2,
48+
Mask surface,
49+
BlockVector3Set placed
2550
) {
2651
super(editSession);
2752
this.position = position;

worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/BufferedPattern.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public BufferedPattern(Actor actor, Pattern parent, @Nullable Region region) {
5050
this.pattern = parent;
5151
this.timer = Fawe.instance().getTimer();
5252
// Assume brush is used if no region provided, i.e. unlikely to required BlockVectorSet
53-
set = region == null ? new LocalBlockVectorSet() : BlockVector3Set.getAppropriateVectorSet(region);
53+
set = region == null
54+
? LocalBlockVectorSet.wrapped()
55+
: BlockVector3Set.getAppropriateVectorSet(region);
5456
}
5557

5658
@Override

0 commit comments

Comments
 (0)