3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

Add loadIfPresent method foor use where the section should definitely exist and be FULL

Dieser Commit ist enthalten in:
dordsor21 2021-09-12 11:32:20 +01:00
Ursprung 6f180421e1
Commit 5a9ad2e689
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
6 geänderte Dateien mit 53 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -61,8 +61,9 @@ public class HeightmapProcessor implements IBatchProcessor {
if (!(hasSectionSet || hasSectionGet)) { if (!(hasSectionSet || hasSectionGet)) {
continue; continue;
} }
char[] setSection = hasSectionSet ? set.load(layer) : null; char[] setSection = hasSectionSet ? set.loadIfPresent(layer) : null;
if (Arrays.equals(setSection, FaweCache.IMP.EMPTY_CHAR_4096) || Arrays.equals(setSection, AIR_LAYER)) { if (setSection == null || Arrays.equals(setSection, FaweCache.IMP.EMPTY_CHAR_4096) ||
Arrays.equals(setSection, AIR_LAYER)) {
hasSectionSet = false; hasSectionSet = false;
} }
if (!hasSectionSet && !hasSectionGet) { if (!hasSectionSet && !hasSectionGet) {

Datei anzeigen

@ -33,6 +33,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -170,7 +171,8 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
System.arraycopy(tmp, 0, (blocksGet = new char[4096]), 0, 4096); System.arraycopy(tmp, 0, (blocksGet = new char[4096]), 0, 4096);
} }
char[] blocksSet; char[] blocksSet;
System.arraycopy(set.load(layer), 0, (blocksSet = new char[4096]), 0, 4096); // loadIfPresent shouldn't be null if set.hasSection(layer) is true
System.arraycopy(Objects.requireNonNull(set.loadIfPresent(layer)), 0, (blocksSet = new char[4096]), 0, 4096);
// Account for negative layers // Account for negative layers
int by = layer << 4; int by = layer << 4;

Datei anzeigen

@ -44,10 +44,14 @@ public interface IBatchProcessor {
for (int layer = set.getMinSectionPosition(); layer <= minLayer; layer++) { for (int layer = set.getMinSectionPosition(); layer <= minLayer; layer++) {
if (set.hasSection(layer)) { if (set.hasSection(layer)) {
if (layer == minLayer) { if (layer == minLayer) {
char[] arr = set.load(layer); char[] arr = set.loadIfPresent(layer);
int index = (minY & 15) << 8; if (arr != null) {
for (int i = 0; i < index; i++) { int index = (minY & 15) << 8;
arr[i] = 0; for (int i = 0; i < index; i++) {
arr[i] = 0;
}
} else {
arr = new char[4096];
} }
set.setBlocks(layer, arr); set.setBlocks(layer, arr);
} else { } else {
@ -59,10 +63,14 @@ public interface IBatchProcessor {
for (int layer = maxLayer; layer < set.getMaxSectionPosition(); layer++) { for (int layer = maxLayer; layer < set.getMaxSectionPosition(); layer++) {
if (set.hasSection(layer)) { if (set.hasSection(layer)) {
if (layer == minLayer) { if (layer == minLayer) {
char[] arr = set.load(layer); char[] arr = set.loadIfPresent(layer);
int index = ((maxY + 1) & 15) << 8; if (arr != null) {
for (int i = index; i < arr.length; i++) { int index = ((maxY + 1) & 15) << 8;
arr[i] = 0; for (int i = index; i < arr.length; i++) {
arr[i] = 0;
}
} else {
arr = new char[4096];
} }
set.setBlocks(layer, arr); set.setBlocks(layer, arr);
} else { } else {

Datei anzeigen

@ -12,6 +12,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -31,8 +32,26 @@ public interface IBlocks extends Trimable {
*/ */
boolean hasSection(int layer); boolean hasSection(int layer);
/**
* Obtain the specified chunk section stored as an array of ordinals. Uses normal minecraft chunk-section position indices
* (length 4096). Operations synchronises on the section and will load the section into memory if not present. For chunk
* GET operations, this will load the data from the world. For chunk SET, this will create a new empty array.
*
* @param layer chunk section layer (may be negative)
* @return char array of ordinals of the chunk section
*/
char[] load(int layer); char[] load(int layer);
/**
* Obtain the specified chunk section stored as an array of ordinals if present or null. Uses normal minecraft chunk-section
* position indices (length 4096). Does not synchronise to the section layer as it will not attempt to load into memory.
*
* @param layer chunk section layer (may be negative)
* @return char array of ordinals of the chunk section if present
*/
@Nullable
char[] loadIfPresent(int layer);
BlockState getBlock(int x, int y, int z); BlockState getBlock(int x, int y, int z);
Map<BlockVector3, CompoundTag> getTiles(); Map<BlockVector3, CompoundTag> getTiles();

Datei anzeigen

@ -145,6 +145,16 @@ public abstract class CharBlocks implements IBlocks {
} }
} }
@Nullable
@Override
public char[] loadIfPresent(int layer) {
if (layer < minSectionPosition || layer > minSectionPosition) {
return null;
}
layer -= minSectionPosition;
return sections[layer].isFull() ? blocks[layer] : null;
}
@Override @Override
public BlockState getBlock(int x, int y, int z) { public BlockState getBlock(int x, int y, int z) {
return BlockTypesCache.states[get(x, y, z)]; return BlockTypesCache.states[get(x, y, z)];

Datei anzeigen

@ -37,6 +37,7 @@ import javax.annotation.Nonnull;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@ -769,7 +770,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int layer = get.getMinSectionPosition(); layer < get.getMaxSectionPosition(); layer++) { for (int layer = get.getMinSectionPosition(); layer < get.getMaxSectionPosition(); layer++) {
if (set.hasSection(layer)) { if (set.hasSection(layer)) {
char[] arr = set.load(layer); char[] arr = Objects.requireNonNull(set.loadIfPresent(layer)); // This shouldn't be null if above is true
if (trimX || trimZ) { if (trimX || trimZ) {
int indexY = 0; int indexY = 0;
for (int y = 0; y < 16; y++, indexY += 256) { // For each y layer within a chunk section for (int y = 0; y < 16; y++, indexY += 256) { // For each y layer within a chunk section