mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-10 04:28:35 +00:00
upstream changes
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
public final class BitMath {
|
||||
|
||||
public static int mask(int bits) {
|
||||
return ~(~0 << bits);
|
||||
}
|
||||
|
||||
public static int unpackX(long packed) {
|
||||
return extractSigned(packed, 0, 26);
|
||||
}
|
||||
|
||||
public static int unpackZ(long packed) {
|
||||
return extractSigned(packed, 26, 26);
|
||||
}
|
||||
|
||||
public static int unpackY(long packed) {
|
||||
return extractSigned(packed, 26 + 26, 12);
|
||||
}
|
||||
|
||||
public static int extractSigned(long i, int shift, int bits) {
|
||||
return fixSign((int) (i >> shift) & mask(bits), bits);
|
||||
}
|
||||
|
||||
public static int fixSign(int i, int bits) {
|
||||
// Using https://stackoverflow.com/a/29266331/436524
|
||||
return i << (32 - bits) >> (32 - bits);
|
||||
}
|
||||
|
||||
private BitMath() {
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,10 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.sk89q.worldedit.math.BitMath.mask;
|
||||
import static com.sk89q.worldedit.math.BitMath.unpackX;
|
||||
import static com.sk89q.worldedit.math.BitMath.unpackY;
|
||||
import static com.sk89q.worldedit.math.BitMath.unpackZ;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -67,6 +71,31 @@ public abstract class BlockVector3 {
|
||||
return new BlockVector3Imp(x, y, z);
|
||||
}
|
||||
|
||||
private static final int WORLD_XZ_MINMAX = 30_000_000;
|
||||
private static final int WORLD_Y_MAX = 4095;
|
||||
|
||||
private static boolean isHorizontallyInBounds(int h) {
|
||||
return -WORLD_XZ_MINMAX <= h && h <= WORLD_XZ_MINMAX;
|
||||
}
|
||||
|
||||
public static boolean isLongPackable(BlockVector3 location) {
|
||||
return isHorizontallyInBounds(location.getX()) &&
|
||||
isHorizontallyInBounds(location.getZ()) &&
|
||||
0 <= location.getY() && location.getY() <= WORLD_Y_MAX;
|
||||
}
|
||||
|
||||
public static void checkLongPackable(BlockVector3 location) {
|
||||
checkArgument(isLongPackable(location),
|
||||
"Location exceeds long packing limits: %s", location);
|
||||
}
|
||||
|
||||
private static final long BITS_26 = mask(26);
|
||||
private static final long BITS_12 = mask(12);
|
||||
|
||||
public static BlockVector3 fromLongPackedForm(long packed) {
|
||||
return at(unpackX(packed), unpackY(packed), unpackZ(packed));
|
||||
}
|
||||
|
||||
// thread-safe initialization idiom
|
||||
private static final class YzxOrderComparator {
|
||||
|
||||
@ -154,6 +183,11 @@ public abstract class BlockVector3 {
|
||||
// return orDefault.setComponents(getX(), getY() - 1, getZ());
|
||||
// }
|
||||
|
||||
public long toLongPackedForm() {
|
||||
checkLongPackable(this);
|
||||
return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & (long) BITS_12) << (26 + 26)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X coordinate.
|
||||
*
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import static com.sk89q.worldedit.math.BlockVector2.COMPARING_GRID_ARRANGEMENT;
|
||||
|
||||
/**
|
||||
* Sort block positions by region, then chunk.
|
||||
*/
|
||||
public class RegionOptimizedChunkComparator {
|
||||
|
||||
private static final Comparator<BlockVector2> CHUNK_COMPARATOR =
|
||||
Comparator.comparing((BlockVector2 chunkPos) -> chunkPos.shr(5), COMPARING_GRID_ARRANGEMENT)
|
||||
.thenComparing(COMPARING_GRID_ARRANGEMENT);
|
||||
|
||||
public static final Comparator<BlockVector3> INSTANCE
|
||||
= Comparator.comparing(blockPos -> blockPos.toBlockVector2().shr(4), CHUNK_COMPARATOR);
|
||||
|
||||
private RegionOptimizedChunkComparator() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Sort block positions by region, chunk, and finally Y-Z-X.
|
||||
*/
|
||||
public class RegionOptimizedComparator {
|
||||
|
||||
public static final Comparator<BlockVector3> INSTANCE
|
||||
= RegionOptimizedChunkComparator.INSTANCE
|
||||
.thenComparing(BlockVector3.sortByCoordsYzx());
|
||||
|
||||
private RegionOptimizedComparator() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user