mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-17 02:04:04 +00:00
Further work on BlockState transition
This commit is contained in:
@@ -22,9 +22,7 @@ package com.sk89q.worldedit.regions.shape;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
@@ -35,45 +33,15 @@ import com.sk89q.worldedit.regions.Region;
|
||||
public abstract class ArbitraryShape {
|
||||
|
||||
protected final Region extent;
|
||||
private int cacheOffsetX;
|
||||
private int cacheOffsetY;
|
||||
private int cacheOffsetZ;
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private int cacheSizeX;
|
||||
private int cacheSizeY;
|
||||
private int cacheSizeZ;
|
||||
|
||||
public ArbitraryShape(Region extent) {
|
||||
this.extent = extent;
|
||||
|
||||
Vector min = extent.getMinimumPoint();
|
||||
Vector max = extent.getMaximumPoint();
|
||||
|
||||
cacheOffsetX = min.getBlockX() - 1;
|
||||
cacheOffsetY = min.getBlockY() - 1;
|
||||
cacheOffsetZ = min.getBlockZ() - 1;
|
||||
|
||||
cacheSizeX = (int) (max.getX() - cacheOffsetX + 2);
|
||||
cacheSizeY = (int) (max.getY() - cacheOffsetY + 2);
|
||||
cacheSizeZ = (int) (max.getZ() - cacheOffsetZ + 2);
|
||||
|
||||
cache = new short[cacheSizeX * cacheSizeY * cacheSizeZ];
|
||||
}
|
||||
|
||||
protected Region getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cache entries:
|
||||
* 0 = unknown
|
||||
* -1 = outside
|
||||
* -2 = inside but type and data 0
|
||||
* > 0 = inside, value = (type | (data << 8)), not handling data < 0
|
||||
*/
|
||||
private final short[] cache;
|
||||
|
||||
/**
|
||||
* Override this function to specify the shape to generate.
|
||||
*
|
||||
@@ -83,60 +51,7 @@ public abstract class ArbitraryShape {
|
||||
* @param defaultMaterial The material returned by the pattern for the current block.
|
||||
* @return material to place or null to not place anything.
|
||||
*/
|
||||
protected abstract BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial);
|
||||
|
||||
private BaseBlock getMaterialCached(int x, int y, int z, Pattern pattern) {
|
||||
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
|
||||
|
||||
final short cacheEntry = cache[index];
|
||||
switch (cacheEntry) {
|
||||
case 0:
|
||||
// unknown, fetch material
|
||||
final BaseBlock material = getMaterial(x, y, z, pattern.apply(new BlockVector(x, y, z)));
|
||||
if (material == null) {
|
||||
// outside
|
||||
cache[index] = -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
short newCacheEntry = (short) (material.getBlockType().getLegacyId() | ((material.getData() + 1) << 8));
|
||||
if (newCacheEntry == 0) {
|
||||
// type and data 0
|
||||
newCacheEntry = -2;
|
||||
}
|
||||
|
||||
cache[index] = newCacheEntry;
|
||||
return material;
|
||||
|
||||
case -1:
|
||||
// outside
|
||||
return null;
|
||||
|
||||
case -2:
|
||||
// type and data 0
|
||||
return new BaseBlock(BlockTypes.AIR);
|
||||
}
|
||||
|
||||
return new BaseBlock(cacheEntry & 255, ((cacheEntry >> 8) - 1) & 15);
|
||||
}
|
||||
|
||||
private boolean isInsideCached(int x, int y, int z, Pattern pattern) {
|
||||
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
|
||||
|
||||
switch (cache[index]) {
|
||||
case 0:
|
||||
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
|
||||
return getMaterialCached(x, y, z, pattern) != null;
|
||||
|
||||
case -1:
|
||||
// outside
|
||||
return false;
|
||||
|
||||
default:
|
||||
// inside
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected abstract BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial);
|
||||
|
||||
/**
|
||||
* Generates the shape.
|
||||
@@ -156,7 +71,7 @@ public abstract class ArbitraryShape {
|
||||
int z = position.getBlockZ();
|
||||
|
||||
if (!hollow) {
|
||||
final BaseBlock material = getMaterial(x, y, z, pattern.apply(position));
|
||||
final BlockStateHolder material = getMaterial(x, y, z, pattern.apply(position));
|
||||
if (material != null && editSession.setBlock(position, material)) {
|
||||
++affected;
|
||||
}
|
||||
@@ -164,43 +79,11 @@ public abstract class ArbitraryShape {
|
||||
continue;
|
||||
}
|
||||
|
||||
final BaseBlock material = getMaterialCached(x, y, z, pattern);
|
||||
final BlockStateHolder material = getMaterial(x, y, z, pattern.apply(position));
|
||||
if (material == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean draw = false;
|
||||
do {
|
||||
if (!isInsideCached(x + 1, y, z, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x - 1, y, z, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, y, z + 1, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, y, z - 1, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, y + 1, z, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, y - 1, z, pattern)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
if (!draw) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (editSession.setBlock(position, material)) {
|
||||
++affected;
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ package com.sk89q.worldedit.regions.shape;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,7 @@ public class RegionShape extends ArbitraryShape {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
||||
protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) {
|
||||
if (!this.extent.contains(new Vector(x, y, z))) {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user