mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
linear clipboard get block
This commit is contained in:
parent
6de30f8ed4
commit
1a48546f0c
@ -121,15 +121,25 @@ public class CPUOptimizedClipboard extends LinearClipboard {
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(int index) {
|
||||
char ordinal = states[index];
|
||||
BlockState state = BlockState.getFromOrdinal(ordinal);
|
||||
if (state.getMaterial().hasContainer()) {
|
||||
BlockState block = getBlock(index);
|
||||
if (block.getMaterial().hasContainer()) {
|
||||
CompoundTag nbt = getTag(index);
|
||||
if (nbt != null) {
|
||||
return state.toBaseBlock(nbt);
|
||||
return block.toBaseBlock(nbt);
|
||||
}
|
||||
}
|
||||
return state.toBaseBlock();
|
||||
return block.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int index) {
|
||||
char ordinal = states[index];
|
||||
return BlockState.getFromOrdinal(ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return getBlock(getIndex(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -307,58 +307,63 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||
try {
|
||||
int index = HEADER_SIZE + (getIndex(x, y, z) << 1);
|
||||
int combinedId = byteBuffer.getChar(index);
|
||||
BlockState state = BlockState.getFromOrdinal(combinedId);
|
||||
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
|
||||
CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z));
|
||||
return state.toBaseBlock(nbt);
|
||||
return toBaseBlock(getBlock(x, y, z), x, y, z);
|
||||
}
|
||||
|
||||
private BaseBlock toBaseBlock(BlockState state, int i) {
|
||||
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
|
||||
CompoundTag nbt;
|
||||
if (nbtMap.size() < 4) {
|
||||
nbt = null;
|
||||
for (Map.Entry<IntegerTrio, CompoundTag> entry : nbtMap.entrySet()) {
|
||||
IntegerTrio key = entry.getKey();
|
||||
int index = getIndex(key.x, key.y, key.z);
|
||||
if (index == i) {
|
||||
nbt = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int y = i / getArea();
|
||||
int newI = i - y * getArea();
|
||||
int z = newI / getWidth();
|
||||
int x = newI - z * getWidth();
|
||||
nbt = nbtMap.get(new IntegerTrio(x, y, z));
|
||||
}
|
||||
return state.toBaseBlock();
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return state.toBaseBlock(nbt);
|
||||
}
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) {
|
||||
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
|
||||
CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z));
|
||||
return state.toBaseBlock(nbt);
|
||||
}
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(int i) {
|
||||
return toBaseBlock(getBlock(i), i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int index) {
|
||||
try {
|
||||
int diskIndex = HEADER_SIZE + (i << 1);
|
||||
int diskIndex = HEADER_SIZE + (index << 1);
|
||||
char ordinal = byteBuffer.getChar(diskIndex);
|
||||
BlockState state = BlockState.getFromOrdinal(ordinal);
|
||||
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
|
||||
CompoundTag nbt;
|
||||
if (nbtMap.size() < 4) {
|
||||
nbt = null;
|
||||
for (Map.Entry<IntegerTrio, CompoundTag> entry : nbtMap.entrySet()) {
|
||||
IntegerTrio key = entry.getKey();
|
||||
int index = getIndex(key.x, key.y, key.z);
|
||||
if (index == i) {
|
||||
nbt = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// x + z * getWidth() + y * area;
|
||||
int y = i / getArea();
|
||||
int newI = i - y * getArea();
|
||||
int z = newI / getWidth();
|
||||
int x = newI - z * getWidth();
|
||||
nbt = nbtMap.get(new IntegerTrio(x, y, z));
|
||||
}
|
||||
if (nbt != null) {
|
||||
return state.toBaseBlock(nbt);
|
||||
}
|
||||
}
|
||||
return state.toBaseBlock();
|
||||
return BlockState.getFromOrdinal(ordinal);
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return getBlock(getIndex(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.io.Closeable;
|
||||
@ -29,6 +30,8 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
|
||||
|
||||
public abstract BaseBlock getFullBlock(int i);
|
||||
|
||||
public abstract BlockState getBlock(int i);
|
||||
|
||||
public abstract void setBiome(int index, BiomeType biome);
|
||||
|
||||
public abstract BiomeType getBiome(int index);
|
||||
|
@ -16,6 +16,7 @@ import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -227,16 +228,25 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(int index) {
|
||||
int combinedId = getOrdinal(index);
|
||||
BlockType type = BlockTypes.getFromStateId(combinedId);
|
||||
BaseBlock base = type.withStateId(combinedId).toBaseBlock();
|
||||
if (type.getMaterial().hasContainer()) {
|
||||
BlockState block = getBlock(index);
|
||||
if (block.getMaterial().hasContainer()) {
|
||||
CompoundTag nbt = getTag(index);
|
||||
if (nbt != null) {
|
||||
return base.toBaseBlock(nbt);
|
||||
return block.toBaseBlock(nbt);
|
||||
}
|
||||
}
|
||||
return base;
|
||||
return block.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int index) {
|
||||
int ordinal = getOrdinal(index);
|
||||
return BlockState.getFromOrdinal(ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
return getBlock(getIndex(x, y, z));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
|
Loading…
Reference in New Issue
Block a user