<commit_before>package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;

import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.VillagerData;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;

import java.util.ArrayList;
import java.util.List;

public class MetadataRewriter {

    public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
        for (Metadata metadata : new ArrayList<>(metadatas)) {
            try {
                metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));

                EntityTracker tracker = connection.get(EntityTracker.class);

                if (metadata.getMetaType() == MetaType1_14.Slot) {
                    InventoryPackets.toClient((Item) metadata.getValue());
                } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
                    // Convert to new block id
                    int data = (int) metadata.getValue();
                    metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
                }

                if (type == null) continue;

                //Metadata 6 added to abstract_entity
                if (metadata.getId() > 5) {
                    metadata.setId(metadata.getId() + 1);
                }

                //Metadata 12 added to living_entity
                if (metadata.getId() > 11 && type.isOrHasParent(Entity1_14Types.EntityType.LIVINGENTITY)) {
                    metadata.setId(metadata.getId() + 1);
                }

                if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
                    if (metadata.getId() == 10) {
                        // New block format
                        int data = (int) metadata.getValue();
                        metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
                    }
                }

                if (type.is(Entity1_14Types.EntityType.HORSE)) {
                    if (metadata.getId() == 18) {
                        metadatas.remove(metadata);

                        int armorType = (int) metadata.getValue();
                        Item armorItem = null;
                        if (armorType == 1) {  //iron armor
                            armorItem = new Item(InventoryPackets.getNewItemId(727), (byte) 1, (short) 0, null);
                        } else if (armorType == 2) {  //gold armor
                            armorItem = new Item(InventoryPackets.getNewItemId(728), (byte) 1, (short) 0, null);
                        } else if (armorType == 3) {  //diamond armor
                            armorItem = new Item(InventoryPackets.getNewItemId(729), (byte) 1, (short) 0, null);
                        }

                        PacketWrapper equipmentPacket = new PacketWrapper(0x42, null, connection);
                        equipmentPacket.write(Type.VAR_INT, entityId);
                        equipmentPacket.write(Type.VAR_INT, 4);
                        equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
                        equipmentPacket.send(Protocol1_14To1_13_2.class);
                    }
                }

                if (type.is(Entity1_14Types.EntityType.VILLAGER)) {
                    if (metadata.getId() == 15) {
                        // plains
                        metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
                        metadata.setMetaType(MetaType1_14.VillagerData);
                    }<commit_msg>fix horse equipment packet id<commit_after>package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;

import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.VillagerData;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;

import java.util.ArrayList;
import java.util.List;

public class MetadataRewriter {

    public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
        for (Metadata metadata : new ArrayList<>(metadatas)) {
            try {
                metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));

                EntityTracker tracker = connection.get(EntityTracker.class);

                if (metadata.getMetaType() == MetaType1_14.Slot) {
                    InventoryPackets.toClient((Item) metadata.getValue());
                } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
                    // Convert to new block id
                    int data = (int) metadata.getValue();
                    metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
                }

                if (type == null) continue;

                //Metadata 6 added to abstract_entity
                if (metadata.getId() > 5) {
                    metadata.setId(metadata.getId() + 1);
                }

                //Metadata 12 added to living_entity
                if (metadata.getId() > 11 && type.isOrHasParent(Entity1_14Types.EntityType.LIVINGENTITY)) {
                    metadata.setId(metadata.getId() + 1);
                }

                if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
                    if (metadata.getId() == 10) {
                        // New block format
                        int data = (int) metadata.getValue();
                        metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
                    }
                }

                if (type.is(Entity1_14Types.EntityType.HORSE)) {
                    if (metadata.getId() == 18) {
                        metadatas.remove(metadata);

                        int armorType = (int) metadata.getValue();
                        Item armorItem = null;
                        if (armorType == 1) {  //iron armor
                            armorItem = new Item(InventoryPackets.getNewItemId(727), (byte) 1, (short) 0, null);
                        } else if (armorType == 2) {  //gold armor
                            armorItem = new Item(InventoryPackets.getNewItemId(728), (byte) 1, (short) 0, null);
                        } else if (armorType == 3) {  //diamond armor
                            armorItem = new Item(InventoryPackets.getNewItemId(729), (byte) 1, (short) 0, null);
                        }

                        PacketWrapper equipmentPacket = new PacketWrapper(0x46, null, connection);
                        equipmentPacket.write(Type.VAR_INT, entityId);
                        equipmentPacket.write(Type.VAR_INT, 4);
                        equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
                        equipmentPacket.send(Protocol1_14To1_13_2.class);
                    }
                }

                if (type.is(Entity1_14Types.EntityType.VILLAGER)) {
                    if (metadata.getId() == 15) {
                        // plains
                        metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
                        metadata.setMetaType(MetaType1_14.VillagerData);
                    }
{'fraction_non_alphanumeric': 0.10077896786757547, 'fraction_numerical': 0.02750730282375852, 'mean_word_length': 1.824682021313166, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22477', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2239, 'n_words': 380}