Tile entity fixes + send block update

This commit is contained in:
Jesse Boyd 2016-12-02 17:03:57 +11:00
parent 5a914513b9
commit aa27d01fc4
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
32 changed files with 527 additions and 332 deletions

View File

@ -1,10 +1,13 @@
package com.boydti.fawe.bukkit.v0; package com.boydti.fawe.bukkit.v0;
import com.boydti.fawe.Fawe; 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.bukkit.FaweBukkit;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
@ -20,8 +23,10 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
@ -231,6 +236,31 @@ public abstract class BukkitQueue_0<CHUNK, CHUNKSECTIONS, SECTION> extends NMSMa
} }
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (FawePlayer player : players) {
Player bukkitPlayer = ((BukkitPlayer) player).parent;
World world = bukkitPlayer.getWorld();
for (Map.Entry<Long, Map<Short, Short>> entry : blockMap.entrySet()) {
long chunkHash = entry.getKey();
int cx = MathMan.unpairIntX(chunkHash);
int cz = MathMan.unpairIntY(chunkHash);
Map<Short, Short> blocks = entry.getValue();
for (Map.Entry<Short, Short> 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 @Override
public void endSet(boolean parallel) { public void endSet(boolean parallel) {
ChunkListener.physicsFreeze = false; ChunkListener.physicsFreeze = false;

View File

@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; 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.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
@ -408,18 +406,21 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_10.methodFromNative.invoke(BukkitQueue_1_10.adapter, nativeTag); NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_10.methodFromNative.invoke(BukkitQueue_1_10.adapter, nativeTag);
tileEntity.a(tag); // ReadTagIntoTile tileEntity.a(tag); // ReadTagIntoTile
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }

View File

@ -23,7 +23,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -210,146 +209,110 @@ public final class FaweAdapter_1_10 implements BukkitImplAdapter
return null; return null;
} }
private Tag toNative(NBTBase foreign) public Tag toNative(NBTBase foreign) {
{
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
if ((foreign instanceof NBTTagCompound)) if (foreign instanceof NBTTagCompound) {
{ Map<String, Tag> values = new HashMap<String, Tag>();
Map<String, Tag> values = new HashMap(); Set<String> foreignKeys = ((NBTTagCompound) foreign).c(); // map.keySet
Set<String> foreignKeys = ((NBTTagCompound)foreign).c();
for (String str : foreignKeys) for (String str : foreignKeys) {
{ NBTBase base = ((NBTTagCompound) foreign).get(str);
NBTBase base = ((NBTTagCompound)foreign).get(str);
values.put(str, toNative(base)); values.put(str, toNative(base));
} }
return new CompoundTag(values); return new CompoundTag(values);
} } else if (foreign instanceof NBTTagByte) {
if ((foreign instanceof NBTTagByte)) { return new ByteTag(((NBTTagByte) foreign).g()); // getByte
return new ByteTag(((NBTTagByte)foreign).g()); } else if (foreign instanceof NBTTagByteArray) {
} return new ByteArrayTag(((NBTTagByteArray) foreign).c()); // data
if ((foreign instanceof NBTTagByteArray)) { } else if (foreign instanceof NBTTagDouble) {
return new ByteArrayTag(((NBTTagByteArray)foreign).c()); return new DoubleTag(((NBTTagDouble) foreign).h()); // getDouble
} } else if (foreign instanceof NBTTagFloat) {
if ((foreign instanceof NBTTagDouble)) { return new FloatTag(((NBTTagFloat) foreign).i()); // getFloat
return new DoubleTag(((NBTTagDouble)foreign).h()); } else if (foreign instanceof NBTTagInt) {
} return new IntTag(((NBTTagInt) foreign).e()); // getInt
if ((foreign instanceof NBTTagFloat)) { } else if (foreign instanceof NBTTagIntArray) {
return new FloatTag(((NBTTagFloat)foreign).i()); return new IntArrayTag(((NBTTagIntArray) foreign).d()); // data
} } else if (foreign instanceof NBTTagList) {
if ((foreign instanceof NBTTagInt)) { try {
return new IntTag(((NBTTagInt)foreign).e()); return toNativeList((NBTTagList) foreign);
} } catch (Throwable e) {
if ((foreign instanceof NBTTagIntArray)) { logger.log(Level.WARNING, "Failed to convert NBTTagList", e);
return new IntArrayTag(((NBTTagIntArray)foreign).d()); return new ListTag(ByteTag.class, new ArrayList<ByteTag>());
}
if ((foreign instanceof NBTTagList)) {
try
{
return toNativeList((NBTTagList)foreign);
} }
catch (Throwable e) } else if (foreign instanceof NBTTagLong) {
{ return new LongTag(((NBTTagLong) foreign).d()); // getLong
this.logger.log(Level.WARNING, "Failed to convert NBTTagList", e); } else if (foreign instanceof NBTTagShort) {
return new ListTag(ByteTag.class, new ArrayList()); return new ShortTag(((NBTTagShort) foreign).f()); // getShort
} } else if (foreign instanceof NBTTagString) {
} return new StringTag(((NBTTagString) foreign).c_()); // data
if ((foreign instanceof NBTTagLong)) { } else if (foreign instanceof NBTTagEnd) {
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)) {
return new EndTag(); 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) public ListTag toNativeList(NBTTagList foreign) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException List<Tag> values = new ArrayList<Tag>();
{ int type = foreign.g();
List<Tag> values = new ArrayList();
int type = foreign.getTypeId();
List foreignList = (List)this.nbtListTagListField.get(foreign); List foreignList;
for (int i = 0; i < foreign.size(); i++) foreignList = (List) nbtListTagListField.get(foreign);
{ for (int i = 0; i < foreign.size(); i++) {
NBTBase element = (NBTBase)foreignList.get(i); NBTBase element = (NBTBase) foreignList.get(i);
values.add(toNative(element)); values.add(toNative(element)); // List elements shouldn't have names
} }
Class<? extends Tag> cls = NBTConstants.getClassFromType(type); Class<? extends Tag> cls = NBTConstants.getClassFromType(type);
return new ListTag(cls, values); return new ListTag(cls, values);
} }
private NBTBase fromNative(Tag foreign) public NBTBase fromNative(Tag foreign) {
{
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
Map.Entry<String, Tag> entry; if (foreign instanceof CompoundTag) {
if ((foreign instanceof CompoundTag))
{
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
for (Iterator localIterator = ((CompoundTag)foreign) for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
.getValue().entrySet().iterator(); localIterator.hasNext();) .getValue().entrySet()) {
{ tag.set(entry.getKey(), fromNative(entry.getValue()));
entry = (Map.Entry)localIterator.next();
tag.set((String)entry.getKey(), fromNative((Tag)entry.getValue()));
} }
return tag; return tag;
} } else if (foreign instanceof ByteTag) {
if ((foreign instanceof ByteTag)) { return new NBTTagByte(((ByteTag) foreign).getValue());
return new NBTTagByte(((ByteTag)foreign).getValue().byteValue()); } else if (foreign instanceof ByteArrayTag) {
} return new NBTTagByteArray(((ByteArrayTag) foreign).getValue());
if ((foreign instanceof ByteArrayTag)) { } else if (foreign instanceof DoubleTag) {
return new NBTTagByteArray(((ByteArrayTag)foreign).getValue()); return new NBTTagDouble(((DoubleTag) foreign).getValue());
} } else if (foreign instanceof FloatTag) {
if ((foreign instanceof DoubleTag)) { return new NBTTagFloat(((FloatTag) foreign).getValue());
return new NBTTagDouble(((DoubleTag)foreign).getValue().doubleValue()); } else if (foreign instanceof IntTag) {
} return new NBTTagInt(((IntTag) foreign).getValue());
if ((foreign instanceof FloatTag)) { } else if (foreign instanceof IntArrayTag) {
return new NBTTagFloat(((FloatTag)foreign).getValue().floatValue()); return new NBTTagIntArray(((IntArrayTag) foreign).getValue());
} } else if (foreign instanceof ListTag) {
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))
{
NBTTagList tag = new NBTTagList(); NBTTagList tag = new NBTTagList();
ListTag foreignList = (ListTag)foreign; ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) { for (Tag t : foreignList.getValue()) {
tag.add(fromNative(t)); tag.add(fromNative(t));
} }
return tag; return tag;
} } else if (foreign instanceof LongTag) {
if ((foreign instanceof LongTag)) { return new NBTTagLong(((LongTag) foreign).getValue());
return new NBTTagLong(((LongTag)foreign).getValue().longValue()); } else if (foreign instanceof ShortTag) {
} return new NBTTagShort(((ShortTag) foreign).getValue());
if ((foreign instanceof ShortTag)) { } else if (foreign instanceof StringTag) {
return new NBTTagShort(((ShortTag)foreign).getValue().shortValue()); return new NBTTagString(((StringTag) foreign).getValue());
} } else if (foreign instanceof EndTag) {
if ((foreign instanceof StringTag)) { try {
return new NBTTagString(((StringTag)foreign).getValue()); return (NBTBase) nbtCreateTagMethod.invoke(null, (byte) 0);
} } catch (Exception e) {
if ((foreign instanceof EndTag)) {
try
{
return (NBTBase)this.nbtCreateTagMethod.invoke(null, new Object[] { Byte.valueOf((byte) 0) });
}
catch (Exception e)
{
return null; 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());
} }
} }

