chore: replace some hardcoded ordinals

Dieser Commit ist enthalten in:
dordsor21 2023-06-05 00:17:13 +01:00
Ursprung 46e8a37cf0
Commit e5d27c27bb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
12 geänderte Dateien mit 39 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -11,6 +11,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@ -191,8 +192,8 @@ public class CPUOptimizedClipboard extends LinearClipboard {
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) { public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
char ordinal = block.getOrdinalChar(); char ordinal = block.getOrdinalChar();
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = 1; ordinal = BlockTypesCache.ReservedIDs.AIR;
} }
states[index] = ordinal; states[index] = ordinal;
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -696,8 +697,8 @@ public class DiskOptimizedClipboard extends LinearClipboard {
try { try {
int index = headerSize + (getIndex(x, y, z) << 1); int index = headerSize + (getIndex(x, y, z) << 1);
char ordinal = block.getOrdinalChar(); char ordinal = block.getOrdinalChar();
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = 1; ordinal = BlockTypesCache.ReservedIDs.AIR;
} }
byteBuffer.putChar(index, ordinal); byteBuffer.putChar(index, ordinal);
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();

Datei anzeigen

@ -16,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@ -269,8 +270,8 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) { public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
int ordinal = block.getOrdinal(); int ordinal = block.getOrdinal();
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = 1; ordinal = BlockTypesCache.ReservedIDs.AIR;
} }
setOrdinal(index, ordinal); setOrdinal(index, ordinal);
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();

Datei anzeigen

@ -172,8 +172,8 @@ public class FastSchematicWriter implements ClipboardWriter {
} }
int ordinal = block.getOrdinal(); int ordinal = block.getOrdinal();
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = 1; ordinal = BlockTypesCache.ReservedIDs.AIR;
} }
char value = palette[ordinal]; char value = palette[ordinal];
if (value == Character.MAX_VALUE) { if (value == Character.MAX_VALUE) {

Datei anzeigen

@ -41,8 +41,8 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
@Override @Override
public final void applyBlock(FilterBlock block) { public final void applyBlock(FilterBlock block) {
int ordinal = block.getOrdinal(); int ordinal = block.getOrdinal();
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = 1; ordinal = BlockTypesCache.ReservedIDs.AIR;
} }
counter[ordinal]++; counter[ordinal]++;
} }

Datei anzeigen

