From 3236bdd78eb07fb3fc1de7dea608ebeb29b6f6cf Mon Sep 17 00:00:00 2001 From: IronApollo Date: Mon, 25 Mar 2019 13:31:12 -0400 Subject: [PATCH] Changes to NBT-handling in operations and extents, changes to match the widely supported setBlock functionality, minor code cleanup --- .../adapter/v1_13_1/Spigot_v1_13_R2.java | 23 ++----- .../fawe/bukkit/v0/BukkitChunk_All.java | 6 +- .../fawe/bukkit/v0/BukkitQueue_All.java | 3 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 7 +- .../bukkit/adapter/BukkitImplAdapter.java | 3 +- .../com/sk89q/worldedit/blocks/LazyBlock.java | 2 +- .../boydti/fawe/jnbt/SchematicStreamer.java | 2 +- .../com/boydti/fawe/jnbt/anvil/MCAWorld.java | 3 +- .../com/boydti/fawe/object/FaweChunk.java | 6 +- .../com/boydti/fawe/object/FaweQueue.java | 42 ++++++----- .../com/boydti/fawe/object/HistoryExtent.java | 11 +-- .../fawe/object/brush/CopyPastaBrush.java | 5 +- .../boydti/fawe/object/brush/ErodeBrush.java | 2 +- .../changeset/AbstractDelegateChangeSet.java | 4 +- .../object/changeset/BlockBagChangeSet.java | 5 +- .../fawe/object/changeset/FaweChangeSet.java | 8 +-- .../AbstractDelegateFaweClipboard.java | 9 +-- .../clipboard/CPUOptimizedClipboard.java | 24 +++---- .../clipboard/DiskOptimizedClipboard.java | 40 +++++------ .../fawe/object/clipboard/FaweClipboard.java | 19 ++--- .../clipboard/MemoryOptimizedClipboard.java | 24 +++---- .../object/clipboard/OffsetFaweClipboard.java | 7 +- .../object/clipboard/ReadOnlyClipboard.java | 5 +- .../object/clipboard/WorldCopyClipboard.java | 32 ++++----- .../object/clipboard/WorldCutClipboard.java | 10 +-- .../clipboard/remap/ClipboardRemapper.java | 2 +- .../clipboard/remap/RemappedClipboard.java | 13 ++-- .../object/extent/BlockTranslateExtent.java | 11 +-- .../object/extent/FastWorldEditExtent.java | 28 +++++--- .../fawe/object/extent/FaweRegionExtent.java | 16 ++++- .../object/extent/MemoryCheckingExtent.java | 2 +- .../extent/PositionTransformExtent.java | 9 ++- .../fawe/object/extent/ProcessedWEExtent.java | 20 ++++-- .../boydti/fawe/object/extent/SlowExtent.java | 2 +- .../fawe/object/extent/StripNBTExtent.java | 32 ++++++--- .../fawe/object/extent/TemporalExtent.java | 26 +++++-- .../fawe/object/extent/TransformExtent.java | 12 ++-- .../function/block/CombinedBlockCopy.java | 5 +- .../function/block/SimpleBlockCopy.java | 2 +- .../object/queue/FaweQueueDelegateExtent.java | 2 +- .../fawe/object/queue/IDelegateFaweQueue.java | 10 +-- .../fawe/object/schematic/Schematic.java | 5 +- .../object/schematic/StructureFormat.java | 2 +- .../com/sk89q/worldedit/CuboidClipboard.java | 5 +- .../java/com/sk89q/worldedit/EditSession.java | 25 +++---- .../worldedit/command/RegionCommands.java | 2 +- .../factory/parser/DefaultBlockParser.java | 2 +- .../extent/clipboard/BlockArrayClipboard.java | 12 +++- .../clipboard/io/SpongeSchematicWriter.java | 59 +++------------- .../extent/logging/AbstractLoggingExtent.java | 2 +- .../transform/BlockTransformExtent.java | 69 ++----------------- .../extent/world/SurvivalModeExtent.java | 2 +- .../function/block/ExtentBlockCopy.java | 35 +++------- .../function/operation/ForwardExtentCopy.java | 1 + .../worldedit/world/block/BaseBlock.java | 12 ++-- .../worldedit/world/block/BlockState.java | 30 -------- .../world/block/BlockStateHolder.java | 7 +- 57 files changed, 347 insertions(+), 417 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java index 962f2c574..f35a803eb 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java @@ -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); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java index 2325413cf..19ac5c9c0 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java @@ -356,12 +356,12 @@ public class BukkitChunk_All extends IntFaweChunk { } 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); } } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index bdb0dff98..dea95cace 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -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 * 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(); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index 7090f8234..33c2e51e0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -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 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); diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java index 6a3c496eb..d87e7c571 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/LazyBlock.java @@ -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; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index 8194e3a41..9ad05ceaa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -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 > void run(int x, int y, int z, B block) { BlockType type = block.getBlockType(); switch (type.getResource().toUpperCase()) { case "ACACIA_STAIRS": diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java index 3c6d0c7a3..e661da1a1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java @@ -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 nbt = ReflectionUtils.getMap(block.getNbtData().getValue()); if (nbt.containsKey("Items")) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java index a3af9b5f0..50ca1f4cc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java @@ -107,10 +107,10 @@ public abstract class FaweChunk implements Callable { */ public abstract int getBlockCombinedId(int x, int y, int z); - public void setBlock(int x, int y, int z, BlockStateHolder block) { + public > 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()); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java index 56e6dec1b..347807f43 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -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 > 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 > 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 onEach) { + default void forEachBlockInChunk(int cx, int cz, RunnableVal2 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 onEach) { + default void forEachTileInChunk(int cx, int cz, RunnableVal2 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); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index 334565487..75c88b73d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -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 > 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 > boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java index b86bc4b2a..94e384a18 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java @@ -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; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java index 3e78de8d2..36f90aeff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java @@ -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 > void run(int x, int y, int z, B block) { es.setBlock(x + bx, y + by, z + bz, block); } }, true); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java index fafc4c608..da005d865 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java @@ -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); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index ab32831d9..4e742229b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -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); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index c2c862589..680b5f424 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -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(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java index a4e191692..4f39d2b66 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java @@ -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 > 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 > 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); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 9e7d5d2ed..bc430a84f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -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 > 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 > 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; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index ecb4a8708..fc48c3b6a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -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 > 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 > 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) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java index 7267432fd..bcf3fe4e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java @@ -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 > boolean setBlock(int index, B block); - public abstract boolean setBlock(int x, int y, int z, BlockStateHolder block); + public abstract > 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 > 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 > 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 > 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 values = ReflectionUtils.getMap(tag.getValue()); values.put("x", new IntTag(x)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 806941840..8f95ee6d1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -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 > 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 > 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; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/OffsetFaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/OffsetFaweClipboard.java index abdaf65c1..e349e0991 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/OffsetFaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/OffsetFaweClipboard.java @@ -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 > 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 > void run(int x, int y, int z, B block) { task.run(x - ox, y - oy, z - oz, block); } }, air); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java index 6726f2630..8b5b85a47 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java @@ -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); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index b1643ae33..9f174663f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -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 values = ReflectionUtils.getMap(tag.getValue()); + if (block.hasNbtData()) { + Map 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 values = ReflectionUtils.getMap(tag.getValue()); +// BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + BaseBlock block = extent.getFullBlock(pos); + if (block.hasNbtData()) { + Map 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 values = ReflectionUtils.getMap(tag.getValue()); + if (block.hasNbtData()) { + Map values = ReflectionUtils.getMap(block.getNbtData().getValue()); values.put("x", new IntTag(xx)); values.put("y", new IntTag(yy)); values.put("z", new IntTag(zz)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java index f77c2bf65..242c6bc52 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCutClipboard.java @@ -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; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java index 2c0059d92..b48c55f6e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java @@ -493,7 +493,7 @@ public class ClipboardRemapper { // } } - public BlockStateHolder remap(BlockStateHolder block) { + public > B remap(B block) { // int combined = block.getCombined(); // if (remap[combined]) { // char value = remapCombined[combined]; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/RemappedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/RemappedClipboard.java index 165258f27..3f6fb01ab 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/RemappedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/RemappedClipboard.java @@ -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 > void run(int x, int y, int z, B block) { + task.run(x, y, z, remapper.remap(block)); } }, air); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java index b399b95f3..beab0ec14 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java @@ -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 > 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)); + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java index 57cab3f72..3db2fe41a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java @@ -111,9 +111,16 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa } @Override - public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } + + + + @Override + public > 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); - } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index f971d3996..c0e4477b8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -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 > 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 > 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) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java index dc47955d9..9503ade76 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java @@ -21,7 +21,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException { if (super.setBlock(location, block)) { if (MemUtil.isMemoryLimited()) { if (this.player != null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java index 6c78edc29..e2f311fe2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java @@ -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 > 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); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index 85b37faf5..7593d0b2d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -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 > 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 > 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; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java index 48487ccf1..05679c565 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java @@ -18,7 +18,7 @@ public class SlowExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (!Fawe.isMainThread()) try { Thread.sleep(sleep); } catch (InterruptedException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java index 8295e1f50..0d69f4259 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java @@ -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 > 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 > 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 stripNBT(T block) { - if (!block.hasNbtData()) return block; - CompoundTag nbt = block.getNbtData(); + public > B stripBlockNBT(B block) { + if(!(block instanceof BaseBlock)) return block; + BaseBlock localBlock = (BaseBlock)block; + if (!localBlock.hasNbtData()) return block; + CompoundTag nbt = localBlock.getNbtData(); Map value = nbt.getValue(); for (String key : strip) { value.remove(key); } - return block; + return (B) localBlock; + } + + public T stripEntityNBT(T entity) { + if (!entity.hasNbtData()) return entity; + CompoundTag nbt = entity.getNbtData(); + Map value = nbt.getValue(); + for (String key : strip) { + value.remove(key); + } + return entity; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java index e18ec0ac7..b6f1cd552 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java @@ -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 > 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) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java index a06eab224..3b5d50902 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java @@ -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 > 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 > 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 diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java index 0e2f615aa..767538a6e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java @@ -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); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java index c1c6dd200..9f3e40af5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java @@ -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)); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java index 90649b8ff..9d9df1f07 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java @@ -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 diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java index 3522558cb..f80bcc89e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java @@ -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 > 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 > 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 onEach) { + default void forEachBlockInChunk(int cx, int cz, RunnableVal2 onEach) { getQueue().forEachBlockInChunk(cx, cz, onEach); } @Override - default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { + default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { getQueue().forEachTileInChunk(cx, cz, onEach); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java index 87409c343..68282c90e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java @@ -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 > 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 > 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);} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java index 413f458a8..ca77bf03a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java @@ -212,7 +212,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { ArrayList> 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; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index 5c42c0cf0..bb87f2c5d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -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) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 59697acb3..df587294d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1043,7 +1043,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } - public boolean setBlock(int x, int y, int z, BlockStateHolder block) { + public > 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 > 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); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 1f678beed..671704d3d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -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 { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index 52dc9c485..904c67d95 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -246,7 +246,7 @@ public class DefaultBlockParser extends InputParser { 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); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 5037d5194..14cbc1170 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -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 diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index b4127dd47..33ef02976 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -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 > void run(int x, int y, int z, B block) { try { - CompoundTag tile = block.getNbtData(); - if (tile != null) { - Map values = tile.getValue(); + boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData(); + if (hasNbt) { + BaseBlock localBlock = (BaseBlock)block; + Map 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 schematic = new HashMap<>(); -// schematic.put("Version", new IntTag(1)); -// -// Map 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 palette = new HashMap<>(); -// -// List 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 values = new HashMap<>(); -// for (Map.Entry 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(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java index 8647a7cec..83bc2a9e3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/logging/AbstractLoggingExtent.java @@ -51,7 +51,7 @@ public abstract class AbstractLoggingExtent extends AbstractDelegateExtent { } @Override - public final boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { onBlockChange(position, block); return super.setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 515684c8d..7ead8f224 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -105,38 +105,38 @@ public class BlockTransformExtent extends ResettableExtent { * @param reverse true to transform in the opposite direction * @return the same block */ - private > T transformBlock(T block, boolean reverse) { + protected > 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 > 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 > 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 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 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 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. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index 35142703b..d935716c2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -91,7 +91,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > 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; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java index 07bb63b2a..34a4671c9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java @@ -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 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; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 68549980a..a44c52ffa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -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; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index cf9a5d147..4d9ad873f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -244,7 +244,7 @@ public class BaseBlock implements BlockStateHolder, 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, 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, TileEntityBlock { @Override public BaseBlock with(Property property, V value) { - return toImmutableState().with(property, value).toBaseBlock(); + return toImmutableState().with(property, value).toBaseBlock(getNbtData()); } @Override - public BlockStateHolder with(PropertyKey property, V value) { - return toImmutableState().with(property, value); + public BaseBlock with(PropertyKey property, V value) { + return toImmutableState().with(property, value).toBaseBlock(getNbtData()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 4ca5a0e77..835942bea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -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 { 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 diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 6fa0a7eb1..f04bba98b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -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> extends FawePattern, TileEntityBlock { +public interface BlockStateHolder> extends FawePattern { /** * Get the block type @@ -46,7 +45,7 @@ public interface BlockStateHolder> extends FawePat * @return */ @Deprecated - BlockStateHolder withPropertyId(int propertyId); + T withPropertyId(int propertyId); /** * Get combined id (legacy uses) @@ -91,7 +90,7 @@ public interface BlockStateHolder> extends FawePat * @param value The value * @return The modified state, or same if could not be applied */ - BlockStateHolder with(final PropertyKey property, final V value); + T with(final PropertyKey property, final V value); /** * Gets the value at the given state