Search in sources :

Example 1 with IConvertingHandler

use of de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler in project Vampirism by TeamLapen.

the class VampirismEntityRegistry method applyNewResources.

public void applyNewResources(Map<ResourceLocation, Integer> valuesIn, int multiplier) {
    this.bloodValues.putAll(valuesIn);
    this.bloodMultiplier = multiplier;
    Map<ResourceLocation, BiteableEntry> biteables = Maps.newHashMap();
    Set<ResourceLocation> blacklist = Sets.newHashSet();
    float bloodValueMultiplier = bloodMultiplier / 10F;
    final IConvertingHandler defaultHandler = defaultConvertingHandlerCreator.apply(null);
    for (Map.Entry<EntityType<? extends CreatureEntity>, IConvertingHandler> entry : convertibles.entrySet()) {
        ResourceLocation id = entry.getKey().getRegistryName();
        if (id == null) {
            LOGGER.warn("Cannot register convertible {} since there is no EntityString for it", entry.getKey());
            continue;
        }
        Integer blood = valuesIn.remove(id);
        if (blood == null) {
            LOGGER.warn("Missing blood value for convertible creature {} ({})", entry.getKey().getDescription(), id);
            continue;
        }
        blood = Math.round(blood * bloodValueMultiplier);
        LOGGER.debug("Registering convertible {} with blood {} and handler {}", entry.getKey().getDescription().getString(), blood, entry.getValue().getClass().getName());
        BiteableEntry biteEntry = new BiteableEntry(blood, (entry.getValue() == null ? defaultHandler : entry.getValue()));
        biteables.put(id, biteEntry);
    }
    LOGGER.info("Registered {} convertibles", biteables.size());
    for (Map.Entry<ResourceLocation, Integer> entry : valuesIn.entrySet()) {
        int blood = Math.abs(Math.round(entry.getValue() * bloodValueMultiplier));
        if (blood == 0) {
            blacklist.add(entry.getKey());
        } else {
            biteables.put(entry.getKey(), new BiteableEntry(blood));
        }
    }
    biteableEntryManager.setNewBiteables(biteables, blacklist);
}
Also used : CreatureEntity(net.minecraft.entity.CreatureEntity) IConvertingHandler(de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler) EntityType(net.minecraft.entity.EntityType) ResourceLocation(net.minecraft.util.ResourceLocation) BiteableEntry(de.teamlapen.vampirism.api.entity.BiteableEntry) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with IConvertingHandler

use of de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler in project Vampirism by TeamLapen.

the class ConvertedCreatureEntity method getConvertedHelper.

/**
 * @return The {@link de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler.IDefaultHelper} for this creature
 */
@Nullable
protected IConvertingHandler.IDefaultHelper getConvertedHelper() {
    if (nil())
        return null;
    BiteableEntry biteableEntry = VampirismAPI.entityRegistry().getEntry(entityCreature);
    if (biteableEntry == null) {
        LOGGER.warn("Cannot find biteable entry for {}", entityCreature);
        return null;
    }
    IConvertingHandler handler = biteableEntry.convertingHandler;
    if (handler instanceof DefaultConvertingHandler) {
        return ((DefaultConvertingHandler) handler).getHelper();
    }
    return null;
}
Also used : IConvertingHandler(de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler) BiteableEntry(de.teamlapen.vampirism.api.entity.BiteableEntry) Nullable(javax.annotation.Nullable)

Aggregations

BiteableEntry (de.teamlapen.vampirism.api.entity.BiteableEntry)2 IConvertingHandler (de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Nullable (javax.annotation.Nullable)1 CreatureEntity (net.minecraft.entity.CreatureEntity)1 EntityType (net.minecraft.entity.EntityType)1 ResourceLocation (net.minecraft.util.ResourceLocation)1