Search in sources :

Example 1 with PehkuiEntityExtensions

use of virtuoel.pehkui.util.PehkuiEntityExtensions in project Pehkui by Virtuoel.

the class ScaleData method getScale.

/**
 * Gets the scale with modifiers applied
 *
 * @param delta Tick delta for use with rendering. Use 1.0F if no delta is available.
 * @return Scale with modifiers applied
 */
public float getScale(float delta) {
    final Entity e = getEntity();
    final boolean canCache = delta == 1.0F && e != null && e.world != null && !e.world.isClient && (e.getType() != EntityType.PLAYER || !getScaleType().getAffectsDimensions()) && !((PehkuiEntityExtensions) e).pehkui_isFirstUpdate();
    if (canCache && !Float.isNaN(cachedScale)) {
        return cachedScale;
    }
    float value = getBaseScale(delta);
    for (final ScaleModifier m : getBaseValueModifiers()) {
        value = m.modifyScale(this, value, delta);
    }
    if (canCache) {
        cachedScale = value;
    }
    return value;
}
Also used : Entity(net.minecraft.entity.Entity) PehkuiEntityExtensions(virtuoel.pehkui.util.PehkuiEntityExtensions)

Example 2 with PehkuiEntityExtensions

use of virtuoel.pehkui.util.PehkuiEntityExtensions in project Pehkui by Virtuoel.

the class PehkuiEntitySelectorOptions method register.

public static void register() {
    EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale").toString().replace(':', '.'), r -> cast(r).pehkui_setScaleRange(FloatRange.parse(r.getReader())), r -> cast(r).pehkui_getScaleRange().isDummy(), SCALE_RANGE_DESCRIPTION);
    EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale_type").toString().replace(':', '.'), r -> cast(r).pehkui_setScaleType(parseScaleType(r)), r -> cast(r).pehkui_getScaleType() == ScaleTypes.INVALID, SCALE_TYPE_DESCRIPTION);
    EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("computed_scale").toString().replace(':', '.'), r -> cast(r).pehkui_setComputedScaleRange(FloatRange.parse(r.getReader())), r -> cast(r).pehkui_getComputedScaleRange().isDummy(), SCALE_RANGE_DESCRIPTION);
    EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("computed_scale_type").toString().replace(':', '.'), r -> cast(r).pehkui_setComputedScaleType(parseScaleType(r)), r -> cast(r).pehkui_getComputedScaleType() == ScaleTypes.INVALID, SCALE_TYPE_DESCRIPTION);
    EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale_nbt").toString().replace(':', '.'), r -> {
        final boolean negated = r.readNegationCharacter();
        final NbtCompound parsed = (new StringNbtReader(r.getReader())).parseCompound();
        r.setPredicate(entity -> {
            final NbtCompound nbt = ((PehkuiEntityExtensions) entity).pehkui_writeScaleNbt(new NbtCompound());
            return NbtHelper.matches(parsed, nbt, true) != negated;
        });
    }, reader -> true, SCALE_NBT_DESCRIPTION);
}
Also used : StringNbtReader(net.minecraft.nbt.StringNbtReader) NbtCompound(net.minecraft.nbt.NbtCompound) PehkuiEntityExtensions(virtuoel.pehkui.util.PehkuiEntityExtensions)

Aggregations

PehkuiEntityExtensions (virtuoel.pehkui.util.PehkuiEntityExtensions)2 Entity (net.minecraft.entity.Entity)1 NbtCompound (net.minecraft.nbt.NbtCompound)1 StringNbtReader (net.minecraft.nbt.StringNbtReader)1