View File

@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; 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.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
@ -422,11 +420,14 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { 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); 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);

View File

@ -23,7 +23,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -210,146 +209,111 @@ public final class FaweAdapter_1_11 implements BukkitImplAdapter
return null; return null;
} }
private Tag toNative(NBTBase foreign) public Tag toNative(NBTBase foreign) {
{
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
if ((foreign instanceof NBTTagCompound)) if (foreign instanceof NBTTagCompound) {
{ Map<String, Tag> values = new HashMap<String, Tag>();
Map<String, Tag> values = new HashMap(); Set<String> foreignKeys = ((NBTTagCompound) foreign).c(); // map.keySet
Set<String> foreignKeys = ((NBTTagCompound)foreign).c();
for (String str : foreignKeys) for (String str : foreignKeys) {
{ NBTBase base = ((NBTTagCompound) foreign).get(str);
NBTBase base = ((NBTTagCompound)foreign).get(str);
values.put(str, toNative(base)); values.put(str, toNative(base));
} }
return new CompoundTag(values); return new CompoundTag(values);
} } else if (foreign instanceof NBTTagByte) {
if ((foreign instanceof NBTTagByte)) { return new ByteTag(((NBTTagByte) foreign).g()); // getByte
return new ByteTag(((NBTTagByte)foreign).g()); } else if (foreign instanceof NBTTagByteArray) {
} return new ByteArrayTag(((NBTTagByteArray) foreign).c()); // data
if ((foreign instanceof NBTTagByteArray)) { } else if (foreign instanceof NBTTagDouble) {
return new ByteArrayTag(((NBTTagByteArray)foreign).c()); return new DoubleTag(((NBTTagDouble) foreign).asDouble()); // getDouble
} } else if (foreign instanceof NBTTagFloat) {
if ((foreign instanceof NBTTagDouble)) { return new FloatTag(((NBTTagFloat) foreign).i()); // getFloat
return new DoubleTag(((NBTTagDouble)foreign).asDouble()); } else if (foreign instanceof NBTTagInt) {
} return new IntTag(((NBTTagInt) foreign).e()); // getInt
if ((foreign instanceof NBTTagFloat)) { } else if (foreign instanceof NBTTagIntArray) {
return new FloatTag(((NBTTagFloat)foreign).i()); return new IntArrayTag(((NBTTagIntArray) foreign).d()); // data
} } else if (foreign instanceof NBTTagList) {
if ((foreign instanceof NBTTagInt)) { try {
return new IntTag(((NBTTagInt)foreign).e()); return toNativeList((NBTTagList) foreign);
} } catch (Throwable e) {
if ((foreign instanceof NBTTagIntArray)) { logger.log(Level.WARNING, "Failed to convert NBTTagList", e);
return new IntArrayTag(((NBTTagIntArray)foreign).d()); return new ListTag(ByteTag.class, new ArrayList<ByteTag>());
}
if ((foreign instanceof NBTTagList)) {
try
{
return toNativeList((NBTTagList)foreign);
} }
catch (Throwable e) } else if (foreign instanceof NBTTagLong) {
{ return new LongTag(((NBTTagLong) foreign).d()); // getLong
this.logger.log(Level.WARNING, "Failed to convert NBTTagList", e); } else if (foreign instanceof NBTTagShort) {
return new ListTag(ByteTag.class, new ArrayList()); return new ShortTag(((NBTTagShort) foreign).f()); // getShort
} } else if (foreign instanceof NBTTagString) {
} return new StringTag(((NBTTagString) foreign).c_()); // data
if ((foreign instanceof NBTTagLong)) { } else if (foreign instanceof NBTTagEnd) {
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)) {
return new EndTag(); 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) public ListTag toNativeList(NBTTagList foreign) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException List<Tag> values = new ArrayList<Tag>();
{ int type = foreign.g();
List<Tag> values = new ArrayList();
int type = foreign.getTypeId();
List foreignList = (List)this.nbtListTagListField.get(foreign); List foreignList;
for (int i = 0; i < foreign.size(); i++) foreignList = (List) nbtListTagListField.get(foreign);
{ for (int i = 0; i < foreign.size(); i++) {
NBTBase element = (NBTBase)foreignList.get(i); NBTBase element = (NBTBase) foreignList.get(i);
values.add(toNative(element)); values.add(toNative(element)); // List elements shouldn't have names
} }
Class<? extends Tag> cls = NBTConstants.getClassFromType(type); Class<? extends Tag> cls = NBTConstants.getClassFromType(type);
return new ListTag(cls, values); return new ListTag(cls, values);
} }
private NBTBase fromNative(Tag foreign) public NBTBase fromNative(Tag foreign) {
{
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
Map.Entry<String, Tag> entry; if (foreign instanceof CompoundTag) {
if ((foreign instanceof CompoundTag))
{
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
for (Iterator localIterator = ((CompoundTag)foreign) for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
.getValue().entrySet().iterator(); localIterator.hasNext();) .getValue().entrySet()) {
{ tag.set(entry.getKey(), fromNative(entry.getValue()));
entry = (Map.Entry)localIterator.next();
tag.set((String)entry.getKey(), fromNative((Tag)entry.getValue()));
} }
return tag; return tag;
} } else if (foreign instanceof ByteTag) {
if ((foreign instanceof ByteTag)) { return new NBTTagByte(((ByteTag) foreign).getValue());
return new NBTTagByte(((ByteTag)foreign).getValue().byteValue()); } else if (foreign instanceof ByteArrayTag) {
} return new NBTTagByteArray(((ByteArrayTag) foreign).getValue());
if ((foreign instanceof ByteArrayTag)) { } else if (foreign instanceof DoubleTag) {
return new NBTTagByteArray(((ByteArrayTag)foreign).getValue()); return new NBTTagDouble(((DoubleTag) foreign).getValue());
} } else if (foreign instanceof FloatTag) {
if ((foreign instanceof DoubleTag)) { return new NBTTagFloat(((FloatTag) foreign).getValue());
return new NBTTagDouble(((DoubleTag)foreign).getValue().doubleValue()); } else if (foreign instanceof IntTag) {
} return new NBTTagInt(((IntTag) foreign).getValue());
if ((foreign instanceof FloatTag)) { } else if (foreign instanceof IntArrayTag) {
return new NBTTagFloat(((FloatTag)foreign).getValue().floatValue()); return new NBTTagIntArray(((IntArrayTag) foreign).getValue());
} } else if (foreign instanceof ListTag) {
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))
{
NBTTagList tag = new NBTTagList(); NBTTagList tag = new NBTTagList();
ListTag foreignList = (ListTag)foreign; ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) { for (Tag t : foreignList.getValue()) {
tag.add(fromNative(t)); tag.add(fromNative(t));
} }
return tag; return tag;
} } else if (foreign instanceof LongTag) {
if ((foreign instanceof LongTag)) { return new NBTTagLong(((LongTag) foreign).getValue());
return new NBTTagLong(((LongTag)foreign).getValue().longValue()); } else if (foreign instanceof ShortTag) {
} return new NBTTagShort(((ShortTag) foreign).getValue());
if ((foreign instanceof ShortTag)) { } else if (foreign instanceof StringTag) {
return new NBTTagShort(((ShortTag)foreign).getValue().shortValue()); return new NBTTagString(((StringTag) foreign).getValue());
} } else if (foreign instanceof EndTag) {
if ((foreign instanceof StringTag)) { try {
return new NBTTagString(((StringTag)foreign).getValue()); return (NBTBase) nbtCreateTagMethod.invoke(null, (byte) 0);
} } catch (Exception e) {
if ((foreign instanceof EndTag)) {
try
{
return (NBTBase)this.nbtCreateTagMethod.invoke(null, new Object[] { Byte.valueOf((byte) 0) });
}
catch (Exception e)
{
return null; 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());
} }
} }

