Skip to content

Commit

Permalink
Fixed issues with placing large schematics with a lot of empty blocks (
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Dec 28, 2024
1 parent 73009de commit ff5e486
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/com/bgsoftware/superiorskyblock/core/BigBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,31 @@ public int nextSetBit(int fromIndex) {
int backendIdx = fromIndex / DEFAULT_CAPACITY;
int bitSetIdx = fromIndex % DEFAULT_CAPACITY;

int next = -1;
return nextSetBitInternal(backendIdx, bitSetIdx);
}

private int nextSetBitInternal(int backendIdx, int bitSetIdx) {
if (backendIdx < 0 || backendIdx >= this.backend.length)
return -1;

BitSet bitSet = this.backend[backendIdx];
if (bitSet != null) {
next = bitSet.nextSetBit(bitSetIdx);
if (next == -1 && ++backendIdx < this.backend.length) {
bitSet = this.backend[backendIdx];
if (bitSet != null)
next = bitSet.nextSetBit(0);
int next = bitSet.nextSetBit(bitSetIdx);
if (next != -1) {
return backendIdx * DEFAULT_CAPACITY + next;
}
}

return next == -1 ? -1 : backendIdx * DEFAULT_CAPACITY + next;
return nextSetBitInternal(backendIdx + 1, 0);
}

public int cardinality() {
int cardinality = 0;
for (BitSet bitSet : backend) {
if (bitSet != null)
cardinality += bitSet.cardinality();
}
return cardinality;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.bgsoftware.superiorskyblock.core.VarintArray;
import com.bgsoftware.superiorskyblock.core.logging.Debug;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.bgsoftware.superiorskyblock.core.mutable.MutableBoolean;
import com.bgsoftware.superiorskyblock.core.profiler.ProfileType;
import com.bgsoftware.superiorskyblock.core.profiler.Profiler;
import com.bgsoftware.superiorskyblock.core.schematic.SchematicBlock;
Expand Down Expand Up @@ -246,8 +247,17 @@ private void pasteSchematicAsyncInternal(Island island, Location location, long
List<CompletableFuture<Chunk>> chunkFutures = new ArrayList<>(affectedChunks.size());

AtomicBoolean failed = new AtomicBoolean(false);
MutableBoolean printedWarning = new MutableBoolean(false);

affectedChunks.forEach(chunkPosition -> {
if (!island.isInside(chunkPosition.getWorld(), chunkPosition.getX(), chunkPosition.getZ())) {
if (!printedWarning.get()) {
Log.warn("Part of the schematic ", name, " is placed outside of the island, skipping this part...");
printedWarning.set(true);
}
return;
}

chunkFutures.add(ChunksProvider.loadChunk(chunkPosition, ChunkLoadReason.SCHEMATIC_PLACE, chunk -> {
if (failed.get())
return;
Expand Down

0 comments on commit ff5e486

Please sign in to comment.