Search in sources :

Example 1 with Int2IntOpenHashMap

use of com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap in project ViaBackwards by ViaVersion.

the class EntityRewriterBase method mapTypes.

/**
 * Maps entity ids based on the enum constant's names.
 *
 * @param oldTypes     entity types of the higher version
 * @param newTypeClass entity types enum class of the lower version
 * @param <E>          new enum type
 */
@Override
public <E extends Enum<E> & EntityType> void mapTypes(EntityType[] oldTypes, Class<E> newTypeClass) {
    if (typeMappings == null) {
        typeMappings = new Int2IntOpenHashMap(oldTypes.length, 0.99F);
        typeMappings.defaultReturnValue(-1);
    }
    for (EntityType oldType : oldTypes) {
        try {
            E newType = Enum.valueOf(newTypeClass, oldType.name());
            typeMappings.put(oldType.getId(), newType.getId());
        } catch (IllegalArgumentException ignored) {
        // Don't warn
        }
    }
}
Also used : EntityType(com.viaversion.viaversion.api.minecraft.entities.EntityType) Int2IntOpenHashMap(com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap)

Aggregations

EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)1 Int2IntOpenHashMap (com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap)1