diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java index dc5835d8..1963b949 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java @@ -1,10 +1,13 @@ package com.boydti.fawe.bukkit.v0; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweCache; +import com.boydti.fawe.bukkit.BukkitPlayer; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; @@ -20,8 +23,10 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkUnloadEvent; @@ -231,6 +236,31 @@ public abstract class BukkitQueue_0 extends NMSMa } } + @Override + public void sendBlockUpdate(Map> blockMap, FawePlayer... players) { + for (FawePlayer player : players) { + Player bukkitPlayer = ((BukkitPlayer) player).parent; + World world = bukkitPlayer.getWorld(); + for (Map.Entry> entry : blockMap.entrySet()) { + long chunkHash = entry.getKey(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + Map blocks = entry.getValue(); + for (Map.Entry blockEntry : blocks.entrySet()) { + short blockHash = blockEntry.getKey(); + int x = (blockHash >> 12 & 0xF) + (cx << 4); + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + (cz << 4); + short combined = blockEntry.getValue(); + int id = FaweCache.getId(combined); + byte data = (byte) FaweCache.getData(combined); + Location loc = new Location(world, x, y, z); + bukkitPlayer.sendBlockChange(loc, id, data); + } + } + } + } + @Override public void endSet(boolean parallel) { ChunkListener.physicsFreeze = false; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java index e52e546a..88589cd1 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java @@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; @@ -408,18 +406,21 @@ public class BukkitChunk_1_10 extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPosition pos = new BlockPosition(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_10.methodFromNative.invoke(BukkitQueue_1_10.adapter, nativeTag); tileEntity.a(tag); // ReadTagIntoTile } - } + } } catch (Throwable e) { MainUtil.handleError(e); } diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/FaweAdapter_1_10.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/FaweAdapter_1_10.java index f1ba0989..71ced154 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/FaweAdapter_1_10.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_10/FaweAdapter_1_10.java @@ -23,7 +23,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -210,146 +209,110 @@ public final class FaweAdapter_1_10 implements BukkitImplAdapter return null; } - private Tag toNative(NBTBase foreign) - { + public Tag toNative(NBTBase foreign) { if (foreign == null) { return null; } - if ((foreign instanceof NBTTagCompound)) - { - Map values = new HashMap(); - Set foreignKeys = ((NBTTagCompound)foreign).c(); - for (String str : foreignKeys) - { - NBTBase base = ((NBTTagCompound)foreign).get(str); + if (foreign instanceof NBTTagCompound) { + Map values = new HashMap(); + Set foreignKeys = ((NBTTagCompound) foreign).c(); // map.keySet + + for (String str : foreignKeys) { + NBTBase base = ((NBTTagCompound) foreign).get(str); values.put(str, toNative(base)); } return new CompoundTag(values); - } - if ((foreign instanceof NBTTagByte)) { - return new ByteTag(((NBTTagByte)foreign).g()); - } - if ((foreign instanceof NBTTagByteArray)) { - return new ByteArrayTag(((NBTTagByteArray)foreign).c()); - } - if ((foreign instanceof NBTTagDouble)) { - return new DoubleTag(((NBTTagDouble)foreign).h()); - } - if ((foreign instanceof NBTTagFloat)) { - return new FloatTag(((NBTTagFloat)foreign).i()); - } - if ((foreign instanceof NBTTagInt)) { - return new IntTag(((NBTTagInt)foreign).e()); - } - if ((foreign instanceof NBTTagIntArray)) { - return new IntArrayTag(((NBTTagIntArray)foreign).d()); - } - if ((foreign instanceof NBTTagList)) { - try - { - return toNativeList((NBTTagList)foreign); + } else if (foreign instanceof NBTTagByte) { + return new ByteTag(((NBTTagByte) foreign).g()); // getByte + } else if (foreign instanceof NBTTagByteArray) { + return new ByteArrayTag(((NBTTagByteArray) foreign).c()); // data + } else if (foreign instanceof NBTTagDouble) { + return new DoubleTag(((NBTTagDouble) foreign).h()); // getDouble + } else if (foreign instanceof NBTTagFloat) { + return new FloatTag(((NBTTagFloat) foreign).i()); // getFloat + } else if (foreign instanceof NBTTagInt) { + return new IntTag(((NBTTagInt) foreign).e()); // getInt + } else if (foreign instanceof NBTTagIntArray) { + return new IntArrayTag(((NBTTagIntArray) foreign).d()); // data + } else if (foreign instanceof NBTTagList) { + try { + return toNativeList((NBTTagList) foreign); + } catch (Throwable e) { + logger.log(Level.WARNING, "Failed to convert NBTTagList", e); + return new ListTag(ByteTag.class, new ArrayList()); } - catch (Throwable e) - { - this.logger.log(Level.WARNING, "Failed to convert NBTTagList", e); - return new ListTag(ByteTag.class, new ArrayList()); - } - } - if ((foreign instanceof NBTTagLong)) { - return new LongTag(((NBTTagLong)foreign).d()); - } - if ((foreign instanceof NBTTagShort)) { - return new ShortTag(((NBTTagShort)foreign).f()); - } - if ((foreign instanceof NBTTagString)) { - return new StringTag(((NBTTagString)foreign).c_()); - } - if ((foreign instanceof NBTTagEnd)) { + } else if (foreign instanceof NBTTagLong) { + return new LongTag(((NBTTagLong) foreign).d()); // getLong + } else if (foreign instanceof NBTTagShort) { + return new ShortTag(((NBTTagShort) foreign).f()); // getShort + } else if (foreign instanceof NBTTagString) { + return new StringTag(((NBTTagString) foreign).c_()); // data + } else if (foreign instanceof NBTTagEnd) { return new EndTag(); + } else { + throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); } - throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); } - private ListTag toNativeList(NBTTagList foreign) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException - { - List values = new ArrayList(); - int type = foreign.getTypeId(); + public ListTag toNativeList(NBTTagList foreign) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + List values = new ArrayList(); + int type = foreign.g(); - List foreignList = (List)this.nbtListTagListField.get(foreign); - for (int i = 0; i < foreign.size(); i++) - { - NBTBase element = (NBTBase)foreignList.get(i); - values.add(toNative(element)); + List foreignList; + foreignList = (List) nbtListTagListField.get(foreign); + for (int i = 0; i < foreign.size(); i++) { + NBTBase element = (NBTBase) foreignList.get(i); + values.add(toNative(element)); // List elements shouldn't have names } + Class cls = NBTConstants.getClassFromType(type); return new ListTag(cls, values); } - private NBTBase fromNative(Tag foreign) - { + public NBTBase fromNative(Tag foreign) { if (foreign == null) { return null; } - Map.Entry entry; - if ((foreign instanceof CompoundTag)) - { + if (foreign instanceof CompoundTag) { NBTTagCompound tag = new NBTTagCompound(); - for (Iterator localIterator = ((CompoundTag)foreign) - .getValue().entrySet().iterator(); localIterator.hasNext();) - { - entry = (Map.Entry)localIterator.next(); - - tag.set((String)entry.getKey(), fromNative((Tag)entry.getValue())); + for (Map.Entry entry : ((CompoundTag) foreign) + .getValue().entrySet()) { + tag.set(entry.getKey(), fromNative(entry.getValue())); } return tag; - } - if ((foreign instanceof ByteTag)) { - return new NBTTagByte(((ByteTag)foreign).getValue().byteValue()); - } - if ((foreign instanceof ByteArrayTag)) { - return new NBTTagByteArray(((ByteArrayTag)foreign).getValue()); - } - if ((foreign instanceof DoubleTag)) { - return new NBTTagDouble(((DoubleTag)foreign).getValue().doubleValue()); - } - if ((foreign instanceof FloatTag)) { - return new NBTTagFloat(((FloatTag)foreign).getValue().floatValue()); - } - if ((foreign instanceof IntTag)) { - return new NBTTagInt(((IntTag)foreign).getValue().intValue()); - } - if ((foreign instanceof IntArrayTag)) { - return new NBTTagIntArray(((IntArrayTag)foreign).getValue()); - } - if ((foreign instanceof ListTag)) - { + } else if (foreign instanceof ByteTag) { + return new NBTTagByte(((ByteTag) foreign).getValue()); + } else if (foreign instanceof ByteArrayTag) { + return new NBTTagByteArray(((ByteArrayTag) foreign).getValue()); + } else if (foreign instanceof DoubleTag) { + return new NBTTagDouble(((DoubleTag) foreign).getValue()); + } else if (foreign instanceof FloatTag) { + return new NBTTagFloat(((FloatTag) foreign).getValue()); + } else if (foreign instanceof IntTag) { + return new NBTTagInt(((IntTag) foreign).getValue()); + } else if (foreign instanceof IntArrayTag) { + return new NBTTagIntArray(((IntArrayTag) foreign).getValue()); + } else if (foreign instanceof ListTag) { NBTTagList tag = new NBTTagList(); - ListTag foreignList = (ListTag)foreign; + ListTag foreignList = (ListTag) foreign; for (Tag t : foreignList.getValue()) { tag.add(fromNative(t)); } return tag; - } - if ((foreign instanceof LongTag)) { - return new NBTTagLong(((LongTag)foreign).getValue().longValue()); - } - if ((foreign instanceof ShortTag)) { - return new NBTTagShort(((ShortTag)foreign).getValue().shortValue()); - } - if ((foreign instanceof StringTag)) { - return new NBTTagString(((StringTag)foreign).getValue()); - } - if ((foreign instanceof EndTag)) { - try - { - return (NBTBase)this.nbtCreateTagMethod.invoke(null, new Object[] { Byte.valueOf((byte) 0) }); - } - catch (Exception e) - { + } else if (foreign instanceof LongTag) { + return new NBTTagLong(((LongTag) foreign).getValue()); + } else if (foreign instanceof ShortTag) { + return new NBTTagShort(((ShortTag) foreign).getValue()); + } else if (foreign instanceof StringTag) { + return new NBTTagString(((StringTag) foreign).getValue()); + } else if (foreign instanceof EndTag) { + try { + return (NBTBase) nbtCreateTagMethod.invoke(null, (byte) 0); + } catch (Exception e) { return null; } + } else { + throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName()); } - throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName()); } -} +} \ No newline at end of file diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java index 727dfb27..e9a48877 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java @@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; @@ -422,11 +420,14 @@ public class BukkitChunk_1_11 extends CharFaweChunk tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + Map tilesToSpawn = this.getTiles(); + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPosition pos = new BlockPosition(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) com.boydti.fawe.bukkit.v1_11.BukkitQueue_1_11.methodFromNative.invoke(com.boydti.fawe.bukkit.v1_11.BukkitQueue_1_11.adapter, nativeTag); diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/FaweAdapter_1_11.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/FaweAdapter_1_11.java index e6fb0d8c..5b16c35c 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/FaweAdapter_1_11.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_11/FaweAdapter_1_11.java @@ -23,7 +23,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -210,146 +209,111 @@ public final class FaweAdapter_1_11 implements BukkitImplAdapter return null; } - private Tag toNative(NBTBase foreign) - { + public Tag toNative(NBTBase foreign) { if (foreign == null) { return null; } - if ((foreign instanceof NBTTagCompound)) - { - Map values = new HashMap(); - Set foreignKeys = ((NBTTagCompound)foreign).c(); - for (String str : foreignKeys) - { - NBTBase base = ((NBTTagCompound)foreign).get(str); + if (foreign instanceof NBTTagCompound) { + Map values = new HashMap(); + Set foreignKeys = ((NBTTagCompound) foreign).c(); // map.keySet + + for (String str : foreignKeys) { + NBTBase base = ((NBTTagCompound) foreign).get(str); values.put(str, toNative(base)); } return new CompoundTag(values); - } - if ((foreign instanceof NBTTagByte)) { - return new ByteTag(((NBTTagByte)foreign).g()); - } - if ((foreign instanceof NBTTagByteArray)) { - return new ByteArrayTag(((NBTTagByteArray)foreign).c()); - } - if ((foreign instanceof NBTTagDouble)) { - return new DoubleTag(((NBTTagDouble)foreign).asDouble()); - } - if ((foreign instanceof NBTTagFloat)) { - return new FloatTag(((NBTTagFloat)foreign).i()); - } - if ((foreign instanceof NBTTagInt)) { - return new IntTag(((NBTTagInt)foreign).e()); - } - if ((foreign instanceof NBTTagIntArray)) { - return new IntArrayTag(((NBTTagIntArray)foreign).d()); - } - if ((foreign instanceof NBTTagList)) { - try - { - return toNativeList((NBTTagList)foreign); + } else if (foreign instanceof NBTTagByte) { + return new ByteTag(((NBTTagByte) foreign).g()); // getByte + } else if (foreign instanceof NBTTagByteArray) { + return new ByteArrayTag(((NBTTagByteArray) foreign).c()); // data + } else if (foreign instanceof NBTTagDouble) { + return new DoubleTag(((NBTTagDouble) foreign).asDouble()); // getDouble + } else if (foreign instanceof NBTTagFloat) { + return new FloatTag(((NBTTagFloat) foreign).i()); // getFloat + } else if (foreign instanceof NBTTagInt) { + return new IntTag(((NBTTagInt) foreign).e()); // getInt + } else if (foreign instanceof NBTTagIntArray) { + return new IntArrayTag(((NBTTagIntArray) foreign).d()); // data + } else if (foreign instanceof NBTTagList) { + try { + return toNativeList((NBTTagList) foreign); + } catch (Throwable e) { + logger.log(Level.WARNING, "Failed to convert NBTTagList", e); + return new ListTag(ByteTag.class, new ArrayList()); } - catch (Throwable e) - { - this.logger.log(Level.WARNING, "Failed to convert NBTTagList", e); - return new ListTag(ByteTag.class, new ArrayList()); - } - } - if ((foreign instanceof NBTTagLong)) { - return new LongTag(((NBTTagLong)foreign).d()); - } - if ((foreign instanceof NBTTagShort)) { - return new ShortTag(((NBTTagShort)foreign).f()); - } - if ((foreign instanceof NBTTagString)) { - return new StringTag(((NBTTagString)foreign).c_()); - } - if ((foreign instanceof NBTTagEnd)) { + } else if (foreign instanceof NBTTagLong) { + return new LongTag(((NBTTagLong) foreign).d()); // getLong + } else if (foreign instanceof NBTTagShort) { + return new ShortTag(((NBTTagShort) foreign).f()); // getShort + } else if (foreign instanceof NBTTagString) { + return new StringTag(((NBTTagString) foreign).c_()); // data + } else if (foreign instanceof NBTTagEnd) { return new EndTag(); + } else { + throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); } - throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); } - private ListTag toNativeList(NBTTagList foreign) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException - { - List values = new ArrayList(); - int type = foreign.getTypeId(); + public ListTag toNativeList(NBTTagList foreign) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + List values = new ArrayList(); + int type = foreign.g(); - List foreignList = (List)this.nbtListTagListField.get(foreign); - for (int i = 0; i < foreign.size(); i++) - { - NBTBase element = (NBTBase)foreignList.get(i); - values.add(toNative(element)); + List foreignList; + foreignList = (List) nbtListTagListField.get(foreign); + for (int i = 0; i < foreign.size(); i++) { + NBTBase element = (NBTBase) foreignList.get(i); + values.add(toNative(element)); // List elements shouldn't have names } + Class cls = NBTConstants.getClassFromType(type); return new ListTag(cls, values); } - private NBTBase fromNative(Tag foreign) - { + public NBTBase fromNative(Tag foreign) { if (foreign == null) { return null; } - Map.Entry entry; - if ((foreign instanceof CompoundTag)) - { + if (foreign instanceof CompoundTag) { NBTTagCompound tag = new NBTTagCompound(); - for (Iterator localIterator = ((CompoundTag)foreign) - .getValue().entrySet().iterator(); localIterator.hasNext();) - { - entry = (Map.Entry)localIterator.next(); - - tag.set((String)entry.getKey(), fromNative((Tag)entry.getValue())); + for (Map.Entry entry : ((CompoundTag) foreign) + .getValue().entrySet()) { + tag.set(entry.getKey(), fromNative(entry.getValue())); } return tag; - } - if ((foreign instanceof ByteTag)) { - return new NBTTagByte(((ByteTag)foreign).getValue().byteValue()); - } - if ((foreign instanceof ByteArrayTag)) { - return new NBTTagByteArray(((ByteArrayTag)foreign).getValue()); - } - if ((foreign instanceof DoubleTag)) { - return new NBTTagDouble(((DoubleTag)foreign).getValue().doubleValue()); - } - if ((foreign instanceof FloatTag)) { - return new NBTTagFloat(((FloatTag)foreign).getValue().floatValue()); - } - if ((foreign instanceof IntTag)) { - return new NBTTagInt(((IntTag)foreign).getValue().intValue()); - } - if ((foreign instanceof IntArrayTag)) { - return new NBTTagIntArray(((IntArrayTag)foreign).getValue()); - } - if ((foreign instanceof ListTag)) - { + } else if (foreign instanceof ByteTag) { + return new NBTTagByte(((ByteTag) foreign).getValue()); + } else if (foreign instanceof ByteArrayTag) { + return new NBTTagByteArray(((ByteArrayTag) foreign).getValue()); + } else if (foreign instanceof DoubleTag) { + return new NBTTagDouble(((DoubleTag) foreign).getValue()); + } else if (foreign instanceof FloatTag) { + return new NBTTagFloat(((FloatTag) foreign).getValue()); + } else if (foreign instanceof IntTag) { + return new NBTTagInt(((IntTag) foreign).getValue()); + } else if (foreign instanceof IntArrayTag) { + return new NBTTagIntArray(((IntArrayTag) foreign).getValue()); + } else if (foreign instanceof ListTag) { NBTTagList tag = new NBTTagList(); - ListTag foreignList = (ListTag)foreign; + ListTag foreignList = (ListTag) foreign; for (Tag t : foreignList.getValue()) { tag.add(fromNative(t)); } return tag; - } - if ((foreign instanceof LongTag)) { - return new NBTTagLong(((LongTag)foreign).getValue().longValue()); - } - if ((foreign instanceof ShortTag)) { - return new NBTTagShort(((ShortTag)foreign).getValue().shortValue()); - } - if ((foreign instanceof StringTag)) { - return new NBTTagString(((StringTag)foreign).getValue()); - } - if ((foreign instanceof EndTag)) { - try - { - return (NBTBase)this.nbtCreateTagMethod.invoke(null, new Object[] { Byte.valueOf((byte) 0) }); - } - catch (Exception e) - { + } else if (foreign instanceof LongTag) { + return new NBTTagLong(((LongTag) foreign).getValue()); + } else if (foreign instanceof ShortTag) { + return new NBTTagShort(((ShortTag) foreign).getValue()); + } else if (foreign instanceof StringTag) { + return new NBTTagString(((StringTag) foreign).getValue()); + } else if (foreign instanceof EndTag) { + try { + return (NBTBase) nbtCreateTagMethod.invoke(null, (byte) 0); + } catch (Exception e) { return null; } + } else { + throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName()); } - throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName()); } + } diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java index 7524906d..af116bd8 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java @@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -356,14 +354,17 @@ public class BukkitChunk_1_7 extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); int bx = this.getX() << 4; int bz = this.getZ() << 4; - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - TileEntity tileEntity = nmsWorld.getTileEntity(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + TileEntity tileEntity = nmsWorld.getTileEntity(x, y, z); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) BukkitQueue17.methodFromNative.invoke(BukkitQueue17.adapter, nativeTag); tileEntity.a(tag); // ReadTagIntoTile diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java index d2d06e85..e559e30e 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java @@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; @@ -292,11 +291,14 @@ public class BukkitChunk_1_8 extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + Map tilesToSpawn = this.getTiles(); + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPosition pos = new BlockPosition(pair.get0x() + bx, pair.get1() & 0xFF, pair.get0y() + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPosition pos = new BlockPosition(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) BukkitQueue18R3.methodFromNative.invoke(BukkitQueue18R3.adapter, nativeTag); diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java index 426eece9..df73e72b 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java @@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; @@ -415,11 +413,14 @@ public class BukkitChunk_1_9 extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + Map tilesToSpawn = this.getTiles(); + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPosition pos = new BlockPosition(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_9_R1.methodFromNative.invoke(BukkitQueue_1_9_R1.adapter, nativeTag); diff --git a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java index 64877a80..8f1ac838 100644 --- a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java @@ -1,7 +1,6 @@ package com.boydti.fawe.example; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MathMan; @@ -21,7 +20,7 @@ public abstract class CharFaweChunk extends FaweChunk public final byte[] heightMap; public int[][] biomes; - public HashMap tiles; + public HashMap tiles; public HashSet entities; public HashSet entityRemoves; @@ -139,9 +138,7 @@ public abstract class CharFaweChunk extends FaweChunk if (tiles == null) { tiles = new HashMap<>(); } - byte i = MathMan.pair16((byte) x, (byte) z); - byte j = (byte) y; - BytePair pair = new BytePair(i, j); + short pair = MathMan.tripleBlockCoord(x, y, z); tiles.put(pair, tile); } @@ -150,15 +147,13 @@ public abstract class CharFaweChunk extends FaweChunk if (tiles == null) { return null; } - byte i = MathMan.pair16((byte) x, (byte) z); - byte j = (byte) y; - BytePair pair = new BytePair(i, j); + short pair = MathMan.tripleBlockCoord(x, y, z); return tiles.get(pair); } @Override - public Map getTiles() { - return tiles == null ? new HashMap() : tiles; + public Map getTiles() { + return tiles == null ? new HashMap() : tiles; } @Override diff --git a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java index 23a5f714..42acbe89 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java @@ -95,11 +95,9 @@ public class NMSRelighter implements Relighter{ int bx = chunkX << 4; int bz = chunkZ << 4; for (short blockHash : blocks.keySet()) { - int hi = (byte) (blockHash >>> 8); - int lo = (byte) blockHash; - int y = lo & 0xFF; - int x = (hi & 0xF) + bx; - int z = ((hi >> 4) & 0xF) + bz; + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; int lcx = x & 0xF; int lcz = z & 0xF; int oldLevel = queue.getEmmittedLight(x, y, z); diff --git a/core/src/main/java/com/boydti/fawe/example/NullFaweChunk.java b/core/src/main/java/com/boydti/fawe/example/NullFaweChunk.java index e48f391f..85cbd94c 100644 --- a/core/src/main/java/com/boydti/fawe/example/NullFaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/example/NullFaweChunk.java @@ -1,6 +1,5 @@ package com.boydti.fawe.example; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.sk89q.jnbt.CompoundTag; @@ -74,7 +73,7 @@ public class NullFaweChunk extends FaweChunk { } @Override - public Map getTiles() { + public Map getTiles() { return new HashMap<>(); } diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index e59acc57..e4dd0c3c 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -2,7 +2,6 @@ package com.boydti.fawe.jnbt.anvil; import com.boydti.fawe.FaweCache; import com.boydti.fawe.jnbt.NBTStreamer; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.RunnableVal2; @@ -27,7 +26,7 @@ public class MCAChunk extends FaweChunk { // data: byte[16][2048] // skylight: byte[16][2048] // blocklight: byte[16][2048] -// entities: Map +// entities: Map // tiles: List // biomes: byte[256] // compressedSize: int @@ -39,7 +38,7 @@ public class MCAChunk extends FaweChunk { public byte[][] skyLight; public byte[][] blockLight; public byte[] biomes; - public Map tiles = new HashMap<>(); + public Map tiles = new HashMap<>(); public Map entities = new HashMap<>(); private long inhabitedTime; private long lastUpdate; @@ -159,9 +158,7 @@ public class MCAChunk extends FaweChunk { int x = tile.getInt("x") & 15; int y = tile.getInt("y"); int z = tile.getInt("z") & 15; - byte i = MathMan.pair16((byte) x, (byte) z); - byte j = (byte) y; - BytePair pair = new BytePair(i, j); + short pair = MathMan.tripleBlockCoord(x, y, z); tiles.put(pair, tile); } }); @@ -227,9 +224,7 @@ public class MCAChunk extends FaweChunk { @Override public void setTile(int x, int y, int z, CompoundTag tile) { modified = true; - byte i = MathMan.pair16((byte) x, (byte) z); - byte j = (byte) y; - BytePair pair = new BytePair(i, j); + short pair = MathMan.tripleBlockCoord(x, y, z); if (tile != null) { tiles.put(pair, tile); } else { @@ -257,8 +252,8 @@ public class MCAChunk extends FaweChunk { } @Override - public Map getTiles() { - return tiles == null ? new HashMap() : tiles; + public Map getTiles() { + return tiles == null ? new HashMap() : tiles; } @Override @@ -266,9 +261,7 @@ public class MCAChunk extends FaweChunk { if (tiles == null || tiles.isEmpty()) { return null; } - byte i = MathMan.pair16((byte) x, (byte) z); - byte j = (byte) y; - BytePair pair = new BytePair(i, j); + short pair = MathMan.tripleBlockCoord(x, y, z); return tiles.get(pair); } diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java index aa6c7464..d780fd01 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java @@ -3,6 +3,7 @@ package com.boydti.fawe.jnbt.anvil; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.RunnableVal4; import com.sk89q.jnbt.CompoundTag; @@ -328,4 +329,11 @@ public class MCAQueue extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + if (parent != null) { + parentNMS.sendBlockUpdate(blockMap, players); + } + } } diff --git a/core/src/main/java/com/boydti/fawe/object/FaweChunk.java b/core/src/main/java/com/boydti/fawe/object/FaweChunk.java index df4d0df3..b4fa8d3e 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweChunk.java @@ -240,7 +240,7 @@ public abstract class FaweChunk implements Callable { * get1 => y * @return */ - public abstract Map getTiles(); + public abstract Map getTiles(); /** * Get the tile at a location diff --git a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java index a7260746..d2e3a7d2 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockData; import java.io.File; import java.util.Collection; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedDeque; @@ -244,6 +245,8 @@ public abstract class FaweQueue { return count; } + public abstract void sendBlockUpdate(Map> blockMap, FawePlayer... players); + @Deprecated public boolean next() { int amount = Settings.QUEUE.PARALLEL_THREADS; diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 9347395b..24c0ef0c 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -3,7 +3,6 @@ package com.boydti.fawe.object.changeset; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; @@ -256,15 +255,15 @@ public abstract class FaweChangeSet implements ChangeSet { // Tile changes { // Tiles created - Map tiles = next.getTiles(); - for (Map.Entry entry : tiles.entrySet()) { + Map tiles = next.getTiles(); + for (Map.Entry entry : tiles.entrySet()) { synchronized (lock) { addTileCreate(entry.getValue()); } } // Tiles removed tiles = previous.getTiles(); - for (Map.Entry entry : tiles.entrySet()) { + for (Map.Entry entry : tiles.entrySet()) { synchronized (lock) { addTileRemove(entry.getValue()); } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 903cd72a..e027e7fc 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -298,7 +298,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } try { NBTOutputStream nbtos = getTileCreateOS(); - nbtos.writeNamedTag(tileCreateSize++ + "", tag); + nbtos.writeTag(tag); } catch (IOException e) { MainUtil.handleError(e); } @@ -310,7 +310,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } try { NBTOutputStream nbtos = getTileRemoveOS(); - nbtos.writeNamedTag(tileRemoveSize++ + "", tag); + nbtos.writeTag(tag); } catch (IOException e) { MainUtil.handleError(e); } @@ -322,7 +322,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } try { NBTOutputStream nbtos = getEntityRemoveOS(); - nbtos.writeNamedTag(entityRemoveSize++ + "", tag); + nbtos.writeTag(tag); } catch (IOException e) { MainUtil.handleError(e); } @@ -334,7 +334,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } try { NBTOutputStream nbtos = getEntityCreateOS(); - nbtos.writeNamedTag(entityCreateSize++ + "", tag); + nbtos.writeTag(tag); } catch (IOException e) { MainUtil.handleError(e); } @@ -468,7 +468,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { public CompoundTag read() { try { - return (CompoundTag) is.readNamedTag().getTag(); + return (CompoundTag) is.readTag(); } catch (Exception ignoreEOS) {} return null; } @@ -518,7 +518,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { public CompoundTag read() { try { - return (CompoundTag) is.readNamedTag().getTag(); + return (CompoundTag) is.readTag(); } catch (Exception ignoreEOS) {} return null; } diff --git a/core/src/main/java/com/boydti/fawe/util/DelegateFaweQueue.java b/core/src/main/java/com/boydti/fawe/util/DelegateFaweQueue.java index b59c7eb2..901ce9a4 100644 --- a/core/src/main/java/com/boydti/fawe/util/DelegateFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/util/DelegateFaweQueue.java @@ -1,6 +1,7 @@ package com.boydti.fawe.util; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.exception.FaweException; @@ -9,6 +10,7 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.world.biome.BaseBiome; import java.io.File; import java.util.Collection; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedDeque; @@ -166,6 +168,11 @@ public class DelegateFaweQueue extends FaweQueue { return parent.cancel(); } + @Override + public void sendBlockUpdate(Map> blockMap, FawePlayer... players) { + parent.sendBlockUpdate(blockMap, players); + } + @Override public boolean next() { return parent.next(); diff --git a/core/src/main/java/com/boydti/fawe/util/MathMan.java b/core/src/main/java/com/boydti/fawe/util/MathMan.java index bc9a35ab..8dcd746b 100644 --- a/core/src/main/java/com/boydti/fawe/util/MathMan.java +++ b/core/src/main/java/com/boydti/fawe/util/MathMan.java @@ -65,9 +65,7 @@ public class MathMan { } public static final short tripleBlockCoord(int x, int y, int z) { - byte hi = (byte) ((x & 15) + ((z & 15) << 4)); - byte lo = (byte) y; - return (short) (((hi & 0xFF) << 8) | (lo & 0xFF)); + return (short) ((x & 15) << 12 | (z & 15) << 8 | y); } public static final long chunkXZ2Int(int x, int z) { diff --git a/core/src/main/java/com/sk89q/jnbt/NBTInputStream.java b/core/src/main/java/com/sk89q/jnbt/NBTInputStream.java index cb58caf2..d5af94b7 100644 --- a/core/src/main/java/com/sk89q/jnbt/NBTInputStream.java +++ b/core/src/main/java/com/sk89q/jnbt/NBTInputStream.java @@ -197,6 +197,9 @@ public final class NBTInputStream implements Closeable { return; case NBTConstants.TYPE_LIST: int childType = is.readByte(); + if (childType == NBTConstants.TYPE_LIST) { + childType = NBTConstants.TYPE_COMPOUND; + } length = is.readInt(); reader = getReader.runAndGet(node + ".?", null).value2; if (reader != null) { @@ -307,6 +310,9 @@ public final class NBTInputStream implements Closeable { return (new String(bytes, NBTConstants.CHARSET)); case NBTConstants.TYPE_LIST: int childType = is.readByte(); + if (childType == NBTConstants.TYPE_LIST) { + childType = NBTConstants.TYPE_COMPOUND; + } length = is.readInt(); List tagList = new ArrayList(); for (int i = 0; i < length; ++i) { @@ -382,6 +388,9 @@ public final class NBTInputStream implements Closeable { return new StringTag(new String(bytes, NBTConstants.CHARSET)); case NBTConstants.TYPE_LIST: int childType = is.readByte(); + if (childType == NBTConstants.TYPE_LIST) { + childType = NBTConstants.TYPE_COMPOUND; + } length = is.readInt(); List tagList = new ArrayList(); for (int i = 0; i < length; ++i) { diff --git a/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java index 03425dfe..0436330d 100644 --- a/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java +++ b/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java @@ -89,6 +89,10 @@ public final class NBTOutputStream implements Closeable { writeTagPayload(tag); } + public void writeEndTag() throws IOException { + os.writeByte(NBTConstants.TYPE_END); + } + /** * Writes tag payload. * @@ -194,8 +198,12 @@ public final class NBTOutputStream implements Closeable { Class clazz = tag.getType(); List tags = tag.getValue(); int size = tags.size(); - - os.writeByte(NBTUtils.getTypeCode(clazz)); + if (!tags.isEmpty()) { + Tag tag0 = tags.get(0); + os.writeByte(NBTUtils.getTypeCode(tag0.getClass())); + } else { + os.writeByte(NBTUtils.getTypeCode(clazz)); + } os.writeInt(size); for (Tag tag1 : tags) { writeTagPayload(tag1); diff --git a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index c947fae3..6c692b68 100644 --- a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -343,12 +341,15 @@ public class ForgeChunk_All extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPos pos = new BlockPos(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); diff --git a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 2696dd21..bd45b378 100644 --- a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; +import com.boydti.fawe.forge.ForgePlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.SPacketChunkData; +import net.minecraft.network.play.server.SPacketMultiBlockChange; import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.tileentity.TileEntity; @@ -97,6 +103,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + for (Map.Entry> chunkEntry : blockMap.entrySet()) { + try { + long chunkHash = chunkEntry.getKey(); + Map blocks = chunkEntry.getValue(); + SPacketMultiBlockChange packet = new SPacketMultiBlockChange(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(); + PacketBuffer buffer = new PacketBuffer(byteBuf); + buffer.writeInt(cx); + buffer.writeInt(cz); + buffer.writeVarIntToBuffer(blocks.size()); + for (Map.Entry blockEntry : blocks.entrySet()) { + buffer.writeShort(blockEntry.getKey()); + buffer.writeVarIntToBuffer(blockEntry.getValue()); + } + packet.readPacketData(buffer); + for (FawePlayer player : players) { + ((ForgePlayer) player).parent.connection.sendPacket(packet); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + protected BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(0, 0, 0); @Override diff --git a/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index 07396bdb..a74601c2 100644 --- a/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -357,12 +355,15 @@ public class ForgeChunk_All extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPos pos = new BlockPos(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); diff --git a/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index c0bedc60..22ddeaa7 100644 --- a/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge111/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; +import com.boydti.fawe.forge.ForgePlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.SPacketChunkData; +import net.minecraft.network.play.server.SPacketMultiBlockChange; import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.tileentity.TileEntity; @@ -82,6 +88,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + for (Map.Entry> chunkEntry : blockMap.entrySet()) { + try { + long chunkHash = chunkEntry.getKey(); + Map blocks = chunkEntry.getValue(); + SPacketMultiBlockChange packet = new SPacketMultiBlockChange(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(); + PacketBuffer buffer = new PacketBuffer(byteBuf); + buffer.writeInt(cx); + buffer.writeInt(cz); + buffer.writeVarInt(blocks.size()); + for (Map.Entry blockEntry : blocks.entrySet()) { + buffer.writeShort(blockEntry.getKey()); + buffer.writeVarInt(blockEntry.getValue()); + } + packet.readPacketData(buffer); + for (FawePlayer player : players) { + ((ForgePlayer) player).parent.connection.sendPacket(packet); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + @Override public void setHeightMap(FaweChunk chunk, byte[] heightMap) { Chunk forgeChunk = (Chunk) chunk.getChunk(); diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index f5d5e504..bd980e2c 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -304,16 +302,16 @@ public class ForgeChunk_All extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); int bx = this.getX() << 4; int bz = this.getZ() << 4; - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - int x = MathMan.unpair16x((byte) pair.get0()) + bx; - int y = pair.get1() & 0xFF; - int z = MathMan.unpair16y((byte) pair.get0()) + bz; + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; TileEntity tileEntity = nmsWorld.getTileEntity(x, y, z); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 361e3ffa..e0961f5d 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -3,7 +3,9 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; +import com.boydti.fawe.forge.ForgePlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.MainUtil; @@ -12,6 +14,8 @@ import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; import net.minecraft.server.management.PlayerManager; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.LongHashMap; @@ -283,6 +289,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + for (Map.Entry> chunkEntry : blockMap.entrySet()) { + try { + long chunkHash = chunkEntry.getKey(); + Map blocks = chunkEntry.getValue(); + S22PacketMultiBlockChange packet = new S22PacketMultiBlockChange(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + ByteBuf byteBuf = new UnpooledByteBufAllocator(true).buffer(); + PacketBuffer buffer = new PacketBuffer(byteBuf); + buffer.writeInt(cx); + buffer.writeInt(cz); + buffer.writeVarIntToBuffer(blocks.size()); + for (Map.Entry blockEntry : blocks.entrySet()) { + buffer.writeShort(blockEntry.getKey()); + buffer.writeVarIntToBuffer(blockEntry.getValue()); + } + packet.readPacketData(buffer); + for (FawePlayer player : players) { + ((ForgePlayer) player).parent.playerNetServerHandler.sendPacket(packet); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + public void setCount(int tickingBlockCount, int nonEmptyBlockCount, ExtendedBlockStorage section) throws NoSuchFieldException, IllegalAccessException { Class clazz = section.getClass(); Field fieldTickingBlockCount = clazz.getDeclaredField("field_76683_c"); // tickRefCount diff --git a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index e12046fc..4a989105 100644 --- a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -258,11 +256,14 @@ public class ForgeChunk_All extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + Map tilesToSpawn = this.getTiles(); + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPos pos = new BlockPos(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); diff --git a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 718636b4..9f4505d7 100644 --- a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; +import com.boydti.fawe.forge.ForgePlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -26,7 +30,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; import net.minecraft.server.management.PlayerManager; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; @@ -197,6 +203,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + for (Map.Entry> chunkEntry : blockMap.entrySet()) { + try { + long chunkHash = chunkEntry.getKey(); + Map blocks = chunkEntry.getValue(); + S22PacketMultiBlockChange packet = new S22PacketMultiBlockChange(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(); + PacketBuffer buffer = new PacketBuffer(byteBuf); + buffer.writeInt(cx); + buffer.writeInt(cz); + buffer.writeVarIntToBuffer(blocks.size()); + for (Map.Entry blockEntry : blocks.entrySet()) { + buffer.writeShort(blockEntry.getKey()); + buffer.writeVarIntToBuffer(blockEntry.getValue()); + } + packet.readPacketData(buffer); + for (FawePlayer player : players) { + ((ForgePlayer) player).parent.playerNetServerHandler.sendPacket(packet); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + @Override public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; diff --git a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index ab2b7056..de32d8a3 100644 --- a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; -import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; @@ -341,12 +339,15 @@ public class ForgeChunk_All extends CharFaweChunk { } } // Set tiles - Map tilesToSpawn = this.getTiles(); + Map tilesToSpawn = this.getTiles(); - for (Map.Entry entry : tilesToSpawn.entrySet()) { + for (Map.Entry entry : tilesToSpawn.entrySet()) { CompoundTag nativeTag = entry.getValue(); - BytePair pair = entry.getKey(); - BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos + short blockHash = entry.getKey(); + int x = (blockHash >> 12 & 0xF) + bx; + int y = (blockHash & 0xFF); + int z = (blockHash >> 8 & 0xF) + bz; + BlockPos pos = new BlockPos(x, y, z); // Set pos TileEntity tileEntity = nmsWorld.getTileEntity(pos); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); diff --git a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 2696dd21..af8e74ef 100644 --- a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0; import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; +import com.boydti.fawe.forge.ForgePlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.SPacketChunkData; +import net.minecraft.network.play.server.SPacketMultiBlockChange; import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.tileentity.TileEntity; @@ -235,6 +241,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + for (Map.Entry> chunkEntry : blockMap.entrySet()) { + try { + long chunkHash = chunkEntry.getKey(); + Map blocks = chunkEntry.getValue(); + SPacketMultiBlockChange packet = new SPacketMultiBlockChange(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(); + PacketBuffer buffer = new PacketBuffer(byteBuf); + buffer.writeInt(cx); + buffer.writeInt(cz); + buffer.writeVarIntToBuffer(blocks.size()); + for (Map.Entry blockEntry : blocks.entrySet()) { + buffer.writeShort(blockEntry.getKey()); + buffer.writeVarIntToBuffer(blockEntry.getValue()); + } + packet.readPacketData(buffer); + for (FawePlayer player : players) { + ((ForgePlayer) player).parent.connection.sendPacket(packet); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + @Override public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java index 5ae3e8db..e28b95db 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java @@ -7,18 +7,24 @@ import cn.nukkit.level.Level; import cn.nukkit.level.Position; import cn.nukkit.level.format.generic.BaseFullChunk; import cn.nukkit.math.Vector3; +import cn.nukkit.network.protocol.UpdateBlockPacket; import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.Settings; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.nukkit.core.NBTConverter; import com.boydti.fawe.nukkit.optimization.FaweNukkit; +import com.boydti.fawe.nukkit.optimization.FaweNukkitPlayer; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.world.World; import java.io.File; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -117,6 +123,43 @@ public class NukkitQueue extends NMSMappedFaweQueue> blockMap, FawePlayer... players) { + ArrayList blocks = new ArrayList(); + for (Map.Entry> entry : blockMap.entrySet()) { + long chunkHash = entry.getKey(); + int cx = MathMan.unpairIntX(chunkHash); + int cz = MathMan.unpairIntY(chunkHash); + Map ids = entry.getValue(); + for (Map.Entry blockEntry : ids.entrySet()) { + short combined = blockEntry.getValue(); + int id = FaweCache.getId(combined); + int data = FaweCache.getData(combined); + Block block = Block.get(id, data); + short blockHash = blockEntry.getKey(); + block.x = (blockHash >> 12 & 0xF) + (cx << 4); + block.y = (blockHash & 0xFF); + block.z = (blockHash >> 8 & 0xF) + (cz << 4); + blocks.add(block); + } + } + Map> playerMap = new HashMap<>(); + for (FawePlayer player : players) { + Player nukkitPlayer = ((FaweNukkitPlayer) player).parent; + List list = playerMap.get(nukkitPlayer.getLevel()); + if (list == null) { + list = new ArrayList<>(); + playerMap.put(nukkitPlayer.getLevel(), list); + } + list.add(nukkitPlayer); + } + Block[] blocksArray = blocks.toArray(new Block[blocks.size()]); + for (Map.Entry> levelListEntry : playerMap.entrySet()) { + List playerList = levelListEntry.getValue(); + levelListEntry.getKey().sendBlocks(playerList.toArray(new Player[playerList.size()]), blocksArray, UpdateBlockPacket.FLAG_ALL_PRIORITY); + } + } + @Override public boolean hasSky() { return world.getDimension() == 0;