@ -73,11 +73,11 @@ public class HeightmapProcessor implements IBatchProcessor {
for (int y = 15; y >= 0; y--) { for (int y = 15; y >= 0; y--) {
// We don't need to actually iterate over x and z as we're both reading and writing an index // We don't need to actually iterate over x and z as we're both reading and writing an index
for (int j = 0; j < BLOCKS_PER_Y; j++) { for (int j = 0; j < BLOCKS_PER_Y; j++) {
char ordinal = 0; char ordinal = BlockTypesCache.ReservedIDs.__RESERVED__;
if (hasSectionSet) { if (hasSectionSet) {
ordinal = setSection[index(y, j)]; ordinal = setSection[index(y, j)];
} }
if (ordinal == 0) { if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
if (!hasSectionGet) { if (!hasSectionGet) {
if (!hasSectionSet) { if (!hasSectionSet) {
continue layer; continue layer;

Datei anzeigen

@ -5,6 +5,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
public class MutableBiomeChange implements Change { public class MutableBiomeChange implements Change {
@ -13,8 +14,8 @@ public class MutableBiomeChange implements Change {
private int to; private int to;
public MutableBiomeChange() { public MutableBiomeChange() {
this.from = 0; this.from = BlockTypesCache.ReservedIDs.__RESERVED__;
this.to = 0; this.to = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
public void setBiome(int x, int y, int z, int from, int to) { public void setBiome(int x, int y, int z, int from, int to) {

Datei anzeigen

@ -6,6 +6,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
public class MutableFullBlockChange implements Change { public class MutableFullBlockChange implements Change {
@ -39,14 +40,14 @@ public class MutableFullBlockChange implements Change {
if (blockBag != null) { if (blockBag != null) {
BlockState toState = BlockState.getFromOrdinal(to); BlockState toState = BlockState.getFromOrdinal(to);
if (fromState != toState) { if (fromState != toState) {
if (allowFetch && from != 0) { if (allowFetch && from != BlockTypesCache.ReservedIDs.__RESERVED__) {
try { try {
blockBag.fetchPlacedBlock(fromState); blockBag.fetchPlacedBlock(fromState);
} catch (BlockBagException e) { } catch (BlockBagException e) {
return; return;
} }
} }
if (allowStore && to != 0) { if (allowStore && to != BlockTypesCache.ReservedIDs.__RESERVED__) {
try { try {
blockBag.storeDroppedBlock(toState); blockBag.storeDroppedBlock(toState);
} catch (BlockBagException ignored) { } catch (BlockBagException ignored) {

Datei anzeigen

@ -186,7 +186,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
} }
final int combinedFrom = from; final int combinedFrom = from;
final int combinedTo = blocksSet[index]; final int combinedTo = blocksSet[index];
if (combinedTo != 0) { if (combinedTo != BlockTypesCache.ReservedIDs.__RESERVED__) {
add(xx, yy, zz, combinedFrom, combinedTo); add(xx, yy, zz, combinedFrom, combinedTo);
} }
} }

Datei anzeigen

@ -7,6 +7,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
@ -71,7 +72,7 @@ public interface IBatchProcessor {
if (arr != null) { if (arr != null) {
int index = (minY & 15) << 8; int index = (minY & 15) << 8;
for (int i = 0; i < index; i++) { for (int i = 0; i < index; i++) {
arr[i] = 0; arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} else { } else {
arr = new char[4096]; arr = new char[4096];
@ -89,7 +90,7 @@ public interface IBatchProcessor {
if (arr != null) { if (arr != null) {
int index = ((maxY + 1) & 15) << 8; int index = ((maxY + 1) & 15) << 8;
for (int i = index; i < arr.length; i++) { for (int i = index; i < arr.length; i++) {
arr[i] = 0; arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} else { } else {
arr = new char[4096]; arr = new char[4096];
@ -130,7 +131,7 @@ public interface IBatchProcessor {
if (arr != null) { if (arr != null) {
int index = (minY & 15) << 8; int index = (minY & 15) << 8;
for (int i = index; i < 4096; i++) { for (int i = index; i < 4096; i++) {
arr[i] = 0; arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
set.setBlocks(layer, arr); set.setBlocks(layer, arr);
@ -139,7 +140,7 @@ public interface IBatchProcessor {
if (arr != null) { if (arr != null) {
int index = ((maxY + 1) & 15) << 8; int index = ((maxY + 1) & 15) << 8;
for (int i = 0; i < index; i++) { for (int i = 0; i < index; i++) {
arr[i] = 0; arr[i] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
set.setBlocks(layer, arr); set.setBlocks(layer, arr);

Datei anzeigen

@ -31,6 +31,7 @@ import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.storage.ChunkStore; import com.sk89q.worldedit.world.storage.ChunkStore;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -839,14 +840,14 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int z = 0; z < lowerZ; z++) { for (int z = 0; z < lowerZ; z++) {
// null the z values // null the z values
for (int x = 0; x < 16; x++, index++) { for (int x = 0; x < 16; x++, index++) {
arr[index] = 0; arr[index] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
index = indexY + upperZi; index = indexY + upperZi;
for (int z = upperZ + 1; z < 16; z++) { for (int z = upperZ + 1; z < 16; z++) {
// null the z values // null the z values
for (int x = 0; x < 16; x++, index++) { for (int x = 0; x < 16; x++, index++) {
arr[index] = 0; arr[index] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
} }
@ -855,11 +856,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int z = lowerZ; z <= upperZ; z++, index += 16) { for (int z = lowerZ; z <= upperZ; z++, index += 16) {
for (int x = 0; x < lowerX; x++) { for (int x = 0; x < lowerX; x++) {
// null the x values // null the x values
arr[index + x] = 0; arr[index + x] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
for (int x = upperX + 1; x < 16; x++) { for (int x = upperX + 1; x < 16; x++) {
// null the x values // null the x values
arr[index + x] = 0; arr[index + x] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
} }
@ -925,7 +926,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int z = lowerZ; z <= upperZ; z++) { for (int z = lowerZ; z <= upperZ; z++) {
// null the z values // null the z values
for (int x = 0; x < 16; x++, index++) { for (int x = 0; x < 16; x++, index++) {
arr[index] = 0; arr[index] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
} }
@ -934,7 +935,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int z = lowerZ; z <= upperZ; z++, index += 16) { for (int z = lowerZ; z <= upperZ; z++, index += 16) {
for (int x = lowerX; x <= upperX; x++) { for (int x = lowerX; x <= upperX; x++) {
// null the x values // null the x values
arr[index + x] = 0; arr[index + x] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
} }

Datei anzeigen

@ -38,6 +38,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
@ -408,8 +409,8 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
for (int y = 0, index = 0; y < 16; y++) { for (int y = 0, index = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) { for (int x = 0; x < 16; x++, index++) {
if (arr[index] != 0 && !contains(x, y, z)) { if (arr[index] != BlockTypesCache.ReservedIDs.__RESERVED__ && !contains(x, y, z)) {
arr[index] = 0; arr[index] = BlockTypesCache.ReservedIDs.__RESERVED__;
} }
} }
} }
@ -458,8 +459,8 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
for (int y = 0, index = 0; y < 16; y++) { for (int y = 0, index = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) { for (int x = 0; x < 16; x++, index++) {
if (arr[index] != 0 && contains(x, y, z)) { if (arr[index] != BlockTypesCache.ReservedIDs.__RESERVED__ && contains(x, y, z)) {
arr[index] = 0; arr[index] = BlockTypesCache.ReservedIDs.__RESERVED__;
processExtra = true; processExtra = true;
} }
} }