use of de.teamlapen.vampirism.api.entity.BiteableEntry 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);
}
use of de.teamlapen.vampirism.api.entity.BiteableEntry 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;
}
use of de.teamlapen.vampirism.api.entity.BiteableEntry in project Vampirism by TeamLapen.
the class ExtendedCreature method tick.
@Override
public void tick() {
if (!entity.getCommandSenderWorld().isClientSide) {
/*
* Make sure all entities with no blood die
* check for sanguinare as the entity might converted instead of dying
*/
if (blood == 0 && entity.tickCount % 20 == 10 && entity.getEffect(ModEffects.sanguinare) == null) {
entity.hurt(VReference.NO_BLOOD, 1000);
}
if (blood > 0 && blood < getMaxBlood() && entity.tickCount % 40 == 8) {
entity.addEffect(new EffectInstance(Effects.WEAKNESS, 41));
entity.addEffect(new EffectInstance(Effects.MOVEMENT_SLOWDOWN, 41, 2));
if (entity.getRandom().nextInt(BalanceMobProps.mobProps.BLOOD_REGEN_CHANCE) == 0) {
setBlood(getBlood() + 1);
sync();
}
}
}
if (markForBloodCalculation) {
if (VampirismEntityRegistry.biteableEntryManager.init()) {
BiteableEntry entry = VampirismEntityRegistry.biteableEntryManager.calculate(entity);
if (entry != null) {
setMaxBlood(entry.blood);
}
markForBloodCalculation = false;
}
}
if (this.remainingBarkTicks > 0) {
--this.remainingBarkTicks;
}
}
use of de.teamlapen.vampirism.api.entity.BiteableEntry in project Vampirism by TeamLapen.
the class VampirismEntityRegistry method convert.
@Override
@Nullable
@SuppressWarnings("unchecked")
public IConvertedCreature convert(CreatureEntity entity) {
BiteableEntry b = biteableEntryManager.get(entity);
if (b != null && b.convertingHandler != null) {
return b.convertingHandler.createFrom(entity);
}
LOGGER.warn("Failed to find convertible entry for {}", entity);
return null;
}
use of de.teamlapen.vampirism.api.entity.BiteableEntry in project Vampirism by TeamLapen.
the class BiteableEntryManager method addCalculated.
/**
* Adds a calculated value.
*
* @return The created entry
*/
private BiteableEntry addCalculated(ResourceLocation id, int blood) {
BiteableEntry existing = calculated.containsKey(id) ? calculated.get(id).modifyBloodValue(blood) : new BiteableEntry(blood);
calculated.put(id, existing);
return existing;
}
Aggregations