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

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

Datei anzeigen

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

Datei anzeigen

@ -356,12 +356,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
} }
public void setBlock(BukkitImplAdapter adapter, Chunk chunk, Location location, int combinedId, boolean update) { 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) { 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 { } else {
Block block = location.getWorld().getBlockAt(location); Block block = location.getWorld().getBlockAt(location);
block.setBlockData(BukkitAdapter.adapt(state), false); block.setBlockData(BukkitAdapter.adapt(base), false);
} }
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -154,12 +154,12 @@ public class AbstractDelegateChangeSet extends FaweChangeSet {
} }
@Override @Override
public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) { public void add(BlockVector3 loc, BaseBlock from, BaseBlock to) {
parent.add(loc, from, to); parent.add(loc, from, to);
} }
@Override @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); parent.add(x, y, z, from, to);
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,7 +1,7 @@
package com.boydti.fawe.object.function.block; package com.boydti.fawe.object.function.block;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionFunction;
@ -22,7 +22,8 @@ public class CombinedBlockCopy implements RegionFunction {
@Override @Override
public boolean apply(BlockVector3 position) throws WorldEditException { 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); function.apply(position);
return destination.setBlock(position, block); return destination.setBlock(position, block);
} }

Datei anzeigen

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

Datei anzeigen

@ -54,7 +54,7 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue {
@Override @Override
public CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException { 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 @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -162,7 +162,8 @@ public class CuboidClipboard {
public BaseBlock getBlock(int x, int y, int z) { 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) { public BaseBlock getLazyBlock(BlockVector3 position) {
@ -174,7 +175,7 @@ public class CuboidClipboard {
} }
public boolean setBlock(int x, int y, int z, BaseBlock block) { 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) { public boolean setBlock(int x, int y, int z, BlockState block) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -79,20 +79,12 @@ public class ExtentBlockCopy implements RegionFunction {
} }
@Override @Override
//<<<<<<< HEAD
public boolean apply(BlockVector3 position) throws WorldEditException { public boolean apply(BlockVector3 position) throws WorldEditException {
BlockVector3 orig = position.subtract(from); BlockVector3 orig = position.subtract(from);
BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint(); 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 // 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); return destination.setBlock(transformed.add(to), block);
} }
@ -103,8 +95,9 @@ public class ExtentBlockCopy implements RegionFunction {
* @param state the existing state * @param state the existing state
* @return a new state or the existing one * @return a new state or the existing one
*/ */
private BlockState transformNbtData(BlockState state) { private BaseBlock transformNbtData(BaseBlock state) {
CompoundTag tag = state.getNbtData(); CompoundTag tag = state.getNbtData();
if (tag != null) { if (tag != null) {
// Handle blocks which store their rotation in NBT // Handle blocks which store their rotation in NBT
if (tag.containsKey("Rot")) { if (tag.containsKey("Rot")) {
@ -113,30 +106,20 @@ public class ExtentBlockCopy implements RegionFunction {
Direction direction = MCDirections.fromRotation(rot); Direction direction = MCDirections.fromRotation(rot);
if (direction != null) { 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(); Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL); 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) { if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue()); CompoundTagBuilder builder = tag.createBuilder();
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
//======= builder.putByte("Rot", (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. return state.toBaseBlock(builder.build());
} }
} }
} }
} }
return state; return state;
} }

Datei anzeigen

@ -40,6 +40,7 @@ import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.RegionMaskTestFunction; import com.sk89q.worldedit.function.RegionMaskTestFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter; 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.entity.ExtentEntityCopy;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.Masks;

Datei anzeigen

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

Datei anzeigen

@ -19,19 +19,13 @@
package com.sk89q.worldedit.world.block; package com.sk89q.worldedit.world.block;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.object.string.MutableCharSequence; import com.boydti.fawe.object.string.MutableCharSequence;
import com.google.common.base.Function; 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.Maps;
import com.google.common.collect.Table;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockStateMask; import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
@ -45,10 +39,7 @@ import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -249,27 +240,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
return this.toBaseBlock(); 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 * The internal id with no type information
* @return * @return

Datei anzeigen

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