mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-10 06:48:34 +00:00
.
This commit is contained in:
@ -22,8 +22,14 @@ package com.sk89q.worldedit.math;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
@ -93,6 +99,42 @@ public abstract class BlockVector3 {
|
||||
return new MutableBlockVector3(getX(), getY(), z);
|
||||
}
|
||||
|
||||
public BlockVector3 toImmutable() {
|
||||
return BlockVector3.at(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the BlockVector3 to the north<br>
|
||||
* Normal use you would use north(this),
|
||||
* To avoid constructing a new Vector, pass e.g. north(some MutableBlockVector3)
|
||||
* There is no gaurantee it will use this provided vector
|
||||
* @param orDefault the vector to use as the result<br>
|
||||
* @return BlockVector3
|
||||
*/
|
||||
public BlockVector3 north(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX(), getY(), getZ() - 1);
|
||||
}
|
||||
|
||||
public BlockVector3 east(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX() + 1, getY(), getZ());
|
||||
}
|
||||
|
||||
public BlockVector3 south(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX(), getY(), getZ() + 1);
|
||||
}
|
||||
|
||||
public BlockVector3 west(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX() - 1, getY(), getZ());
|
||||
}
|
||||
|
||||
public BlockVector3 up(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX(), getY() + 1, getZ());
|
||||
}
|
||||
|
||||
public BlockVector3 down(BlockVector3 orDefault) {
|
||||
return orDefault.setComponents(getX(), getY() - 1, getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X coordinate.
|
||||
*
|
||||
@ -576,6 +618,69 @@ public abstract class BlockVector3 {
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
Methods for getting/setting blocks
|
||||
|
||||
Why are these methods here?
|
||||
- Getting a block at a position requires various operations
|
||||
(bounds checks, cache checks, ensuring loaded chunk, get ChunkSection, etc.)
|
||||
- When iterating over a region, it will provide custom BlockVector3 positions
|
||||
- These override the below set/get and avoid lookups (as the iterator shifts it to the chunk level)
|
||||
*/
|
||||
|
||||
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
||||
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
|
||||
}
|
||||
|
||||
public boolean setBlock(Extent orDefault, BlockState state) {
|
||||
return orDefault.setBlock(this, state);
|
||||
}
|
||||
|
||||
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
||||
return orDefault.setBlock(this, block);
|
||||
}
|
||||
|
||||
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
||||
return orDefault.setBiome(getX(), getY(), getZ(), biome);
|
||||
}
|
||||
|
||||
public int getOrdinal(Extent orDefault) {
|
||||
return getBlock(orDefault).getOrdinal();
|
||||
}
|
||||
|
||||
public char getOrdinalChar(Extent orDefault) {
|
||||
return (char) getOrdinal(orDefault);
|
||||
}
|
||||
|
||||
public BlockState getBlock(Extent orDefault) {
|
||||
return orDefault.getBlock(this);
|
||||
}
|
||||
|
||||
public BaseBlock getFullBlock(Extent orDefault) {
|
||||
return orDefault.getFullBlock(this);
|
||||
}
|
||||
|
||||
public CompoundTag getNbtData(Extent orDefault) {
|
||||
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
|
||||
}
|
||||
|
||||
public BlockState getOrdinalBelow(Extent orDefault) {
|
||||
return orDefault.getBlock(getX(), getY() - 1, getZ());
|
||||
}
|
||||
|
||||
public BlockState getStateAbove(Extent orDefault) {
|
||||
return orDefault.getBlock(getX(), getY() + 1, getZ());
|
||||
}
|
||||
|
||||
public BlockState getStateRelativeY(Extent orDefault, final int y) {
|
||||
return orDefault.getBlock(getX(), getY() + y, getZ());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Adapt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a 2D vector by dropping the Y component from this vector.
|
||||
*
|
||||
|
@ -29,7 +29,7 @@ import java.util.Comparator;
|
||||
/**
|
||||
* An immutable 3-dimensional vector.
|
||||
*/
|
||||
public class BlockVector3Imp extends BlockVector3 {
|
||||
public final class BlockVector3Imp extends BlockVector3 {
|
||||
|
||||
public static final BlockVector3Imp ZERO = new BlockVector3Imp(0, 0, 0);
|
||||
public static final BlockVector3Imp UNIT_X = new BlockVector3Imp(1, 0, 0);
|
||||
@ -80,6 +80,11 @@ public class BlockVector3Imp extends BlockVector3 {
|
||||
return (getX() ^ (getZ() << 12)) ^ (getY() << 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockVector3 toImmutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
|
||||
|
@ -1,13 +1,8 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
public class MutableBlockVector3 extends BlockVector3 {
|
||||
import com.boydti.fawe.FaweCache;
|
||||
|
||||
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector3>() {
|
||||
@Override
|
||||
protected MutableBlockVector3 initialValue() {
|
||||
return new MutableBlockVector3();
|
||||
}
|
||||
};
|
||||
public class MutableBlockVector3 extends BlockVector3 {
|
||||
|
||||
public static MutableBlockVector3 at(double x, double y, double z) {
|
||||
return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
|
||||
@ -18,7 +13,7 @@ public class MutableBlockVector3 extends BlockVector3 {
|
||||
}
|
||||
|
||||
public static MutableBlockVector3 get(int x, int y, int z) {
|
||||
return MUTABLE_CACHE.get().setComponents(x, y, z);
|
||||
return FaweCache.MUTABLE_BLOCKVECTOR3.get().setComponents(x, y, z);
|
||||
}
|
||||
|
||||
public MutableBlockVector3() {}
|
||||
|
@ -1,9 +1,20 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MutableVector3 extends Vector3 {
|
||||
|
||||
public static MutableVector3 get(int x, int y, int z) {
|
||||
return FaweCache.MUTABLE_VECTOR3.get().setComponents(x, y, z);
|
||||
}
|
||||
|
||||
public static MutableVector3 get(double x, double y, double z) {
|
||||
return FaweCache.MUTABLE_VECTOR3.get().setComponents(x, y, z);
|
||||
}
|
||||
|
||||
public MutableVector3() {}
|
||||
|
||||
public MutableVector3(double x, double y, double z) {
|
||||
|
Reference in New Issue
Block a user