3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-02 17:40:09 +01:00

Changes to NBT-handling in operations and extents, changes to match the widely supported setBlock functionality, minor code cleanup

Dieser Commit ist enthalten in:
IronApollo 2019-03-25 13:31:12 -04:00
Ursprung 16c22b75da
Commit 3236bdd78e
57 geänderte Dateien mit 347 neuen und 417 gelöschten Zeilen

Datei anzeigen

@ -73,7 +73,6 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
private final Field nbtListTagListField;
private final Method nbtCreateTagMethod;
private Method chunkSetTypeMethod;
static {
// A simple test
@ -92,13 +91,6 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
// The method to create an NBTBase tag given its type ID
nbtCreateTagMethod = NBTBase.class.getDeclaredMethod("createTag", byte.class);
nbtCreateTagMethod.setAccessible(true);
// 1.13.2 Adaptation to find the a/setType method
try {
chunkSetTypeMethod = Chunk.class.getMethod("setType", BlockPosition.class, IBlockData.class, boolean.class);
}catch(NoSuchMethodException e) {
chunkSetTypeMethod = Chunk.class.getMethod("a", BlockPosition.class, IBlockData.class, boolean.class);
}
}
private int[] idbToStateOrdinal;
@ -217,7 +209,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@SuppressWarnings("deprecation")
@Override
public BlockState getBlock(Location location) {
public BaseBlock getBlock(Location location) {
checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
@ -233,11 +225,11 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
if (te != null) {
NBTTagCompound tag = new NBTTagCompound();
readTileEntityIntoTag(te, tag); // Load data
return new BaseBlock(state, (CompoundTag) toNative(tag)).toImmutableState();
return new BaseBlock(state, (CompoundTag) toNative(tag));
}
}
return state;
return state.toBaseBlock();
}
@Override
@ -265,7 +257,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
existing = section.getType(x & 15, y & 15, z & 15);
}
BlockPosition pos = null;
CompoundTag nativeTag = state.getNbtData();
CompoundTag nativeTag = state instanceof BaseBlock ? ((BaseBlock)state).getNbtData() : null;
if (nativeTag != null || existing instanceof TileEntityBlock) {
pos = new BlockPosition(x, y, z);
nmsWorld.setTypeAndData(pos, blockData, 0);
@ -289,12 +281,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
sections[y4] = section = new ChunkSection(y4 << 4, nmsWorld.worldProvider.g());
}
if (existing.e() != blockData.e() || existing.getMaterial().f() != blockData.getMaterial().f()) {
try {
chunkSetTypeMethod.invoke(nmsChunk, pos = new BlockPosition(x, y, z), blockData, false);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
logger.warning("Error when setting block!");
e.printStackTrace();
}
nmsChunk.setType(pos = new BlockPosition(x, y, z), blockData, false);
} else {
section.setType(x & 15, y & 15, z & 15, blockData);
}

Datei anzeigen

@ -356,12 +356,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
}
public void setBlock(BukkitImplAdapter adapter, Chunk chunk, Location location, int combinedId, boolean update) {
com.sk89q.worldedit.world.block.BlockState state = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId);
com.sk89q.worldedit.world.block.BaseBlock base = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId).toBaseBlock();
if (adapter != null) {
adapter.setBlock(chunk, (int) location.getX(), (int) location.getY(), (int) location.getZ(), state, update);
adapter.setBlock(chunk, (int) location.getX(), (int) location.getY(), (int) location.getZ(), base, update);
} else {
Block block = location.getWorld().getBlockAt(location);
block.setBlockData(BukkitAdapter.adapt(state), false);
block.setBlockData(BukkitAdapter.adapt(base), false);
}
}
}

Datei anzeigen

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Chunk;
@ -333,7 +334,7 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
return null;
}
Location loc = new Location(getWorld(), x, y, z);
BlockStateHolder block = getAdapter().getBlock(loc);
BaseBlock block = getAdapter().getBlock(loc);
return block.getNbtData();
}

Datei anzeigen

