Skip to content

Commit 650496e

Browse files
twme-aiNotMyFaultPierreSchwang
authored
Fix curves in extended negative world heights (#3608)
* Fix wrapped vector set upgrade for vector additions * Fix wrapped vector set upgrade for bulk additions --------- Co-authored-by: Alexander Brandes <mc.cache@web.de> Co-authored-by: Pierre Maurice Schwang <27054324+PierreSchwang@users.noreply.github.com>
1 parent b4a7ad4 commit 650496e

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

worldedit-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dependencies {
6262
// Tests
6363
testRuntimeOnly(libs.log4j.core)
6464
testImplementation(libs.parallelgzip)
65+
testImplementation(libs.sparsebitset)
6566
}
6667

6768
tasks.test {

worldedit-core/src/main/java/com/fastasyncworldedit/core/math/LocalBlockVectorSet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public boolean contains(Object o) {
576576

577577
@Override
578578
public boolean add(BlockVector3 blockVector3) {
579-
return set.add(blockVector3);
579+
return add(blockVector3.x(), blockVector3.y(), blockVector3.z());
580580
}
581581

582582
@Override
@@ -591,7 +591,11 @@ public boolean containsAll(@Nonnull Collection<?> c) {
591591

592592
@Override
593593
public boolean addAll(@Nonnull Collection<? extends BlockVector3> c) {
594-
return set.addAll(c);
594+
boolean result = false;
595+
for (BlockVector3 vector : c) {
596+
result |= add(vector);
597+
}
598+
return result;
595599
}
596600

597601
@Override
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* WorldEdit, a Minecraft world manipulation toolkit
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldEdit team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.fastasyncworldedit.core.math;
21+
22+
import com.fastasyncworldedit.core.util.collection.BlockVector3Set;
23+
import com.sk89q.worldedit.math.BlockVector3;
24+
import org.junit.jupiter.api.Test;
25+
26+
import java.util.List;
27+
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
30+
class LocalBlockVectorSetTest {
31+
32+
@Test
33+
void upgradesWhenBlockVectorIsOutsideLocalRange() {
34+
BlockVector3Set set = LocalBlockVectorSet.wrapped();
35+
BlockVector3 position = BlockVector3.at(-38, -357, -20);
36+
37+
assertTrue(set.add(position));
38+
assertTrue(set.contains(position));
39+
}
40+
41+
@Test
42+
void retainsExistingVectorsWhenUpgraded() {
43+
BlockVector3Set set = LocalBlockVectorSet.wrapped();
44+
BlockVector3 originalPosition = BlockVector3.at(-38, 128, -20);
45+
BlockVector3 positionOutsideLocalRange = BlockVector3.at(-38, -357, -20);
46+
47+
assertTrue(set.add(originalPosition));
48+
assertTrue(set.add(positionOutsideLocalRange));
49+
assertTrue(set.contains(originalPosition));
50+
assertTrue(set.contains(positionOutsideLocalRange));
51+
}
52+
53+
@Test
54+
void upgradesWhenBulkAddingVectorsOutsideLocalRange() {
55+
BlockVector3Set set = LocalBlockVectorSet.wrapped();
56+
BlockVector3 positionInsideLocalRange = BlockVector3.at(-38, 128, -20);
57+
BlockVector3 positionOutsideLocalRange = BlockVector3.at(-38, -357, -20);
58+
59+
assertTrue(set.addAll(List.of(positionInsideLocalRange, positionOutsideLocalRange)));
60+
assertTrue(set.contains(positionInsideLocalRange));
61+
assertTrue(set.contains(positionOutsideLocalRange));
62+
}
63+
64+
}

0 commit comments

Comments
 (0)