View File

@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -356,14 +354,17 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
int bx = this.getX() << 4; int bx = this.getX() << 4;
int bz = this.getZ() << 4; int bz = this.getZ() << 4;
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
TileEntity tileEntity = nmsWorld.getTileEntity(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); 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) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue17.methodFromNative.invoke(BukkitQueue17.adapter, nativeTag); NBTTagCompound tag = (NBTTagCompound) BukkitQueue17.methodFromNative.invoke(BukkitQueue17.adapter, nativeTag);
tileEntity.a(tag); // ReadTagIntoTile tileEntity.a(tag); // ReadTagIntoTile

View File

@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
@ -292,11 +291,14 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPosition pos = new BlockPosition(pair.get0x() + bx, pair.get1() & 0xFF, pair.get0y() + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue18R3.methodFromNative.invoke(BukkitQueue18R3.adapter, nativeTag); NBTTagCompound tag = (NBTTagCompound) BukkitQueue18R3.methodFromNative.invoke(BukkitQueue18R3.adapter, nativeTag);

View File

@ -4,11 +4,9 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; 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.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
@ -415,11 +413,14 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPosition pos = new BlockPosition(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_9_R1.methodFromNative.invoke(BukkitQueue_1_9_R1.adapter, nativeTag); NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_9_R1.methodFromNative.invoke(BukkitQueue_1_9_R1.adapter, nativeTag);

View File

@ -1,7 +1,6 @@
package com.boydti.fawe.example; package com.boydti.fawe.example;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
@ -21,7 +20,7 @@ public abstract class CharFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
public final byte[] heightMap; public final byte[] heightMap;
public int[][] biomes; public int[][] biomes;
public HashMap<BytePair, CompoundTag> tiles; public HashMap<Short, CompoundTag> tiles;
public HashSet<CompoundTag> entities; public HashSet<CompoundTag> entities;
public HashSet<UUID> entityRemoves; public HashSet<UUID> entityRemoves;
@ -139,9 +138,7 @@ public abstract class CharFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
if (tiles == null) { if (tiles == null) {
tiles = new HashMap<>(); tiles = new HashMap<>();
} }
byte i = MathMan.pair16((byte) x, (byte) z); short pair = MathMan.tripleBlockCoord(x, y, z);
byte j = (byte) y;
BytePair pair = new BytePair(i, j);
tiles.put(pair, tile); tiles.put(pair, tile);
} }
@ -150,15 +147,13 @@ public abstract class CharFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
if (tiles == null) { if (tiles == null) {
return null; return null;
} }
byte i = MathMan.pair16((byte) x, (byte) z); short pair = MathMan.tripleBlockCoord(x, y, z);
byte j = (byte) y;
BytePair pair = new BytePair(i, j);
return tiles.get(pair); return tiles.get(pair);
} }
@Override @Override
public Map<BytePair, CompoundTag> getTiles() { public Map<Short, CompoundTag> getTiles() {
return tiles == null ? new HashMap<BytePair, CompoundTag>() : tiles; return tiles == null ? new HashMap<Short, CompoundTag>() : tiles;
} }
@Override @Override

