package protocolsupport.protocol.transformer.middlepacketimpl.clientbound.play.v_1_8;

import java.io.IOException;

import protocolsupport.api.ProtocolVersion;
import protocolsupport.protocol.ClientBoundPacket;
import protocolsupport.protocol.transformer.middlepacket.clientbound.play.MiddleSpawnObject;
import protocolsupport.protocol.transformer.middlepacketimpl.PacketData;
import protocolsupport.protocol.typeremapper.id.IdRemapper;
import protocolsupport.utils.recyclable.RecyclableCollection;
import protocolsupport.utils.recyclable.RecyclableSingletonList;

public class SpawnObject extends MiddleSpawnObject<RecyclableCollection<PacketData>> {

	@Override
	public RecyclableCollection<PacketData> toData(ProtocolVersion version) throws IOException {
		if (type == 70) {
			int id = IdRemapper.BLOCK.getTable(version).getRemap((objectdata & 4095) << 4) >> 4;
			int data = (objectdata >> 12) & 0xF;
			objectdata = (data << 12) | id;
		}
		PacketData serializer = PacketData.create(ClientBoundPacket.PLAY_SPAWN_OBJECT_ID, version);
		serializer.writeVarInt(entityId);
		serializer.writeByte(IdRemapper.ENTITY_OBJECT.getTable(version).getRemap(type));
		serializer.writeInt((int) x * 32);
		serializer.writeInt((int) y * 32);
		serializer.writeInt((int) z * 32);
		serializer.writeByte(pitch);
		serializer.writeByte(yaw);
		serializer.writeInt(objectdata);
		if (objectdata > 0) {
			serializer.writeShort(motX);
			serializer.writeShort(motY);
			serializer.writeShort(motZ);
		}
		return RecyclableSingletonList.create(serializer);
	}

}

@@ -1183,15 +1183,17 @@
 nt) 
+(
 x * 32)
+)
 ;%0A%09%09
@@ -1222,15 +1222,17 @@
 nt) 
+(
 y * 32)
+)
 ;%0A%09%09
@@ -1261,15 +1261,17 @@
 nt) 
+(
 z * 32)
+)
 ;%0A%09%09

Fix spawn object coords for 1.8