Move EntityNBT to different file and fix the issue to do with respawn chunks unloading. #287

This commit is contained in:
Myles 2016-03-29 15:01:38 +01:00
parent d72b7fc4df
commit 1b99e2cf57
2 changed files with 28 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.Material; import org.bukkit.Material;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -157,7 +158,7 @@ public class EntityPackets {
Item stack = wrapper.get(Type.ITEM, 0); Item stack = wrapper.get(Type.ITEM, 0);
if (stack != null) { if (stack != null) {
if(Material.getMaterial(stack.getId()) != null) { if (Material.getMaterial(stack.getId()) != null) {
if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) { if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) {
entityTracker.getValidBlocking().add(entityID); entityTracker.getValidBlocking().add(entityID);
return; return;
@ -225,6 +226,24 @@ public class EntityPackets {
} }
}); });
// Update Entity NBT
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// int id = wrapper.read(Type.VAR_INT);
// CompoundTag tag = wrapper.read(Type.NBT);
// System.out.println(id + " - " + tag);
wrapper.cancel();
}
});
}
});
/* Packets which do not have any field remapping or handlers */ /* Packets which do not have any field remapping or handlers */
protocol.registerOutgoing(State.PLAY, 0x20, 0x4B); // Entity Properties Packet protocol.registerOutgoing(State.PLAY, 0x20, 0x4B); // Entity Properties Packet

View File

@ -15,6 +15,7 @@ import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.PlayerMovementMapper; import us.myles.ViaVersion.protocols.protocol1_9to1_8.PlayerMovementMapper;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
public class PlayerPackets { public class PlayerPackets {
@ -145,7 +146,7 @@ public class PlayerPackets {
// Parse this info // Parse this info
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception{ public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.INT, 0); int entityID = wrapper.get(Type.INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class); EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getClientEntityTypes().put(entityID, EntityType.PLAYER); tracker.getClientEntityTypes().put(entityID, EntityType.PLAYER);
@ -254,19 +255,6 @@ public class PlayerPackets {
} }
}); });
// Update Entity NBT
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Set Compression // Set Compression
protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() {
@Override @Override
@ -415,6 +403,12 @@ public class PlayerPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0); int action = wrapper.get(Type.VAR_INT, 0);
if (action == 0) {
// Client unloads chunks on respawn, take note
ClientChunks cc = wrapper.user().get(ClientChunks.class);
cc.getBulkChunks().clear();
cc.getLoadedChunks().clear();
}
if (action == 2) { if (action == 2) {
// cancel any blocking >.> // cancel any blocking >.>
EntityTracker tracker = wrapper.user().get(EntityTracker.class); EntityTracker tracker = wrapper.user().get(EntityTracker.class);