View File

@ -95,11 +95,9 @@ public class NMSRelighter implements Relighter{
int bx = chunkX << 4; int bx = chunkX << 4;
int bz = chunkZ << 4; int bz = chunkZ << 4;
for (short blockHash : blocks.keySet()) { for (short blockHash : blocks.keySet()) {
int hi = (byte) (blockHash >>> 8); int x = (blockHash >> 12 & 0xF) + bx;
int lo = (byte) blockHash; int y = (blockHash & 0xFF);
int y = lo & 0xFF; int z = (blockHash >> 8 & 0xF) + bz;
int x = (hi & 0xF) + bx;
int z = ((hi >> 4) & 0xF) + bz;
int lcx = x & 0xF; int lcx = x & 0xF;
int lcz = z & 0xF; int lcz = z & 0xF;
int oldLevel = queue.getEmmittedLight(x, y, z); int oldLevel = queue.getEmmittedLight(x, y, z);

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.example; package com.boydti.fawe.example;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -74,7 +73,7 @@ public class NullFaweChunk extends FaweChunk<Void> {
} }
@Override @Override
public Map<BytePair, CompoundTag> getTiles() { public Map<Short, CompoundTag> getTiles() {
return new HashMap<>(); return new HashMap<>();
} }

View File

@ -2,7 +2,6 @@ package com.boydti.fawe.jnbt.anvil;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.jnbt.NBTStreamer; import com.boydti.fawe.jnbt.NBTStreamer;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.RunnableVal2;
@ -27,7 +26,7 @@ public class MCAChunk extends FaweChunk<Void> {
// data: byte[16][2048] // data: byte[16][2048]
// skylight: byte[16][2048] // skylight: byte[16][2048]
// blocklight: byte[16][2048] // blocklight: byte[16][2048]
// entities: Map<BytePair, CompoundTag> // entities: Map<Short, CompoundTag>
// tiles: List<CompoundTag> // tiles: List<CompoundTag>
// biomes: byte[256] // biomes: byte[256]
// compressedSize: int // compressedSize: int
@ -39,7 +38,7 @@ public class MCAChunk extends FaweChunk<Void> {
public byte[][] skyLight; public byte[][] skyLight;
public byte[][] blockLight; public byte[][] blockLight;
public byte[] biomes; public byte[] biomes;
public Map<BytePair, CompoundTag> tiles = new HashMap<>(); public Map<Short, CompoundTag> tiles = new HashMap<>();
public Map<UUID, CompoundTag> entities = new HashMap<>(); public Map<UUID, CompoundTag> entities = new HashMap<>();
private long inhabitedTime; private long inhabitedTime;
private long lastUpdate; private long lastUpdate;
@ -159,9 +158,7 @@ public class MCAChunk extends FaweChunk<Void> {
int x = tile.getInt("x") & 15; int x = tile.getInt("x") & 15;
int y = tile.getInt("y"); int y = tile.getInt("y");
int z = tile.getInt("z") & 15; int z = tile.getInt("z") & 15;
byte i = MathMan.pair16((byte) x, (byte) z); short pair = MathMan.tripleBlockCoord(x, y, z);
byte j = (byte) y;
BytePair pair = new BytePair(i, j);
tiles.put(pair, tile); tiles.put(pair, tile);
} }
}); });
@ -227,9 +224,7 @@ public class MCAChunk extends FaweChunk<Void> {
@Override @Override
public void setTile(int x, int y, int z, CompoundTag tile) { public void setTile(int x, int y, int z, CompoundTag tile) {
modified = true; modified = true;
byte i = MathMan.pair16((byte) x, (byte) z); short pair = MathMan.tripleBlockCoord(x, y, z);
byte j = (byte) y;
BytePair pair = new BytePair(i, j);
if (tile != null) { if (tile != null) {
tiles.put(pair, tile); tiles.put(pair, tile);
} else { } else {
@ -257,8 +252,8 @@ public class MCAChunk extends FaweChunk<Void> {
} }
@Override @Override
public Map<BytePair, CompoundTag> getTiles() { public Map<Short, CompoundTag> getTiles() {
return tiles == null ? new HashMap<BytePair, CompoundTag>() : tiles; return tiles == null ? new HashMap<Short, CompoundTag>() : tiles;
} }
@Override @Override
@ -266,9 +261,7 @@ public class MCAChunk extends FaweChunk<Void> {
if (tiles == null || tiles.isEmpty()) { if (tiles == null || tiles.isEmpty()) {
return null; return null;
} }
byte i = MathMan.pair16((byte) x, (byte) z); short pair = MathMan.tripleBlockCoord(x, y, z);
byte j = (byte) y;
BytePair pair = new BytePair(i, j);
return tiles.get(pair); return tiles.get(pair);
} }

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.jnbt.anvil;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal4; import com.boydti.fawe.object.RunnableVal4;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -328,4 +329,11 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
parent.endSet(parallel); parent.endSet(parallel);
} }
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
if (parent != null) {
parentNMS.sendBlockUpdate(blockMap, players);
}
}
} }

