Add back statically-set reserved IDs for air blocks only, make it clear they're "reserved" (#1502)

* Add back statically-set reserved IDs for air blocks only, make it clear they're "reserved"
Also:
 - Ensure that reserved is never returned in GET block operations
 - "empty" thus doesn't exist in the GET update methods; remove the needless checks
 - Allow GET/SET chunks to determine their own default values for non-present blocks/sections

* Add comments
This commit is contained in:
Jordan
2021-12-29 16:17:20 +01:00
committed by GitHub
parent bca3a1b04d
commit 177d731957
13 changed files with 109 additions and 117 deletions

View File

@ -425,7 +425,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
);
return 0;
return BlockTypesCache.ReservedIDs.AIR;
}
}
}

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import net.minecraft.core.BlockPos;
@ -844,16 +845,16 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
// Section is null, return empty array
if (section == null) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
return data;
}
if (data != null && data.length != 4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
}
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
}
DelegateSemaphore lock = PaperweightPlatformAdapter.applyLock(section);
synchronized (lock) {
@ -878,8 +879,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
for (int i = 0; i < 4096; i++) {
char paletteVal = data[i];
char ordinal = adapter.ibdIDToOrdinal(paletteVal);
// Don't read "empty".
data[i] = ordinal == 0 ? 1 : ordinal;
data[i] = ordinal;
}
return data;
}
@ -898,18 +898,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
val = ordinal(palette.valueFor(i), adapter);
paletteToOrdinal[i] = val;
}
// Don't read "empty".
if (val == 0) {
val = 1;
}
data[i] = val;
}
} else {
char ordinal = ordinal(palette.valueFor(0), adapter);
// Don't read "empty".
if (ordinal == 0) {
ordinal = 1;
}
Arrays.fill(data, ordinal);
}
} finally {
@ -929,7 +921,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) {
if (ibd == null) {
return 1;
return BlockTypesCache.ReservedIDs.AIR;
} else {
return adapter.adaptToChar(ibd);
}

View File

@ -420,7 +420,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
);
return 0;
return BlockTypesCache.ReservedIDs.AIR;
}
}
}

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import net.minecraft.core.BlockPos;
@ -874,16 +875,16 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
// Section is null, return empty array
if (section == null) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
return data;
}
if (data != null && data.length != 4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
}
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
}
DelegateSemaphore lock = PaperweightPlatformAdapter.applyLock(section);
synchronized (lock) {
@ -915,8 +916,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
for (int i = 0; i < 4096; i++) {
char paletteVal = data[i];
char ordinal = adapter.ibdIDToOrdinal(paletteVal);
// Don't read "empty".
data[i] = ordinal == 0 ? 1 : ordinal;
data[i] = ordinal;
}
return data;
}
@ -935,18 +935,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
val = ordinal(palette.valueFor(i), adapter);
paletteToOrdinal[i] = val;
}
// Don't read "empty".
if (val == 0) {
val = 1;
}
data[i] = val;
}
} else {
char ordinal = ordinal(palette.valueFor(0), adapter);
// Don't read "empty".
if (ordinal == 0) {
ordinal = 1;
}
Arrays.fill(data, ordinal);
}
} finally {
@ -966,7 +958,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) {
if (ibd == null) {
return 1;
return BlockTypesCache.ReservedIDs.AIR;
} else {
return adapter.adaptToChar(ibd);
}

View File

@ -23,8 +23,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
int num_palette = 0;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == 0) {
ordinal = 1;
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
@ -48,11 +48,11 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case 0:
ordinal = 1;
case 1:
case 2:
case 3:
case BlockTypesCache.ReservedIDs.__RESERVED__:
ordinal = BlockTypesCache.ReservedIDs.AIR;
case BlockTypesCache.ReservedIDs.AIR:
case BlockTypesCache.ReservedIDs.CAVE_AIR:
case BlockTypesCache.ReservedIDs.VOID_AIR:
air++;
break;
default:
@ -94,13 +94,13 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
char[] getArr = null;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == 0) {
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
if (getArr == null) {
getArr = get.apply(layer);
}
ordinal = getArr[i];
if (ordinal == 0) {
ordinal = 1;
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
}
int palette = blockToPalette[ordinal];
@ -119,24 +119,24 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
}
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
}
char lastOrdinal = 0;
char lastOrdinal = BlockTypesCache.ReservedIDs.__RESERVED__;
boolean lastticking = false;
boolean tick_placed = Settings.settings().EXPERIMENTAL.ALLOW_TICK_PLACED;
boolean tick_existing = Settings.settings().EXPERIMENTAL.ALLOW_TICK_EXISTING;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case 0: {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
if (getArr == null) {
getArr = get.apply(layer);
}
ordinal = getArr[i];
switch (ordinal) {
case 0:
ordinal = 1;
case 1:
case 2:
case 3:
case BlockTypesCache.ReservedIDs.__RESERVED__:
ordinal = BlockTypesCache.ReservedIDs.AIR;
case BlockTypesCache.ReservedIDs.AIR:
case BlockTypesCache.ReservedIDs.CAVE_AIR:
case BlockTypesCache.ReservedIDs.VOID_AIR:
air++;
break;
default:
@ -151,23 +151,19 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
}
if (ticking) {
BlockState state = BlockState.getFromOrdinal(ordinal);
ticking_blocks
.put(
BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
WorldEditPlugin.getInstance().getBukkitImplAdapter()
.getInternalBlockStateId(state).orElse(0)
);
ticking_blocks.put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
WorldEditPlugin
.getInstance()
.getBukkitImplAdapter()
.getInternalBlockStateId(state)
.orElse(0)
);
}
}
}
set[i] = ordinal;
break;
}
case 1:
case 2:
case 3:
air++;
break;
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> air++;
}
if (!fastmode && tick_placed) {
boolean ticking;