mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 20:43:54 +00:00
Changes to NBT-handling in operations and extents, changes to match the widely supported setBlock functionality, minor code cleanup
This commit is contained in:
@ -73,7 +73,6 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
|
||||
private final Field nbtListTagListField;
|
||||
private final Method nbtCreateTagMethod;
|
||||
private Method chunkSetTypeMethod;
|
||||
|
||||
static {
|
||||
// A simple test
|
||||
@ -92,13 +91,6 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
// The method to create an NBTBase tag given its type ID
|
||||
nbtCreateTagMethod = NBTBase.class.getDeclaredMethod("createTag", byte.class);
|
||||
nbtCreateTagMethod.setAccessible(true);
|
||||
|
||||
// 1.13.2 Adaptation to find the a/setType method
|
||||
try {
|
||||
chunkSetTypeMethod = Chunk.class.getMethod("setType", BlockPosition.class, IBlockData.class, boolean.class);
|
||||
}catch(NoSuchMethodException e) {
|
||||
chunkSetTypeMethod = Chunk.class.getMethod("a", BlockPosition.class, IBlockData.class, boolean.class);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] idbToStateOrdinal;
|
||||
@ -217,7 +209,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public BlockState getBlock(Location location) {
|
||||
public BaseBlock getBlock(Location location) {
|
||||
checkNotNull(location);
|
||||
|
||||
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
|
||||
@ -233,11 +225,11 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
if (te != null) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readTileEntityIntoTag(te, tag); // Load data
|
||||
return new BaseBlock(state, (CompoundTag) toNative(tag)).toImmutableState();
|
||||
return new BaseBlock(state, (CompoundTag) toNative(tag));
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,7 +257,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
existing = section.getType(x & 15, y & 15, z & 15);
|
||||
}
|
||||
BlockPosition pos = null;
|
||||
CompoundTag nativeTag = state.getNbtData();
|
||||
CompoundTag nativeTag = state instanceof BaseBlock ? ((BaseBlock)state).getNbtData() : null;
|
||||
if (nativeTag != null || existing instanceof TileEntityBlock) {
|
||||
pos = new BlockPosition(x, y, z);
|
||||
nmsWorld.setTypeAndData(pos, blockData, 0);
|
||||
@ -289,12 +281,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
sections[y4] = section = new ChunkSection(y4 << 4, nmsWorld.worldProvider.g());
|
||||
}
|
||||
if (existing.e() != blockData.e() || existing.getMaterial().f() != blockData.getMaterial().f()) {
|
||||
try {
|
||||
chunkSetTypeMethod.invoke(nmsChunk, pos = new BlockPosition(x, y, z), blockData, false);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
logger.warning("Error when setting block!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
nmsChunk.setType(pos = new BlockPosition(x, y, z), blockData, false);
|
||||
} else {
|
||||
section.setType(x & 15, y & 15, z & 15, blockData);
|
||||
}
|
||||
|
@ -356,12 +356,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
|
||||
}
|
||||
|
||||
public void setBlock(BukkitImplAdapter adapter, Chunk chunk, Location location, int combinedId, boolean update) {
|
||||
com.sk89q.worldedit.world.block.BlockState state = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId);
|
||||
com.sk89q.worldedit.world.block.BaseBlock base = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId).toBaseBlock();
|
||||
if (adapter != null) {
|
||||
adapter.setBlock(chunk, (int) location.getX(), (int) location.getY(), (int) location.getZ(), state, update);
|
||||
adapter.setBlock(chunk, (int) location.getX(), (int) location.getY(), (int) location.getZ(), base, update);
|
||||
} else {
|
||||
Block block = location.getWorld().getBlockAt(location);
|
||||
block.setBlockData(BukkitAdapter.adapt(state), false);
|
||||
block.setBlockData(BukkitAdapter.adapt(base), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import org.bukkit.Chunk;
|
||||
@ -333,7 +334,7 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
|
||||
return null;
|
||||
}
|
||||
Location loc = new Location(getWorld(), x, y, z);
|
||||
BlockStateHolder block = getAdapter().getBlock(loc);
|
||||
BaseBlock block = getAdapter().getBlock(loc);
|
||||
return block.getNbtData();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user