View File

@ -240,7 +240,7 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
* get1 => y * get1 => y
* @return * @return
*/ */
public abstract Map<BytePair, CompoundTag> getTiles(); public abstract Map<Short, CompoundTag> getTiles();
/** /**
* Get the tile at a location * Get the tile at a location

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockData;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
@ -244,6 +245,8 @@ public abstract class FaweQueue {
return count; return count;
} }
public abstract void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players);
@Deprecated @Deprecated
public boolean next() { public boolean next() {
int amount = Settings.QUEUE.PARALLEL_THREADS; int amount = Settings.QUEUE.PARALLEL_THREADS;

View File

@ -3,7 +3,6 @@ package com.boydti.fawe.object.changeset;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
@ -256,15 +255,15 @@ public abstract class FaweChangeSet implements ChangeSet {
// Tile changes // Tile changes
{ {
// Tiles created // Tiles created
Map<BytePair, CompoundTag> tiles = next.getTiles(); Map<Short, CompoundTag> tiles = next.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tiles.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
synchronized (lock) { synchronized (lock) {
addTileCreate(entry.getValue()); addTileCreate(entry.getValue());
} }
} }
// Tiles removed // Tiles removed
tiles = previous.getTiles(); tiles = previous.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tiles.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
synchronized (lock) { synchronized (lock) {
addTileRemove(entry.getValue()); addTileRemove(entry.getValue());
} }

View File

@ -298,7 +298,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
} }
try { try {
NBTOutputStream nbtos = getTileCreateOS(); NBTOutputStream nbtos = getTileCreateOS();
nbtos.writeNamedTag(tileCreateSize++ + "", tag); nbtos.writeTag(tag);
} catch (IOException e) { } catch (IOException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
@ -310,7 +310,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
} }
try { try {
NBTOutputStream nbtos = getTileRemoveOS(); NBTOutputStream nbtos = getTileRemoveOS();
nbtos.writeNamedTag(tileRemoveSize++ + "", tag); nbtos.writeTag(tag);
} catch (IOException e) { } catch (IOException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
@ -322,7 +322,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
} }
try { try {
NBTOutputStream nbtos = getEntityRemoveOS(); NBTOutputStream nbtos = getEntityRemoveOS();
nbtos.writeNamedTag(entityRemoveSize++ + "", tag); nbtos.writeTag(tag);
} catch (IOException e) { } catch (IOException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
@ -334,7 +334,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
} }
try { try {
NBTOutputStream nbtos = getEntityCreateOS(); NBTOutputStream nbtos = getEntityCreateOS();
nbtos.writeNamedTag(entityCreateSize++ + "", tag); nbtos.writeTag(tag);
} catch (IOException e) { } catch (IOException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
@ -468,7 +468,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public CompoundTag read() { public CompoundTag read() {
try { try {
return (CompoundTag) is.readNamedTag().getTag(); return (CompoundTag) is.readTag();
} catch (Exception ignoreEOS) {} } catch (Exception ignoreEOS) {}
return null; return null;
} }
@ -518,7 +518,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
public CompoundTag read() { public CompoundTag read() {
try { try {
return (CompoundTag) is.readNamedTag().getTag(); return (CompoundTag) is.readTag();
} catch (Exception ignoreEOS) {} } catch (Exception ignoreEOS) {}
return null; return null;
} }

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.util; package com.boydti.fawe.util;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.exception.FaweException;
@ -9,6 +10,7 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
@ -166,6 +168,11 @@ public class DelegateFaweQueue extends FaweQueue {
return parent.cancel(); return parent.cancel();
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
parent.sendBlockUpdate(blockMap, players);
}
@Override @Override
public boolean next() { public boolean next() {
return parent.next(); return parent.next();

View File

@ -65,9 +65,7 @@ public class MathMan {
} }
public static final short tripleBlockCoord(int x, int y, int z) { public static final short tripleBlockCoord(int x, int y, int z) {
byte hi = (byte) ((x & 15) + ((z & 15) << 4)); return (short) ((x & 15) << 12 | (z & 15) << 8 | y);
byte lo = (byte) y;
return (short) (((hi & 0xFF) << 8) | (lo & 0xFF));
} }
public static final long chunkXZ2Int(int x, int z) { public static final long chunkXZ2Int(int x, int z) {

View File

@ -197,6 +197,9 @@ public final class NBTInputStream implements Closeable {
return; return;
case NBTConstants.TYPE_LIST: case NBTConstants.TYPE_LIST:
int childType = is.readByte(); int childType = is.readByte();
if (childType == NBTConstants.TYPE_LIST) {
childType = NBTConstants.TYPE_COMPOUND;
}
length = is.readInt(); length = is.readInt();
reader = getReader.runAndGet(node + ".?", null).value2; reader = getReader.runAndGet(node + ".?", null).value2;
if (reader != null) { if (reader != null) {
@ -307,6 +310,9 @@ public final class NBTInputStream implements Closeable {
return (new String(bytes, NBTConstants.CHARSET)); return (new String(bytes, NBTConstants.CHARSET));
case NBTConstants.TYPE_LIST: case NBTConstants.TYPE_LIST:
int childType = is.readByte(); int childType = is.readByte();
if (childType == NBTConstants.TYPE_LIST) {
childType = NBTConstants.TYPE_COMPOUND;
}
length = is.readInt(); length = is.readInt();
List<Tag> tagList = new ArrayList<Tag>(); List<Tag> tagList = new ArrayList<Tag>();
for (int i = 0; i < length; ++i) { 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)); return new StringTag(new String(bytes, NBTConstants.CHARSET));
case NBTConstants.TYPE_LIST: case NBTConstants.TYPE_LIST:
int childType = is.readByte(); int childType = is.readByte();
if (childType == NBTConstants.TYPE_LIST) {
childType = NBTConstants.TYPE_COMPOUND;
}
length = is.readInt(); length = is.readInt();
List<Tag> tagList = new ArrayList<Tag>(); List<Tag> tagList = new ArrayList<Tag>();
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {

View File

@ -89,6 +89,10 @@ public final class NBTOutputStream implements Closeable {
writeTagPayload(tag); writeTagPayload(tag);
} }
public void writeEndTag() throws IOException {
os.writeByte(NBTConstants.TYPE_END);
}
/** /**
* Writes tag payload. * Writes tag payload.
* *
@ -194,8 +198,12 @@ public final class NBTOutputStream implements Closeable {
Class<? extends Tag> clazz = tag.getType(); Class<? extends Tag> clazz = tag.getType();
List<Tag> tags = tag.getValue(); List<Tag> tags = tag.getValue();
int size = tags.size(); int size = tags.size();
if (!tags.isEmpty()) {
os.writeByte(NBTUtils.getTypeCode(clazz)); Tag tag0 = tags.get(0);
os.writeByte(NBTUtils.getTypeCode(tag0.getClass()));
} else {
os.writeByte(NBTUtils.getTypeCode(clazz));
}
os.writeInt(size); os.writeInt(size);
for (Tag tag1 : tags) { for (Tag tag1 : tags) {
writeTagPayload(tag1); writeTagPayload(tag1);

View File

@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -343,12 +341,15 @@ public class ForgeChunk_All extends CharFaweChunk<Chunk, ForgeQueue_All> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag);

View File

@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.forge.ForgePlayer;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
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.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.SPacketChunkData; 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.PlayerChunkMap;
import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -97,6 +103,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue<World, Chunk, ExtendedBlo
} }
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (Map.Entry<Long, Map<Short, Short>> chunkEntry : blockMap.entrySet()) {
try {
long chunkHash = chunkEntry.getKey();
Map<Short, Short> 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<Short, Short> 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); protected BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(0, 0, 0);
@Override @Override

View File

@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -357,12 +355,15 @@ public class ForgeChunk_All extends CharFaweChunk<Chunk, ForgeQueue_All> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag);

View File

@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.forge.ForgePlayer;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
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.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.SPacketChunkData; 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.PlayerChunkMap;
import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -82,6 +88,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue<World, Chunk, ExtendedBlo
getImpWorld(); getImpWorld();
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (Map.Entry<Long, Map<Short, Short>> chunkEntry : blockMap.entrySet()) {
try {
long chunkHash = chunkEntry.getKey();
Map<Short, Short> 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<Short, Short> 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 @Override
public void setHeightMap(FaweChunk chunk, byte[] heightMap) { public void setHeightMap(FaweChunk chunk, byte[] heightMap) {
Chunk forgeChunk = (Chunk) chunk.getChunk(); Chunk forgeChunk = (Chunk) chunk.getChunk();

View File

@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -304,16 +302,16 @@ public class ForgeChunk_All extends CharFaweChunk<Chunk, ForgeQueue_All> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
int bx = this.getX() << 4; int bx = this.getX() << 4;
int bz = this.getZ() << 4; int bz = this.getZ() << 4;
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
int x = MathMan.unpair16x((byte) pair.get0()) + bx; int x = (blockHash >> 12 & 0xF) + bx;
int y = pair.get1() & 0xFF; int y = (blockHash & 0xFF);
int z = MathMan.unpair16y((byte) pair.get0()) + bz; int z = (blockHash >> 8 & 0xF) + bz;
TileEntity tileEntity = nmsWorld.getTileEntity(x, y, z); TileEntity tileEntity = nmsWorld.getTileEntity(x, y, z);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag);

View File

@ -3,7 +3,9 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.forge.ForgePlayer;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.IntegerPair;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.MainUtil; 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.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S21PacketChunkData; import net.minecraft.network.play.server.S21PacketChunkData;
import net.minecraft.network.play.server.S22PacketMultiBlockChange;
import net.minecraft.server.management.PlayerManager; import net.minecraft.server.management.PlayerManager;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.LongHashMap; import net.minecraft.util.LongHashMap;
@ -283,6 +289,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue<World, Chunk, ExtendedBlo
return false; return false;
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (Map.Entry<Long, Map<Short, Short>> chunkEntry : blockMap.entrySet()) {
try {
long chunkHash = chunkEntry.getKey();
Map<Short, Short> 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<Short, Short> 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 { public void setCount(int tickingBlockCount, int nonEmptyBlockCount, ExtendedBlockStorage section) throws NoSuchFieldException, IllegalAccessException {
Class<? extends ExtendedBlockStorage> clazz = section.getClass(); Class<? extends ExtendedBlockStorage> clazz = section.getClass();
Field fieldTickingBlockCount = clazz.getDeclaredField("field_76683_c"); // tickRefCount Field fieldTickingBlockCount = clazz.getDeclaredField("field_76683_c"); // tickRefCount

View File

@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -258,11 +256,14 @@ public class ForgeChunk_All extends CharFaweChunk<Chunk, ForgeQueue_All> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag);

View File

@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.forge.ForgePlayer;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
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.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -26,7 +30,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S21PacketChunkData; import net.minecraft.network.play.server.S21PacketChunkData;
import net.minecraft.network.play.server.S22PacketMultiBlockChange;
import net.minecraft.server.management.PlayerManager; import net.minecraft.server.management.PlayerManager;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
@ -197,6 +203,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue<World, Chunk, ExtendedBlo
return (int) fieldNonEmptyBlockCount.get(section); return (int) fieldNonEmptyBlockCount.get(section);
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (Map.Entry<Long, Map<Short, Short>> chunkEntry : blockMap.entrySet()) {
try {
long chunkHash = chunkEntry.getKey();
Map<Short, Short> 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<Short, Short> 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 @Override
public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map<?, ?> tilesGeneric, Collection<?>[] entitiesGeneric, Set<UUID> createdEntities, boolean all) throws Exception { public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map<?, ?> tilesGeneric, Collection<?>[] entitiesGeneric, Set<UUID> createdEntities, boolean all) throws Exception {
Map<BlockPos, TileEntity> tiles = (Map<BlockPos, TileEntity>) tilesGeneric; Map<BlockPos, TileEntity> tiles = (Map<BlockPos, TileEntity>) tilesGeneric;

View File

@ -3,10 +3,8 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweQueue; 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.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
@ -341,12 +339,15 @@ public class ForgeChunk_All extends CharFaweChunk<Chunk, ForgeQueue_All> {
} }
} }
// Set tiles // Set tiles
Map<BytePair, CompoundTag> tilesToSpawn = this.getTiles(); Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
for (Map.Entry<BytePair, CompoundTag> entry : tilesToSpawn.entrySet()) { for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue(); CompoundTag nativeTag = entry.getValue();
BytePair pair = entry.getKey(); short blockHash = entry.getKey();
BlockPos pos = new BlockPos(MathMan.unpair16x((byte) pair.get0()) + bx, pair.get1() & 0xFF, MathMan.unpair16y((byte) pair.get0()) + bz); // Set pos 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); TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag); NBTTagCompound tag = (NBTTagCompound) ForgeQueue_All.methodFromNative.invoke(null, nativeTag);

View File

@ -3,13 +3,17 @@ package com.boydti.fawe.forge.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.forge.ForgePlayer;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
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.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -29,7 +33,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.SPacketChunkData; 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.PlayerChunkMap;
import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -235,6 +241,34 @@ public class ForgeQueue_All extends NMSMappedFaweQueue<World, Chunk, ExtendedBlo
fieldNonEmptyBlockCount.set(section, nonEmptyBlockCount); fieldNonEmptyBlockCount.set(section, nonEmptyBlockCount);
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
for (Map.Entry<Long, Map<Short, Short>> chunkEntry : blockMap.entrySet()) {
try {
long chunkHash = chunkEntry.getKey();
Map<Short, Short> 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<Short, Short> 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 @Override
public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map<?, ?> tilesGeneric, Collection<?>[] entitiesGeneric, Set<UUID> createdEntities, boolean all) throws Exception { public CharFaweChunk getPrevious(CharFaweChunk fs, ExtendedBlockStorage[] sections, Map<?, ?> tilesGeneric, Collection<?>[] entitiesGeneric, Set<UUID> createdEntities, boolean all) throws Exception {
Map<BlockPos, TileEntity> tiles = (Map<BlockPos, TileEntity>) tilesGeneric; Map<BlockPos, TileEntity> tiles = (Map<BlockPos, TileEntity>) tilesGeneric;

View File

@ -7,18 +7,24 @@ import cn.nukkit.level.Level;
import cn.nukkit.level.Position; import cn.nukkit.level.Position;
import cn.nukkit.level.format.generic.BaseFullChunk; import cn.nukkit.level.format.generic.BaseFullChunk;
import cn.nukkit.math.Vector3; import cn.nukkit.math.Vector3;
import cn.nukkit.network.protocol.UpdateBlockPacket;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.nukkit.core.NBTConverter; import com.boydti.fawe.nukkit.core.NBTConverter;
import com.boydti.fawe.nukkit.optimization.FaweNukkit; 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.FaweChunk;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -117,6 +123,43 @@ public class NukkitQueue extends NMSMappedFaweQueue<Level, BaseFullChunk, BaseFu
return new File("worlds" + File.separator + world.getFolderName() + File.separator + "region"); return new File("worlds" + File.separator + world.getFolderName() + File.separator + "region");
} }
@Override
public void sendBlockUpdate(Map<Long, Map<Short, Short>> blockMap, FawePlayer... players) {
ArrayList<Block> blocks = new ArrayList<Block>();
for (Map.Entry<Long, Map<Short, Short>> entry : blockMap.entrySet()) {
long chunkHash = entry.getKey();
int cx = MathMan.unpairIntX(chunkHash);
int cz = MathMan.unpairIntY(chunkHash);
Map<Short, Short> ids = entry.getValue();
for (Map.Entry<Short, Short> 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<Level, List<Player>> playerMap = new HashMap<>();
for (FawePlayer player : players) {
Player nukkitPlayer = ((FaweNukkitPlayer) player).parent;
List<Player> 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<Level, List<Player>> levelListEntry : playerMap.entrySet()) {
List<Player> playerList = levelListEntry.getValue();
levelListEntry.getKey().sendBlocks(playerList.toArray(new Player[playerList.size()]), blocksArray, UpdateBlockPacket.FLAG_ALL_PRIORITY);
}
}
@Override @Override
public boolean hasSky() { public boolean hasSky() {
return world.getDimension() == 0; return world.getDimension() == 0;