@ -1,5 +1,4 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
@ -461,9 +460,9 @@ public class BukkitWorld extends AbstractWorld {
int z = position.getBlockZ();
return adapter.setBlock(getWorld().getChunkAt(x >> 4, z >> 4), x, y, z, block, true);
} catch (Exception e) {
if (block.getNbtData() != null) {
if (block instanceof BaseBlock && ((BaseBlock)block).getNbtData() != null) {
logger.warning("Tried to set a corrupt tile entity at " + position.toString());
logger.warning(block.getNbtData().toString());
logger.warning(((BaseBlock)block).getNbtData().toString());
}
e.printStackTrace();
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
@ -486,7 +485,7 @@ public class BukkitWorld extends AbstractWorld {
public BaseBlock getFullBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toBaseBlock();
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
} else {
return getBlock(position).toBaseBlock();
}

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.BaseEntity;
@ -70,7 +71,7 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param location the location
* @return the block
*/
BlockState getBlock(Location location);
BaseBlock getBlock(Location location);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder<?> state, boolean update);

Datei anzeigen

@ -79,7 +79,7 @@ public class LazyBlock extends BaseBlock {
@Override
public CompoundTag getNbtData() {
if (!loaded) {
BlockState loadedBlock = extent.getFullBlock(position).toImmutableState();
BaseBlock loadedBlock = extent.getFullBlock(position);
this.nbtData = loadedBlock.getNbtData();
loaded = true;
}

Datei anzeigen

@ -200,7 +200,7 @@ public class SchematicStreamer extends NBTStreamer {
private void fixStates() {
fc.forEach(new FaweClipboard.BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
BlockType type = block.getBlockType();
switch (type.getResource().toUpperCase()) {
case "ACACIA_STAIRS":

Datei anzeigen

@ -7,6 +7,7 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
@ -60,7 +61,7 @@ public class MCAWorld implements SimpleWorld {
@Override
public boolean clearContainerBlockContents(BlockVector3 position) {
BlockStateHolder block = extent.getLazyBlock(position);
BaseBlock block = extent.getFullBlock(position);
if (block.hasNbtData()) {
Map<String, Tag> nbt = ReflectionUtils.getMap(block.getNbtData().getValue());
if (nbt.containsKey("Items")) {

Datei anzeigen

@ -107,10 +107,10 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
*/
public abstract int getBlockCombinedId(int x, int y, int z);
public void setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> void setBlock(int x, int y, int z, B block) {
setBlock(x, y, z, block.getInternalId());
if (block.hasNbtData()) {
setTile(x & 15, y, z & 15, block.getNbtData());
if (block instanceof BaseBlock && ((BaseBlock)block).hasNbtData()) {
setTile(x & 15, y, z & 15, ((BaseBlock)block).getNbtData());
}
}

Datei anzeigen

@ -76,12 +76,6 @@ public interface FaweQueue extends HasFaweQueue, Extent {
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
try {
BlockState state = BlockState.getFromInternalId(combinedId4Data);
if (state.getMaterial().hasContainer()) {
CompoundTag tile = getTileEntity(x, y, z);
if (tile != null) {
return BaseBlock.getFromInternalId(combinedId4Data, tile).toImmutableState();
}
}
return state;
} catch (Throwable e) {
MainUtil.handleError(e);
@ -90,13 +84,26 @@ public interface FaweQueue extends HasFaweQueue, Extent {
}
@Override
default boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
return setBlock(x, y, z, block.getInternalId(), block.getNbtData());
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return setBlock(x, y, z, block.getInternalId(), block instanceof BaseBlock ? ((BaseBlock)block).getNbtData() : null);
}
@Override
default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()).toBaseBlock();
int combinedId4Data = getCachedCombinedId4Data(position.getBlockX(), position.getBlockY(), position.getBlockZ(), BlockTypes.AIR.getInternalId());
try {
BaseBlock block = BaseBlock.getFromInternalId(combinedId4Data, null);
if (block.getMaterial().hasContainer()) {
CompoundTag tile = getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (tile != null) {
return BaseBlock.getFromInternalId(combinedId4Data, tile);
}
}
return block;
} catch (Throwable e) {
MainUtil.handleError(e);
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
}
@Override
@ -105,7 +112,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
}
@Override
default boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return setBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ(), block);
}
@ -263,7 +270,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
void addTask(Runnable whenFree);
default void forEachBlockInChunk(int cx, int cz, RunnableVal2<BlockVector3, BlockState> onEach) {
default void forEachBlockInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
int bx = cx << 4;
int bz = cz << 4;
MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
@ -275,8 +282,8 @@ public interface FaweQueue extends HasFaweQueue, Extent {
mutable.mutZ(zz);
for (int y = 0; y <= getMaxY(); y++) {
int combined = getCombinedId4Data(xx, y, zz);
BlockState state = BlockState.getFromInternalId(combined);
BlockType type = state.getBlockType();
BaseBlock block = BlockState.getFromInternalId(combined).toBaseBlock();
BlockType type = block.getBlockType();
switch (type.getResource().toUpperCase()) {
case "AIR":
case "VOID_AIR":
@ -286,17 +293,16 @@ public interface FaweQueue extends HasFaweQueue, Extent {
mutable.mutY(y);
CompoundTag tile = getTileEntity(x, y, z);
if (tile != null) {
BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
onEach.run(mutable.toBlockVector3(), block.toImmutableState());
onEach.run(mutable.toBlockVector3(), block.toBaseBlock(tile));
} else {
onEach.run(mutable.toBlockVector3(), state);
onEach.run(mutable.toBlockVector3(), block);
}
}
}
}
}
default void forEachTileInChunk(int cx, int cz, RunnableVal2<BlockVector3, BlockState> onEach) {
default void forEachTileInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
int bx = cx << 4;
int bz = cz << 4;
MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
@ -317,7 +323,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
mutable.mutZ(zz);
mutable.mutY(y);
BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
onEach.run(mutable.toBlockVector3(), block.toImmutableState());
onEach.run(mutable.toBlockVector3(), block);
}
}
}

Datei anzeigen

@ -5,6 +5,7 @@ import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.object.exception.FaweException;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -59,19 +60,19 @@ public class HistoryExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
BlockStateHolder previous = queue.getLazyBlock(x, y, z);
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
BaseBlock previous = queue.getFullBlock(BlockVector3.at(x, y, z)).toBaseBlock();
if (previous.getInternalId() == block.getInternalId()) {
if (!previous.hasNbtData() && !block.hasNbtData()) {
if (!previous.hasNbtData() && (block instanceof BaseBlock && !((BaseBlock)block).hasNbtData())) {
return false;
}
}
this.changeSet.add(x, y, z, previous, block);
this.changeSet.add(x, y, z, previous, block.toBaseBlock());
return getExtent().setBlock(x, y, z, block);
}
@Override
public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException {
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
}

Datei anzeigen

@ -10,6 +10,7 @@ import com.boydti.fawe.object.function.mask.AbstractDelegateMask;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
@ -67,9 +68,9 @@ public class CopyPastaBrush implements Brush, ResettableTool {
@Override
public boolean test(BlockVector3 vector) {
if (super.test(vector) && vector.getBlockY() >= minY) {
BlockStateHolder block = editSession.getLazyBlock(vector);
BaseBlock block = editSession.getFullBlock(position);
if (!block.getBlockType().getMaterial().isAir()) {
builder.add(vector, EditSession.nullBlock, block);
builder.add(vector, EditSession.nullBlock.toBaseBlock(), block);
return true;
}
}

Datei anzeigen

@ -67,7 +67,7 @@ public class ErodeBrush implements Brush {
finalBuffer.forEach(new FaweClipboard.BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
es.setBlock(x + bx, y + by, z + bz, block);
}
}, true);

Datei anzeigen

@ -154,12 +154,12 @@ public class AbstractDelegateChangeSet extends FaweChangeSet {
}
@Override
public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) {
public void add(BlockVector3 loc, BaseBlock from, BaseBlock to) {
parent.add(loc, from, to);
}
@Override
public void add(int x, int y, int z, BlockStateHolder from, BlockStateHolder to) {
public void add(int x, int y, int z, BaseBlock from, BaseBlock to) {
parent.add(x, y, z, from, to);
}

Datei anzeigen

@ -9,6 +9,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -70,7 +71,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
}
@Override
public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) {
public void add(BlockVector3 loc, BaseBlock from, BaseBlock to) {
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
@ -78,7 +79,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
}
@Override
public void add(int x, int y, int z, BlockStateHolder from, BlockStateHolder to) {
public void add(int x, int y, int z, BaseBlock from, BaseBlock to) {
check(from.getBlockType(), to.getBlockType());
super.add(x, y, z, from, to);
}

Datei anzeigen

@ -197,22 +197,22 @@ public abstract class FaweChangeSet implements ChangeSet {
public void add(BlockChange change) {
try {
BlockVector3 loc = change.getPosition();
BlockStateHolder from = change.getPrevious();
BlockStateHolder to = change.getCurrent();
BaseBlock from = change.getPrevious();
BaseBlock to = change.getCurrent();
add(loc, from, to);
} catch (Exception e) {
MainUtil.handleError(e);
}
}
public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) {
public void add(BlockVector3 loc, BaseBlock from, BaseBlock to) {
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
add(x, y, z, from, to);
}
public void add(int x, int y, int z, BlockStateHolder from, BlockStateHolder to) {
public void add(int x, int y, int z, BaseBlock from, BaseBlock to) {
try {
if (from.hasNbtData()) {
CompoundTag nbt = from.getNbtData();

Datei anzeigen

@ -2,6 +2,7 @@ package com.boydti.fawe.object.clipboard;
import com.boydti.fawe.jnbt.NBTStreamer;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -21,17 +22,17 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
return parent.getBlock(x, y, z);
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
return parent.setBlock(x, y, z, block);
}
@Override
public boolean setBlock(int index, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
return parent.setBlock(index, block);
}
@ -56,7 +57,7 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard {
}
@Override
public BlockState getBlock(int index) {
public BaseBlock getBlock(int index) {
return parent.getBlock(index);
}

Datei anzeigen

@ -140,23 +140,23 @@ public class CPUOptimizedClipboard extends FaweClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
int index = getIndex(x, y, z);
return getBlock(index);
}
@Override
public BlockState getBlock(int index) {
public BaseBlock getBlock(int index) {
int combinedId = states[index];
BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId);
BaseBlock base = type.withStateId(combinedId).toBaseBlock();
if (type.getMaterial().hasContainer()) {
CompoundTag nbt = getTag(index);
if (nbt != null) {
return new BaseBlock(state, nbt).toImmutableState();
return base.toBaseBlock(nbt);
}
}
return state;
return base;
}
@Override
@ -165,7 +165,7 @@ public class CPUOptimizedClipboard extends FaweClipboard {
for (int y = 0, index = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index);
BaseBlock block = getBlock(index);
task.run(x, y, z, block);
}
}
@ -174,7 +174,7 @@ public class CPUOptimizedClipboard extends FaweClipboard {
for (int y = 0, index = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index);
BaseBlock block = getBlock(index);
switch (block.getBlockType().getResource().toUpperCase()) {
case "AIR":
case "CAVE_AIR":
@ -237,16 +237,16 @@ public class CPUOptimizedClipboard extends FaweClipboard {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
return setBlock(getIndex(x, y, z), block);
}
@Override
public boolean setBlock(int index, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
states[index] = block.getInternalId();
CompoundTag tile = block.getNbtData();
if (tile != null) {
setTile(index, tile);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
setTile(index, ((BaseBlock)block).getNbtData());
}
return true;
}

Datei anzeigen

@ -379,7 +379,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt);
task.run(x, y, z, block.toImmutableState());
task.run(x, y, z, block);
continue;
}
}
@ -416,7 +416,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt);
task.run(x, y, z, block.toImmutableState());
task.run(x, y, z, block);
continue;
}
}
@ -433,34 +433,34 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
try {
int index = HEADER_SIZE + (getIndex(x, y, z) << 2);
int combinedId = mbb.getInt(index);
BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId);
BaseBlock base = type.withStateId(combinedId).toBaseBlock();
if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z));
if (nbt != null) {
return new BaseBlock(state, nbt).toImmutableState();
return base.toBaseBlock(nbt);
}
}
return state;
return base;
} catch (IndexOutOfBoundsException ignore) {
} catch (Exception e) {
e.printStackTrace();
MainUtil.handleError(e);
}
return EditSession.nullBlock;
return EditSession.nullBlock.toBaseBlock();
}
@Override
public BlockState getBlock(int i) {
public BaseBlock getBlock(int i) {
try {
int diskIndex = (HEADER_SIZE) + (i << 2);
int combinedId = mbb.getInt(diskIndex);
BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId);
BaseBlock base = type.withStateId(combinedId).toBaseBlock();
if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt;
if (nbtMap.size() < 4) {
@ -482,15 +482,15 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
nbt = nbtMap.get(new IntegerTrio(x, y, z));
}
if (nbt != null) {
return new BaseBlock(state, nbt).toImmutableState();
return base.toBaseBlock(nbt);
}
}
return state;
return base;
} catch (IndexOutOfBoundsException ignore) {
} catch (Exception e) {
MainUtil.handleError(e);
}
return EditSession.nullBlock;
return EditSession.nullBlock.toBaseBlock();
}
@Override
@ -504,14 +504,14 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
try {
int index = (HEADER_SIZE) + ((getIndex(x, y, z) << 2));
int combined = block.getInternalId();
mbb.putInt(index, combined);
CompoundTag tile = block.getNbtData();
if (tile != null) {
setTile(x, y, z, tile);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
setTile(x, y, z, ((BaseBlock)block).getNbtData());
}
return true;
} catch (Exception e) {
@ -521,18 +521,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
}
@Override
public boolean setBlock(int i, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int i, B block) {
try {
int combined = block.getInternalId();
int index = (HEADER_SIZE) + (i << 2);
mbb.putInt(index, combined);
CompoundTag tile = block.getNbtData();
if (tile != null) {
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
int y = i / area;
int newI = (i - (y * area));
int z = newI / width;
int x = newI - z * width;
setTile(x, y, z, tile);
setTile(x, y, z, ((BaseBlock)block).getNbtData());
}
return true;
} catch (Exception e) {

Datei anzeigen

@ -5,6 +5,7 @@ import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -24,11 +25,11 @@ import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class FaweClipboard {
public abstract BlockState getBlock(int x, int y, int z);
public abstract BaseBlock getBlock(int x, int y, int z);
public abstract boolean setBlock(int index, BlockStateHolder block);
public abstract <B extends BlockStateHolder<B>> boolean setBlock(int index, B block);
public abstract boolean setBlock(int x, int y, int z, BlockStateHolder block);
public abstract <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block);
public abstract boolean hasBiomes();
@ -38,7 +39,7 @@ public abstract class FaweClipboard {
public abstract BaseBiome getBiome(int index);
public abstract BlockState getBlock(int index);
public abstract BaseBlock getBlock(int index);
public abstract void setBiome(int index, int biome);
@ -66,7 +67,7 @@ public abstract class FaweClipboard {
public abstract void forEach(BlockReader task, boolean air);
public static abstract class BlockReader {
public abstract void run(int x, int y, int z, BlockState block);
public abstract <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block);
}
public abstract void streamBiomes(final NBTStreamer.ByteReader task);
@ -76,7 +77,7 @@ public abstract class FaweClipboard {
private int index = 0;
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
task.run(index++, block.getInternalId());
}
}, true);
@ -88,8 +89,10 @@ public abstract class FaweClipboard {
private int index = 0;
@Override
public void run(int x, int y, int z, BlockState block) {
CompoundTag tag = block.getNbtData();
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
if(!(block instanceof BaseBlock)) return;
BaseBlock base = (BaseBlock)block;
CompoundTag tag = base.getNbtData();
if (tag != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("x", new IntTag(x));

Datei anzeigen

@ -264,23 +264,23 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
int index = getIndex(x, y, z);
return getBlock(index);
}
@Override
public BlockState getBlock(int index) {
public BaseBlock getBlock(int index) {
int combinedId = getCombinedId(index);
BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId);
BaseBlock base = type.withStateId(combinedId).toBaseBlock();
if (type.getMaterial().hasContainer()) {
CompoundTag nbt = getTag(index);
if (nbt != null) {
return new BaseBlock(state, nbt).toImmutableState();
return base.toBaseBlock(nbt);
}
}
return state;
return base;
}
@Override
@ -289,7 +289,7 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
for (int y = 0, index = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index);
BaseBlock block = getBlock(index);
task.run(x, y, z, block);
}
}
@ -298,7 +298,7 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
for (int y = 0, index = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index);
BaseBlock block = getBlock(index);
switch (block.getBlockType().getResource().toUpperCase()) {
case "AIR":
case "CAVE_AIR":
@ -340,17 +340,17 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
return setBlock(getIndex(x, y, z), block);
}
@Override
public boolean setBlock(int index, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int index, B block) {
int combinedId = block.getInternalId();
setCombinedId(index, combinedId);
CompoundTag tile = block.getNbtData();
if (tile != null) {
setTile(index, tile);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
setTile(index, ((BaseBlock)block).getNbtData());
}
return true;
}

Datei anzeigen

@ -2,6 +2,7 @@ package com.boydti.fawe.object.clipboard;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -20,12 +21,12 @@ public class OffsetFaweClipboard extends AbstractDelegateFaweClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
return super.getBlock(x + ox, y + oy, z + oz);
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
return super.setBlock(ox + x, oy + y, oz + z, block);
}
@ -48,7 +49,7 @@ public class OffsetFaweClipboard extends AbstractDelegateFaweClipboard {
public void forEach(final BlockReader task, boolean air) {
super.forEach(new BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
task.run(x - ox, y - oy, z - oz, block);
}
}, air);

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.object.clipboard;
import com.boydti.fawe.jnbt.NBTStreamer;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -45,7 +46,7 @@ public abstract class ReadOnlyClipboard extends FaweClipboard {
}
@Override
public BlockState getBlock(int index) {
public BaseBlock getBlock(int index) {
throw new UnsupportedOperationException("World based clipboards do not provide index access");
}
@ -76,7 +77,7 @@ public abstract class ReadOnlyClipboard extends FaweClipboard {
}
@Override
public abstract BlockState getBlock(int x, int y, int z);
public abstract BaseBlock getBlock(int x, int y, int z);
@Override
public abstract BaseBiome getBiome(int x, int z);

Datei anzeigen

@ -7,6 +7,7 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.RegionFunction;
@ -47,12 +48,12 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
return extent.getLazyBlock(mx + x, my + y, mz + z);
public BaseBlock getBlock(int x, int y, int z) {
return extent.getFullBlock(BlockVector3.at(mx + x, my + y, mz + z));
}
public BlockState getBlockAbs(int x, int y, int z) {
return extent.getLazyBlock(x, y, z);
public BaseBlock getBlockAbs(int x, int y, int z) {
return extent.getFullBlock(BlockVector3.at(x, y, z));
}
@Override
@ -82,13 +83,12 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
@Override
public boolean apply(BlockVector3 pos) throws WorldEditException {
BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
BaseBlock block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
int x = pos.getBlockX() - mx;
int y = pos.getBlockY() - my;
int z = pos.getBlockZ() - mz;
CompoundTag tag = block.getNbtData();
if (tag != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
if (block.hasNbtData()) {
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
@ -108,10 +108,10 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
int y = pos.getBlockY() - my;
int z = pos.getBlockZ() - mz;
if (region.contains(pos)) {
BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
CompoundTag tag = block.getNbtData();
if (tag != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
// BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
BaseBlock block = extent.getFullBlock(pos);
if (block.hasNbtData()) {
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
@ -138,13 +138,13 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
pos.mutX(x);
int xx = pos.getBlockX() - mx;
if (region.contains(pos.toBlockVector3())) {
BlockState block = getBlockAbs(x, y, z);
// BlockState block = getBlockAbs(x, y, z);
BaseBlock block = extent.getFullBlock(pos.toBlockVector3());
if (!air && block.getBlockType().getMaterial().isAir()) {
continue;
}
CompoundTag tag = block.getNbtData();
if (tag != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
if (block.hasNbtData()) {
Map<String, Tag> values = ReflectionUtils.getMap(block.getNbtData().getValue());
values.put("x", new IntTag(xx));
values.put("y", new IntTag(yy));
values.put("z", new IntTag(zz));

Datei anzeigen

@ -1,6 +1,8 @@
package com.boydti.fawe.object.clipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.regions.Region;
@ -14,17 +16,17 @@ public class WorldCutClipboard extends WorldCopyClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BaseBlock getBlock(int x, int y, int z) {
int xx = mx + x;
int yy = my + y;
int zz = mz + z;
BlockState block = extent.getLazyBlock(xx, yy, zz);
BaseBlock block = extent.getFullBlock(BlockVector3.at(xx, yy, zz));
extent.setBlock(xx, yy, zz, EditSession.nullBlock);
return block;
}
public BlockState getBlockAbs(int x, int y, int z) {
BlockState block = extent.getLazyBlock(x, y, z);
public BaseBlock getBlockAbs(int x, int y, int z) {
BaseBlock block = extent.getFullBlock(BlockVector3.at(x, y, z));
extent.setBlock(x, y, z, EditSession.nullBlock);
return block;
}

Datei anzeigen

@ -493,7 +493,7 @@ public class ClipboardRemapper {
// }
}
public BlockStateHolder remap(BlockStateHolder block) {
public <B extends BlockStateHolder<B>> B remap(B block) {
// int combined = block.getCombined();
// if (remap[combined]) {
// char value = remapCombined[combined];

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.object.clipboard.remap;
import com.boydti.fawe.jnbt.NBTStreamer;
import com.boydti.fawe.object.clipboard.AbstractDelegateFaweClipboard;
import com.boydti.fawe.object.clipboard.FaweClipboard;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -16,21 +17,21 @@ public class RemappedClipboard extends AbstractDelegateFaweClipboard {
}
@Override
public BlockState getBlock(int x, int y, int z) {
return (BlockState) remapper.remap(super.getBlock(x, y, z));
public BaseBlock getBlock(int x, int y, int z) {
return remapper.remap(super.getBlock(x, y, z));
}
@Override
public BlockState getBlock(int index) {
return (BlockState) remapper.remap(super.getBlock(index));
public BaseBlock getBlock(int index) {
return remapper.remap(super.getBlock(index));
}
@Override
public void forEach(BlockReader task, boolean air) {
super.forEach(new BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
task.run(x, y, z, (BlockState) remapper.remap(block));
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
task.run(x, y, z, remapper.remap(block));
}
}, air);
}

Datei anzeigen

@ -1,6 +1,7 @@
package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
@ -32,10 +33,7 @@ public class BlockTranslateExtent extends AbstractDelegateExtent {
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
mutable.mutX(x + dx);
mutable.mutY(y + dy);
mutable.mutZ(z + dz);
return getExtent().setBlock(mutable.toBlockVector3(), block);
return this.setBlock(BlockVector3.at(x, y, z), block);
}
@Override
@ -67,4 +65,9 @@ public class BlockTranslateExtent extends AbstractDelegateExtent {
public BlockState getLazyBlock(int x, int y, int z) {
return super.getLazyBlock(x + dx, y + dy, z + dz);
}
@Override
public BaseBlock getFullBlock(BlockVector3 pos) {
return super.getFullBlock(pos.add(dx, dy, dz));
}
}

Datei anzeigen

@ -111,9 +111,16 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
}
@Override
public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException {
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, final B block) throws WorldEditException {
return queue.setBlock(x, y, z, block);
}
@Override
public BlockState getLazyBlock(BlockVector3 location) {
@ -125,13 +132,21 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0);
BlockType type = BlockTypes.getFromStateId(combinedId4Data);
BlockState state = type.withStateId(combinedId4Data);
return state;
}
@Override
public BaseBlock getFullBlock(BlockVector3 pos) {
int combinedId4Data = queue.getCombinedId4Data(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), 0);
BlockType type = BlockTypes.getFromStateId(combinedId4Data);
BaseBlock base = type.withStateId(combinedId4Data).toBaseBlock();
if (type.getMaterial().hasContainer()) {
CompoundTag tile = queue.getTileEntity(x, y, z);
CompoundTag tile = queue.getTileEntity(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
if (tile != null) {
return new BaseBlock(state, tile).toImmutableState();
return base.toBaseBlock(tile);
}
}
return state;
return base;
}
@Override
@ -154,9 +169,4 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
queue.setBiome(position.getBlockX(), position.getBlockZ(), biome);
return true;
}
@Override
public boolean setBlock(int x, int y, int z, final BlockStateHolder block) throws WorldEditException {
return queue.setBlock(x, y, z, block);
}
}

Datei anzeigen

@ -5,6 +5,7 @@ import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -56,7 +57,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!contains(location)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
@ -67,7 +68,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
@ -109,6 +110,17 @@ public abstract class FaweRegionExtent extends ResettableExtent {
}
return super.getBiome(position);
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return EditSession.nullBlock.toBaseBlock();
}
return super.getFullBlock(position);
}
@Override
public BlockState getBlock(BlockVector3 position) {

Datei anzeigen

@ -21,7 +21,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException {
if (super.setBlock(location, block)) {
if (MemUtil.isMemoryLimited()) {
if (this.player != null) {

Datei anzeigen

@ -1,7 +1,7 @@
package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
@ -61,6 +61,11 @@ public class PositionTransformExtent extends ResettableExtent {
public BlockState getBlock(BlockVector3 position) {
return super.getBlock(getPos(position));
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return super.getFullBlock(getPos(position));
}
@Override
public BaseBiome getBiome(BlockVector2 position) {
@ -72,7 +77,7 @@ public class PositionTransformExtent extends ResettableExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return super.setBlock(getPos(BlockVector3.at(x, y, z)), block);
return this.setBlock(getPos(BlockVector3.at(x, y, z)), block);
}

Datei anzeigen

@ -6,7 +6,7 @@ import com.boydti.fawe.util.WEManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -71,9 +71,19 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
return extent.getLazyBlock(x, y, z);
}
}
@Override
public BaseBlock getFullBlock(BlockVector3 pos) {
if (!limit.MAX_CHECKS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
return EditSession.nullBlock.toBaseBlock();
} else {
return extent.getFullBlock(pos);
}
}
@Override
public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException {
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
}
@ -83,9 +93,9 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
CompoundTag nbt = block.getNbtData();
if (nbt != null) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
if (!limit.MAX_BLOCKSTATES()) {
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
return false;

Datei anzeigen

@ -18,7 +18,7 @@ public class SlowExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!Fawe.isMainThread()) try {
Thread.sleep(sleep);
} catch (InterruptedException e) {

Datei anzeigen

@ -4,7 +4,7 @@ import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -34,28 +34,40 @@ public class StripNBTExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
return super.setBlock(location, stripNBT(block));
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return super.setBlock(location, stripBlockNBT(block));
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
return super.setBlock(x, y, z, stripNBT(block));
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return super.setBlock(x, y, z, stripBlockNBT(block));
}
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
return super.createEntity(location, stripNBT(entity));
return super.createEntity(location, stripEntityNBT(entity));
}
public <T extends NbtValued> T stripNBT(T block) {
if (!block.hasNbtData()) return block;
CompoundTag nbt = block.getNbtData();
public <B extends BlockStateHolder<B>> B stripBlockNBT(B block) {
if(!(block instanceof BaseBlock)) return block;
BaseBlock localBlock = (BaseBlock)block;
if (!localBlock.hasNbtData()) return block;
CompoundTag nbt = localBlock.getNbtData();
Map<String, Tag> value = nbt.getValue();
for (String key : strip) {
value.remove(key);
}
return block;
return (B) localBlock;
}
public <T extends NbtValued> T stripEntityNBT(T entity) {
if (!entity.hasNbtData()) return entity;
CompoundTag nbt = entity.getNbtData();
Map<String, Tag> value = nbt.getValue();
for (String key : strip) {
value.remove(key);
}
return entity;
}
}

Datei anzeigen

@ -1,7 +1,7 @@
package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
@ -13,7 +13,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockData;
public class TemporalExtent extends AbstractDelegateExtent {
private int x, y, z = Integer.MAX_VALUE;
private BlockState block = EditSession.nullBlock;
private BlockStateHolder<?> block = EditSession.nullBlock;
private int bx, bz = Integer.MAX_VALUE;
private BaseBiome biome = EditSession.nullBiome;
@ -28,11 +28,11 @@ public class TemporalExtent extends AbstractDelegateExtent {
}
public void set(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> void set(int x, int y, int z, B block) {
this.x = x;
this.y = y;
this.z = z;
this.block = (BlockState) block;
this.block = block;
}
public void set(int x, int z, BaseBiome biome) {
@ -52,7 +52,7 @@ public class TemporalExtent extends AbstractDelegateExtent {
@Override
public BlockState getBlock(BlockVector3 position) {
if (position.getX() == x && position.getY() == y && position.getZ() == z) {
return block;
return block.toImmutableState();
}
return super.getBlock(position);
}
@ -60,7 +60,7 @@ public class TemporalExtent extends AbstractDelegateExtent {
@Override
public BlockState getLazyBlock(BlockVector3 position) {
if (position.getX() == x && position.getY() == y && position.getZ() == z) {
return block;
return block.toImmutableState();
}
return super.getLazyBlock(position);
}
@ -68,10 +68,22 @@ public class TemporalExtent extends AbstractDelegateExtent {
@Override
public BlockState getLazyBlock(int x, int y, int z) {
if (this.x == x && this.y == y && this.z == z) {
return block;
return block.toImmutableState();
}
return super.getLazyBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if (position.getX() == x && position.getY() == y && position.getZ() == z) {
if(block instanceof BaseBlock) {
return (BaseBlock)block;
}else {
return block.toBaseBlock();
}
}
return super.getFullBlock(position);
}
@Override
public BaseBiome getBiome(BlockVector2 position) {

Datei anzeigen

@ -81,22 +81,22 @@ public class TransformExtent extends BlockTransformExtent {
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return transformFast(super.getLazyBlock(getPos(x, y, z))).toImmutableState();
return transformBlock(super.getLazyBlock(getPos(x, y, z)), false).toImmutableState();
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return transformFast(super.getLazyBlock(getPos(position))).toImmutableState();
return transformBlock(super.getLazyBlock(getPos(position)), false).toImmutableState();
}
@Override
public BlockState getBlock(BlockVector3 position) {
return transformFast(super.getBlock(getPos(position))).toImmutableState();
return transformBlock(super.getBlock(getPos(position)), false).toImmutableState();
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transformFast(super.getFullBlock(getPos(position)).toImmutableState());
return transformBlock(super.getFullBlock(getPos(position)), false);
}
@Override
@ -109,13 +109,13 @@ public class TransformExtent extends BlockTransformExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return super.setBlock(getPos(x, y, z), transformFastInverse((BlockState)block));
return super.setBlock(getPos(x, y, z), transformBlock((BlockState)block, false));
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return super.setBlock(getPos(location), transformFastInverse((BlockState)block));
return super.setBlock(getPos(location), transformBlock((BlockState)block, false));
}
@Override

Datei anzeigen

@ -1,7 +1,7 @@
package com.boydti.fawe.object.function.block;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.RegionFunction;
@ -22,7 +22,8 @@ public class CombinedBlockCopy implements RegionFunction {
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockStateHolder block = source.getBlock(position);
// BlockStateHolder block = source.getBlock(position);
BaseBlock block = source.getFullBlock(position);
function.apply(position);
return destination.setBlock(position, block);
}

Datei anzeigen

@ -17,6 +17,6 @@ public class SimpleBlockCopy implements RegionFunction {
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
return destination.setBlock(position, source.getBlock(position));
return destination.setBlock(position, source.getFullBlock(position));
}
}

Datei anzeigen

@ -54,7 +54,7 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue {
@Override
public CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException {
return getLazyBlock(x, y, z).getNbtData();
return getFullBlock(BlockVector3.at(x, y, z)).getNbtData();
}
@Override

Datei anzeigen

@ -14,7 +14,7 @@ import com.boydti.fawe.util.SetQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -66,7 +66,7 @@ public interface IDelegateFaweQueue extends FaweQueue {
}
@Override
default boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return getQueue().setBlock(x, y, z, block);
}
@ -81,7 +81,7 @@ public interface IDelegateFaweQueue extends FaweQueue {
}
@Override
default boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return getQueue().setBlock(position, block);
}
@ -261,12 +261,12 @@ public interface IDelegateFaweQueue extends FaweQueue {
}
@Override
default void forEachBlockInChunk(int cx, int cz, RunnableVal2<BlockVector3, BlockState> onEach) {
default void forEachBlockInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
getQueue().forEachBlockInChunk(cx, cz, onEach);
}
@Override
default void forEachTileInChunk(int cx, int cz, RunnableVal2<BlockVector3, BlockState> onEach) {
default void forEachTileInChunk(int cx, int cz, RunnableVal2<BlockVector3, BaseBlock> onEach) {
getQueue().forEachTileInChunk(cx, cz, onEach);
}

Datei anzeigen

@ -8,6 +8,7 @@ import com.boydti.fawe.util.MaskTraverser;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
@ -215,7 +216,7 @@ public class Schematic {
mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE);
}
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
try {
int xx = x + relx;
int zz = z + relz;
@ -233,7 +234,7 @@ public class Schematic {
} else {
bac.IMP.forEach(new FaweClipboard.BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
try {
extent.setBlock(x + relx, y + rely, z + relz, block);
} catch (WorldEditException e) { throw new RuntimeException(e);}

Datei anzeigen

@ -212,7 +212,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
ArrayList<Map<String, Object>> blocks = new ArrayList<>();
BlockVector3 min = region.getMinimumPoint();
for (BlockVector3 point : region) {
BlockStateHolder block = clipboard.getBlock(point);
BaseBlock block = clipboard.getFullBlock(point);
switch (block.getBlockType().getResource().toUpperCase()) {
case "STRUCTURE_VOID":
continue;

Datei anzeigen

@ -162,7 +162,8 @@ public class CuboidClipboard {
public BaseBlock getBlock(int x, int y, int z) {
return adapt(clipboard.IMP.getBlock(x, y, z));
// return adapt(clipboard.IMP.getBlock(x, y, z));
return clipboard.IMP.getBlock(x, y, z);
}
public BaseBlock getLazyBlock(BlockVector3 position) {
@ -174,7 +175,7 @@ public class CuboidClipboard {
}
public boolean setBlock(int x, int y, int z, BaseBlock block) {
return setBlock(x, y, z, block.toImmutableState());
return setBlock(x, y, z, block);
}
public boolean setBlock(int x, int y, int z, BlockState block) {

Datei anzeigen

@ -1043,7 +1043,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
}
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
this.changes++;
try {
return this.extent.setBlock(x, y, z, block);
@ -1061,15 +1061,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
throw new RuntimeException("Unexpected exception", e);
}
}
@Deprecated
public boolean setBlock(int x, int y, int z, BaseBlock block) {
return setBlock(x, y, z, block.toImmutableState());
}
@Deprecated
public boolean setBlock(BlockVector3 position, BaseBlock block) throws MaxChangedBlocksException {
return setBlock(position, block.toImmutableState());
}
@SuppressWarnings("deprecation")
public boolean setBlock(final BlockVector3 position, final Pattern pattern) {
@ -1602,7 +1593,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
checkNotNull(region);
checkNotNull(block);
if (canBypassAll(region, false, true) && !block.hasNbtData()) {
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (canBypassAll(region, false, true) && !hasNbt) {
return changes = queue.setBlocks((CuboidRegion) region, block.getInternalId());
}
try {
@ -3370,7 +3363,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
@Override
public boolean clearContainerBlockContents(BlockVector3 pos) {
BlockStateHolder block = getFullBlock(pos);
BaseBlock block = getFullBlock(pos);
CompoundTag nbt = block.getNbtData();
if (nbt != null) {
if (nbt.containsKey("items")) {
@ -3452,8 +3445,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
for (int y = 0; y < getMaxY() + 1; y++) {
// BlockStateHolder block = getFullBlock(mutable.setComponents(xx, y, zz));
BlockVector3 bv = BlockVector3.at(xx, y, zz);
BlockStateHolder block = getFullBlock(bv);
fcs.add(mbv, block, BlockTypes.AIR.getDefaultState());
BaseBlock block = getFullBlock(bv);
fcs.add(mbv, block, BlockTypes.AIR.getDefaultState().toBaseBlock());
}
}
}
@ -3481,8 +3474,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
if (contains) {
containsAny = true;
if (fcs != null) {
BlockStateHolder block = getFullBlock(mbv);
fcs.add(mbv, block, BlockTypes.AIR.getDefaultState());
BaseBlock block = getFullBlock(mbv);
fcs.add(mbv, block, BlockTypes.AIR.getDefaultState().toBaseBlock());
}
} else {
BlockStateHolder block = getFullBlock(mbv);

Datei anzeigen

@ -172,7 +172,7 @@ public class RegionCommands extends MethodCommands {
BBC.NO_BLOCK.send(player);
return;
}
CompoundTag nbt = editSession.getBlock(pos.toVector().toBlockPoint()).getNbtData();
CompoundTag nbt = editSession.getFullBlock(pos.toVector().toBlockPoint()).getNbtData();
if (nbt != null) {
player.print(nbt.getValue().toString());
} else {

Datei anzeigen

@ -246,7 +246,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
}
}
if (nbt == null) nbt = state.getNbtData();
// if (nbt == null) nbt = state.getNbtData();
if (stateString != null) {
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);

Datei anzeigen

@ -201,13 +201,13 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
return IMP.getBlock(x, y, z).toImmutableState();
}
return EditSession.nullBlock;
}
public BlockState getBlockAbs(int x, int y, int z) {
return IMP.getBlock(x, y, z);
return IMP.getBlock(x, y, z).toImmutableState();
}
@Override
@ -228,7 +228,13 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position).toBaseBlock();
if(region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
}
return EditSession.nullBlock.toBaseBlock();
}
@Override

Datei anzeigen

@ -33,6 +33,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
@ -125,67 +126,25 @@ public class SpongeSchematicWriter implements ClipboardWriter {
FaweClipboard.BlockReader reader = new FaweClipboard.BlockReader() {
@Override
public void run(int x, int y, int z, BlockState block) {
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
try {
CompoundTag tile = block.getNbtData();
if (tile != null) {
Map<String, Tag> values = tile.getValue();
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
if (hasNbt) {
BaseBlock localBlock = (BaseBlock)block;
Map<String, Tag> values = localBlock.getNbtData().getValue();
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
// Positions are kept in NBT, we don't want that.
values.remove("x");
values.remove("y");
values.remove("z");
if (!values.containsKey("Id")) values.put("Id", new StringTag(block.getNbtId()));
if (!values.containsKey("Id")) values.put("Id", new StringTag(localBlock.getNbtId()));
values.put("Pos", new IntArrayTag(new int[]{
x,
y,
z
}));
numTiles[0]++;
tilesOut.writeTagPayload(tile);
//=======
//
// Map<String, Tag> schematic = new HashMap<>();
// schematic.put("Version", new IntTag(1));
//
// Map<String, Tag> metadata = new HashMap<>();
// metadata.put("WEOffsetX", new IntTag(offset.getBlockX()));
// metadata.put("WEOffsetY", new IntTag(offset.getBlockY()));
// metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ()));
//
// schematic.put("Metadata", new CompoundTag(metadata));
//
// schematic.put("Width", new ShortTag((short) width));
// schematic.put("Height", new ShortTag((short) height));
// schematic.put("Length", new ShortTag((short) length));
//
// // The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
// schematic.put("Offset", new IntArrayTag(new int[]{
// min.getBlockX(),
// min.getBlockY(),
// min.getBlockZ(),
// }));
//
// int paletteMax = 0;
// Map<String, Integer> palette = new HashMap<>();
//
// List<CompoundTag> tileEntities = new ArrayList<>();
//
// ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
//
// for (int y = 0; y < height; y++) {
// int y0 = min.getBlockY() + y;
// for (int z = 0; z < length; z++) {
// int z0 = min.getBlockZ() + z;
// for (int x = 0; x < width; x++) {
// int x0 = min.getBlockX() + x;
// BlockVector3 point = BlockVector3.at(x0, y0, z0);
// BaseBlock block = clipboard.getFullBlock(point);
// if (block.getNbtData() != null) {
// Map<String, Tag> values = new HashMap<>();
// for (Map.Entry<String, Tag> entry : block.getNbtData().getValue().entrySet()) {
// values.put(entry.getKey(), entry.getValue());
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
tilesOut.writeTagPayload(localBlock.getNbtData());
}
int ordinal = block.getOrdinal();
char value = palette[ordinal];
@ -208,7 +167,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
((BlockArrayClipboard) clipboard).IMP.forEach(reader, true);
} else {
for (BlockVector3 pt : region) {
BlockState block = clipboard.getBlock(pt);
BaseBlock block = clipboard.getFullBlock(pt);
int x = pt.getBlockX() - min.getBlockX();
int y = pt.getBlockY() - min.getBlockY();
int z = pt.getBlockZ() - min.getBlockY();

Datei anzeigen

@ -51,7 +51,7 @@ public abstract class AbstractLoggingExtent extends AbstractDelegateExtent {
}
@Override
public final boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
onBlockChange(position, block);
return super.setBlock(position, block);
}

Datei anzeigen

@ -105,38 +105,38 @@ public class BlockTransformExtent extends ResettableExtent {
* @param reverse true to transform in the opposite direction
* @return the same block
*/
private <T extends BlockStateHolder<T>> T transformBlock(T block, boolean reverse) {
protected <T extends BlockStateHolder<T>> T transformBlock(T block, boolean reverse) {
return transform(block, reverse ? transform.inverse() : transform);
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return transformFast(super.getLazyBlock(position)).toImmutableState();
return transformBlock(super.getLazyBlock(position), false).toImmutableState();
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return transformFast(super.getLazyBlock(x, y, z)).toImmutableState();
return transformBlock(super.getLazyBlock(x, y, z), false).toImmutableState();
}
@Override
public BlockState getBlock(BlockVector3 position) {
return transformFast(super.getBlock(position)).toImmutableState();
return transformBlock(super.getBlock(position), false).toImmutableState();
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transformFast(super.getFullBlock(position).toImmutableState());
return transformBlock(super.getFullBlock(position), false);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return super.setBlock(x, y, z, transformFastInverse((BlockState)block));
return super.setBlock(x, y, z, transformBlock(block, true));
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return super.setBlock(location, transformFastInverse((BlockState)block));
return super.setBlock(location, transformBlock(block, true));
}
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
@ -240,61 +240,6 @@ public class BlockTransformExtent extends ResettableExtent {
}
return result;
}
public final BaseBlock transformFast(BlockState block) {
BaseBlock transformed = transformBlock(block, false).toBaseBlock();
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = Direction.fromRotationIndex(rot).get();
if (direction != null) {
Vector3 applyAbsolute = transform.apply(direction.toVector());
Vector3 applyOrigin = transform.apply(Vector3.ZERO);
Vector3 newAbsolute = Vector3.at(applyAbsolute.getX() - applyOrigin.getX(), applyAbsolute.getY() - applyOrigin.getY(), applyAbsolute.getZ() - applyOrigin.getZ());
Direction newDirection = Direction.findClosest(newAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) newDirection.toRotationIndex().getAsInt()));
}
}
transformed.setNbtData(tag);
}
}
return transformed;
}
public final BaseBlock transformFastInverse(BlockState block) {
BaseBlock transformed = transformBlock(block, true).toBaseBlock();
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = Direction.fromRotationIndex(rot).get();
if (direction != null) {
Vector3 applyAbsolute = getTransform().inverse().apply(direction.toVector());
Vector3 applyOrigin = getTransform().inverse().apply(Vector3.ZERO);
Vector3 newAbsolute = Vector3.at(applyAbsolute.getX() - applyOrigin.getX(), applyAbsolute.getY() - applyOrigin.getY(), applyAbsolute.getZ() - applyOrigin.getZ());
Direction newDirection = Direction.findClosest(newAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) newDirection.toRotationIndex().getAsInt()));
}
}
}
transformed.setNbtData(tag);
}
return transformed;
}
/**
* Get the new value with the transformed direction.

Datei anzeigen

@ -91,7 +91,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if (toolUse && block.getBlockType().getMaterial().isAir()) {
world.simulateBlockMine(BlockVector3.at(x, y, z));
return true;

Datei anzeigen

@ -79,20 +79,12 @@ public class ExtentBlockCopy implements RegionFunction {
}
@Override
//<<<<<<< HEAD
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockVector3 orig = position.subtract(from);
BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint();
//=======
// public boolean apply(BlockVector3 position) throws WorldEditException {
// BaseBlock block = source.getFullBlock(position);
// BlockVector3 orig = position.subtract(from);
// BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint();
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// Apply transformations to NBT data if necessary
BlockStateHolder block = transformNbtData(source.getBlock(position));
BaseBlock block = transformNbtData(source.getFullBlock(position));
return destination.setBlock(transformed.add(to), block);
}
@ -103,8 +95,9 @@ public class ExtentBlockCopy implements RegionFunction {
* @param state the existing state
* @return a new state or the existing one
*/
private BlockState transformNbtData(BlockState state) {
private BaseBlock transformNbtData(BaseBlock state) {
CompoundTag tag = state.getNbtData();
if (tag != null) {
// Handle blocks which store their rotation in NBT
if (tag.containsKey("Rot")) {
@ -113,30 +106,20 @@ public class ExtentBlockCopy implements RegionFunction {
Direction direction = MCDirections.fromRotation(rot);
if (direction != null) {
//<<<<<<< HEAD
// Vector applyAbsolute = transform.apply(direction.toVector());
// Vector applyOrigin = transform.apply(Vector.ZERO);
// applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
// applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
// applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());
//=======
Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// Direction newDirection = Direction.findClosest(applyAbsolute, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);
//<<<<<<< HEAD
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
//=======
// return state.toBaseBlock(builder.build());
//>>>>>>> f54d6afb... Make BaseBlock more memory efficient, and make it clear in the API that it's not intended to be used for every single block.
CompoundTagBuilder builder = tag.createBuilder();
builder.putByte("Rot", (byte) MCDirections.toRotation(newDirection));
return state.toBaseBlock(builder.build());
}
}
}
}
return state;
}

Datei anzeigen

@ -40,6 +40,7 @@ import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.RegionMaskTestFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter;
import com.sk89q.worldedit.function.block.ExtentBlockCopy;
import com.sk89q.worldedit.function.entity.ExtentEntityCopy;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;

Datei anzeigen

@ -244,7 +244,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return this.toImmutableState().apply(extent, get, set);
return extent.setBlock(set, this);
}
@Override
@ -253,8 +253,8 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
}
@Override
public BlockStateHolder withPropertyId(int propertyId) {
return getBlockType().withPropertyId(propertyId);
public BaseBlock withPropertyId(int propertyId) {
return getBlockType().withPropertyId(propertyId).toBaseBlock(getNbtData());
}
@Override
@ -274,12 +274,12 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override
public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock();
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
@Override
public <V> BlockStateHolder with(PropertyKey property, V value) {
return toImmutableState().with(property, value);
public <V> BaseBlock with(PropertyKey property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
@Override

Datei anzeigen

@ -19,19 +19,13 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.object.string.MutableCharSequence;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
@ -45,10 +39,7 @@ import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -249,27 +240,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
return this.toBaseBlock();
}
@Override
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override
public String getNbtId() {
return "";
}
@Nullable
@Override
public CompoundTag getNbtData() {
return null;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
throw new UnsupportedOperationException("This class is immutable.");
}
/**
* The internal id with no type information
* @return

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.FawePattern;
@ -31,7 +30,7 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.util.Map;
import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePattern, TileEntityBlock {
public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePattern {
/**
* Get the block type
@ -46,7 +45,7 @@ public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePat
* @return
*/
@Deprecated
BlockStateHolder withPropertyId(int propertyId);
T withPropertyId(int propertyId);
/**
* Get combined id (legacy uses)
@ -91,7 +90,7 @@ public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePat
* @param value The value
* @return The modified state, or same if could not be applied
*/
<V> BlockStateHolder with(final PropertyKey property, final V value);
<V> T with(final PropertyKey property, final V value);
/**
* Gets the value at the given state