package protocolsupport.protocol.packet.middleimpl.clientbound.play.v_5_6_7;

import protocolsupport.api.ProtocolVersion;
import protocolsupport.protocol.packet.ClientBoundPacket;
import protocolsupport.protocol.packet.middle.clientbound.play.MiddleWorldParticle;
import protocolsupport.protocol.packet.middleimpl.ClientBoundPacketData;
import protocolsupport.protocol.serializer.StringSerializer;
import protocolsupport.protocol.typeremapper.id.IdRemapper;
import protocolsupport.protocol.typeremapper.itemstack.ItemStackRemapper;
import protocolsupport.protocol.utils.minecraftdata.MinecraftData;
import protocolsupport.utils.IntTuple;
import protocolsupport.utils.recyclable.RecyclableCollection;
import protocolsupport.utils.recyclable.RecyclableSingletonList;

public class WorldParticle extends MiddleWorldParticle {

	@Override
	public RecyclableCollection<ClientBoundPacketData> toData() {
		ProtocolVersion version = connection.getVersion();
		ClientBoundPacketData serializer = ClientBoundPacketData.create(ClientBoundPacket.PLAY_WORLD_PARTICLES_ID);
		String name = type.getName();
		switch (type) {
			case ITEM_CRACK: {
				IntTuple iddata = ItemStackRemapper.ID_DATA_REMAPPING_REGISTRY.getTable(version).getRemap(adddata.get(0), adddata.get(1));
				if (iddata != null) {
					name += "_" + iddata.getI1() + "_" + (iddata.getI2() != -1 ? iddata.getI2() : adddata.get(1));
				} else {
					name += "_" + adddata.get(0) + "_" +  adddata.get(1);
				}
				break;
			}
			case BLOCK_CRACK:
			case BLOCK_DUST: {
				int blockstate = adddata.get(0);
				blockstate = IdRemapper.BLOCK.getTable(version).getRemap(MinecraftData.getBlockStateFromIdAndData(blockstate & 4095, blockstate >> 12));
				name += "_" + MinecraftData.getBlockIdFromState(blockstate) + "_" + MinecraftData.getBlockDataFromState(blockstate);
				break;
			}
			default: {
				break;
			}
		}
		StringSerializer.writeString(serializer, version, name);
		serializer.writeFloat(x);
		serializer.writeFloat(y);
		serializer.writeFloat(z);
		serializer.writeFloat(offX);
		serializer.writeFloat(offY);
		serializer.writeFloat(offZ);
		serializer.writeFloat(speed);
		serializer.writeInt(Math.max(count, 1));
		return RecyclableSingletonList.create(serializer);
	}

}

@@ -1865,16 +1865,111 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09if (version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_6_4) && count == 0) %7B%0A%09%09%09count = 1;%0A%09%09%7D%0A
 %09%09String
@@ -2254,26 +2254,13 @@
 Int(
-Math.max(
 count
-, 1)
 );%0A%09

Edit to version check