<commit_before>package cat.nyaa.nyaacore.utils;

import net.minecraft.core.IRegistry;
import net.minecraft.network.syncher.DataWatcherObject;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes;
import org.bukkit.entity.EntityType;

import java.lang.reflect.Field;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

public class EntityUtils {
    public static AtomicInteger FAKE_ENTITY_COUNTER = new AtomicInteger(0xffcc);

    public static int getNewEntityId() {
        try {
            Field ENTITY_COUNTER = Entity.class.getDeclaredField("ENTITY_COUNTER");
            return ((AtomicInteger) ENTITY_COUNTER.get(null)).incrementAndGet();
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
        }
        return -FAKE_ENTITY_COUNTER.incrementAndGet();
    }

    public static Optional<Integer> getEntityTypeId(EntityType entityType) {
        Optional<EntityTypes<?>> entityTypesOptional = EntityTypes.byString(entityType.getKey().getKey());
        return entityTypesOptional.map(IRegistry.ENTITY_TYPE::getId);
    }

    /**
     * no cache
     *
     * @param entityClass         target class
     * @param EntityDataFieldName automatic obfuscation
     * @return entityDataIdOptional
     */
    public static Optional<Integer> getEntityDataId(Class<? extends net.minecraft.world.entity.Entity> entityClass, String EntityDataFieldName) {<commit_msg>update EntityUtils<commit_after>package cat.nyaa.nyaacore.utils;

import net.minecraft.core.IRegistry;
import net.minecraft.network.syncher.DataWatcherObject;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes;
import org.bukkit.entity.EntityType;

import java.lang.reflect.Field;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

public class EntityUtils {
    public static AtomicInteger FAKE_ENTITY_COUNTER = new AtomicInteger(0xffcc);

    public static int getNewEntityId() {
        try {
            Field ENTITY_COUNTER = Entity.class.getDeclaredField("ENTITY_COUNTER");
            return ((AtomicInteger) ENTITY_COUNTER.get(null)).incrementAndGet();
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
        }
        return -FAKE_ENTITY_COUNTER.incrementAndGet();
    }

    private static Optional<EntityTypes<?>> getNmsEntityTypes(EntityType entityType) {
        return EntityTypes.byString(entityType.getKey().getKey());
    }
    public static Optional<Integer> getEntityTypeId(EntityType entityType) {
        return getNmsEntityTypes(entityType).map(IRegistry.ENTITY_TYPE::getId);
    }
    public static int getUpdateInterval(EntityType entityType) {
        return getNmsEntityTypes(entityType).map(EntityTypes::updateInterval).orElse(3);
    }
    public static int getClientTrackingRange(EntityType entityType){
        return getNmsEntityTypes(entityType).map(EntityTypes::clientTrackingRange).orElse(5);
    }

    /**
     * no cache
     *
     * @param entityClass         target class
     * @param EntityDataFieldName automatic obfuscation
     * @return entityDataIdOptional
     */
    public static Optional<Integer> getEntityDataId(Class<? extends net.minecraft.world.entity.Entity> entityClass, String EntityDataFieldName) {
{'fraction_non_alphanumeric': 0.09372156505914468, 'fraction_numerical': 0.001213224143160449, 'mean_word_length': 4.153125, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1082903', 'n_tokens_mistral': 943, 'n_tokens_neox': 946, 'n_words': 169}