Fix #910 (tile remove)

This commit is contained in:
Jesse Boyd 2018-03-08 17:36:43 +11:00
parent 9128a17533
commit ddcc297ec5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 62 additions and 80 deletions

View File

@ -365,8 +365,8 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
net.minecraft.server.v1_10_R1.BlockPosition bp = entry.getKey(); net.minecraft.server.v1_10_R1.BlockPosition bp = entry.getKey();
net.minecraft.server.v1_10_R1.TileEntity tile = entry.getValue(); net.minecraft.server.v1_10_R1.TileEntity tile = entry.getValue();
tiles.remove(bp); tiles.remove(bp);
tile.y();
nmsWorld.s(bp); nmsWorld.s(bp);
tile.y();
tile.invalidateBlockCache(); tile.invalidateBlockCache();
} }

View File

@ -375,8 +375,8 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
BlockPosition bp = entry.getKey(); BlockPosition bp = entry.getKey();
TileEntity tile = entry.getValue(); TileEntity tile = entry.getValue();
tiles.remove(bp); tiles.remove(bp);
tile.z();
nmsWorld.s(bp); nmsWorld.s(bp);
tile.z();
tile.invalidateBlockCache(); tile.invalidateBlockCache();
} }

View File

@ -9,38 +9,13 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.*;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.*;
import java.util.Collection; import net.minecraft.server.v1_12_R1.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.ChunkSection;
import net.minecraft.server.v1_12_R1.DataBits;
import net.minecraft.server.v1_12_R1.DataPalette;
import net.minecraft.server.v1_12_R1.DataPaletteBlock;
import net.minecraft.server.v1_12_R1.DataPaletteGlobal;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.EntityTypes;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.MinecraftKey;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.NBTTagInt;
import net.minecraft.server.v1_12_R1.TileEntity;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
@ -128,6 +103,7 @@ public class BukkitChunk_1_12 extends CharFaweChunk<Chunk, BukkitQueue_1_12> {
if (!(currentPalette instanceof DataPaletteGlobal)) { if (!(currentPalette instanceof DataPaletteGlobal)) {
current.a(128, null); current.a(128, null);
} }
DataPaletteBlock paletteBlock = newDataPaletteBlock(); DataPaletteBlock paletteBlock = newDataPaletteBlock();
currentPalette = (DataPalette) BukkitQueue_1_12.fieldPalette.get(current); currentPalette = (DataPalette) BukkitQueue_1_12.fieldPalette.get(current);
if (!(currentPalette instanceof DataPaletteGlobal)) { if (!(currentPalette instanceof DataPaletteGlobal)) {
@ -354,39 +330,41 @@ public class BukkitChunk_1_12 extends CharFaweChunk<Chunk, BukkitQueue_1_12> {
} }
} }
// Trim tiles // Trim tiles
Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
HashMap<BlockPosition, TileEntity> toRemove = null; HashMap<BlockPosition, TileEntity> toRemove = null;
while (iterator.hasNext()) { if (!tiles.isEmpty()) {
Map.Entry<BlockPosition, TileEntity> tile = iterator.next(); Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
BlockPosition pos = tile.getKey(); while (iterator.hasNext()) {
int lx = pos.getX() & 15; Map.Entry<BlockPosition, TileEntity> tile = iterator.next();
int ly = pos.getY(); BlockPosition pos = tile.getKey();
int lz = pos.getZ() & 15; int lx = pos.getX() & 15;
int j = FaweCache.CACHE_I[ly][lz][lx]; int ly = pos.getY();
char[] array = this.getIdArray(j); int lz = pos.getZ() & 15;
if (array == null) { int j = FaweCache.CACHE_I[ly][lz][lx];
continue; char[] array = this.getIdArray(j);
} if (array == null) {
int k = FaweCache.CACHE_J[ly][lz][lx]; continue;
if (array[k] != 0) {
if (toRemove == null) {
toRemove = new HashMap<>();
} }
if (copy != null) { int k = FaweCache.CACHE_J[ly][lz][lx];
copy.storeTile(tile.getValue(), tile.getKey()); if (array[k] != 0) {
if (toRemove == null) {
toRemove = new HashMap<>();
}
if (copy != null) {
copy.storeTile(tile.getValue(), tile.getKey());
}
toRemove.put(tile.getKey(), tile.getValue());
} }
toRemove.put(tile.getKey(), tile.getValue());
} }
} if (toRemove != null) {
if (toRemove != null) { synchronized (BukkitQueue_0.class) {
synchronized (BukkitQueue_0.class) { for (Map.Entry<BlockPosition, TileEntity> entry : toRemove.entrySet()) {
for (Map.Entry<BlockPosition, TileEntity> entry : toRemove.entrySet()) { BlockPosition bp = entry.getKey();
BlockPosition bp = entry.getKey(); TileEntity tile = entry.getValue();
TileEntity tile = entry.getValue(); nmsWorld.s(bp);
tiles.remove(bp); tiles.remove(bp);
tile.z(); tile.z();
nmsWorld.s(bp); tile.invalidateBlockCache();
tile.invalidateBlockCache(); }
} }
} }
} }
@ -485,24 +463,28 @@ public class BukkitChunk_1_12 extends CharFaweChunk<Chunk, BukkitQueue_1_12> {
} }
// Set tiles // Set tiles
Map<Short, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) { if (!tilesToSpawn.isEmpty()) {
CompoundTag nativeTag = entry.getValue(); for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
short blockHash = entry.getKey(); CompoundTag nativeTag = entry.getValue();
int x = (blockHash >> 12 & 0xF) + bx; short blockHash = entry.getKey();
int y = (blockHash & 0xFF); int x = (blockHash >> 12 & 0xF) + bx;
int z = (blockHash >> 8 & 0xF) + bz; int y = (blockHash & 0xFF);
BlockPosition pos = new BlockPosition(x, y, z); // Set pos int z = (blockHash >> 8 & 0xF) + bz;
synchronized (BukkitQueue_0.class) { BlockPosition pos = new BlockPosition(x, y, z); // Set pos
TileEntity tileEntity = nmsWorld.getTileEntity(pos); synchronized (BukkitQueue_0.class) {
if (tileEntity != null) { TileEntity tileEntity = nmsWorld.getTileEntity(pos);
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_12.fromNative(nativeTag); if (tileEntity != null) {
tag.set("x", new NBTTagInt(x)); NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_12.fromNative(nativeTag);
tag.set("y", new NBTTagInt(y)); tag.set("x", new NBTTagInt(x));
tag.set("z", new NBTTagInt(z)); tag.set("y", new NBTTagInt(y));
if (BukkitQueue_1_12.methodTileEntityLoad != null) { tag.set("z", new NBTTagInt(z));
BukkitQueue_1_12.methodTileEntityLoad.invoke(tileEntity, tag); // ReadTagIntoTile
} else {
tileEntity.load(tag); if (BukkitQueue_1_12.methodTileEntityLoad != null) {
BukkitQueue_1_12.methodTileEntityLoad.invoke(tileEntity, tag); // ReadTagIntoTile
} else {
tileEntity.load(tag);
}
} }
} }
} }

View File

@ -283,8 +283,8 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
ChunkPosition bp = entry.getKey(); ChunkPosition bp = entry.getKey();
TileEntity tile = entry.getValue(); TileEntity tile = entry.getValue();
tiles.remove(bp); tiles.remove(bp);
tile.s();
nmsWorld.p(bp.x, bp.y, bp.z); nmsWorld.p(bp.x, bp.y, bp.z);
tile.s();
tile.u(); tile.u();
} }

View File

@ -213,8 +213,8 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
BlockPosition bp = entry.getKey(); BlockPosition bp = entry.getKey();
TileEntity tile = entry.getValue(); TileEntity tile = entry.getValue();
tiles.remove(bp); tiles.remove(bp);
tile.y();
nmsWorld.t(bp); nmsWorld.t(bp);
tile.y();
tile.E(); tile.E();
} }

View File

@ -316,8 +316,8 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
BlockPosition bp = entry.getKey(); BlockPosition bp = entry.getKey();
TileEntity tile = entry.getValue(); TileEntity tile = entry.getValue();
tiles.remove(bp); tiles.remove(bp);
tile.y();
nmsWorld.s(bp); nmsWorld.s(bp);
tile.y();
tile.invalidateBlockCache(); tile.invalidateBlockCache();
} }