• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MutableBoundedValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongepowered.api.data.value.mutable.MutableBoundedValue的典型用法代码示例。如果您正苦于以下问题:Java MutableBoundedValue类的具体用法?Java MutableBoundedValue怎么用?Java MutableBoundedValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MutableBoundedValue类属于org.spongepowered.api.data.value.mutable包,在下文中一共展示了MutableBoundedValue类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: registerKeys

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public void registerKeys() {
    super.registerKeys();
    final ValueCollection c = getValueCollection();
    c.register(Keys.MAX_AIR, 300, 0, Integer.MAX_VALUE);
    c.register(Keys.REMAINING_AIR, 300, 0, Keys.MAX_AIR);
    c.register(Keys.MAX_HEALTH, 20.0, 0.0, 1024.0);
    c.register(Keys.HEALTH, 20.0, 0.0, Keys.MAX_HEALTH)
            .addListener((oldElement, newElement) -> {
                if (newElement <= 0) {
                    handleDeath();
                }
            });
    //noinspection unchecked
    c.register((Key<MutableBoundedValue<Double>>) (Key) Keys.ABSORPTION, 0.0, 0.0, 1024.0);
    c.register(Keys.POTION_EFFECTS, new ArrayList<>());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LanternLiving.java


示例2: nodeSize

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public MutableBoundedValue<Integer> nodeSize() {
    return SpongeValueFactory.boundedBuilder(ThaumicKeys.AURA_NODE_SIZE)
            .defaultValue(1)
            .minimum(0)
            .maximum(Integer.MAX_VALUE)
            .actualValue(this.nodeSize)
            .build();
}
 
开发者ID:gabizou,项目名称:ThaumicSponge,代码行数:10,代码来源:ThaumicAuraNodeData.java


示例3: nodeSize

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public MutableBoundedValue<Integer> nodeSize() {
    return SpongeValueFactory.boundedBuilder(ThaumicKeys.AURA_NODE_SIZE)
            .defaultValue(1)
            .minimum(0)
            .maximum(Integer.MAX_VALUE)
            .actualValue(this.getNodeSize())
            .build();
}
 
开发者ID:gabizou,项目名称:ThaumicSponge,代码行数:10,代码来源:MixinEntityAura.java


示例4: pulsePotions

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
private void pulsePotions(int deltaTicks) {
    // TODO: Move potion effects to a component? + The key registration
    final List<PotionEffect> potionEffects = get(Keys.POTION_EFFECTS).get();
    if (!potionEffects.isEmpty()) {
        final PotionEffect.Builder builder = PotionEffect.builder();
        final ImmutableList.Builder<PotionEffect> newPotionEffects = ImmutableList.builder();
        for (PotionEffect potionEffect : potionEffects) {
            final boolean instant = potionEffect.getType().isInstant();
            final int duration = instant ? 1 : potionEffect.getDuration() - deltaTicks;
            if (duration > 0) {
                final PotionEffect newPotionEffect = builder.from(potionEffect).duration(duration).build();
                ((LanternPotionEffectType) newPotionEffect.getType()).getEffectConsumer().accept(this, newPotionEffect);
                if (!instant) {
                    newPotionEffects.add(newPotionEffect);
                }
            }
            if (potionEffect.getType() == PotionEffectTypes.GLOWING) {
                offer(Keys.GLOWING, duration > 0);
            } else if (potionEffect.getType() == PotionEffectTypes.INVISIBILITY) {
                offer(Keys.INVISIBLE, duration > 0);
            } else if (potionEffect.getType() == PotionEffectTypes.HUNGER && supports(Keys.EXHAUSTION)) {
                final MutableBoundedValue<Double> exhaustion = getValue(Keys.EXHAUSTION).get();
                final double value = exhaustion.get() + (double) deltaTicks * 0.005 * (potionEffect.getAmplifier() + 1.0);
                offer(Keys.EXHAUSTION, Math.min(value, exhaustion.getMaxValue()));
            } else if (potionEffect.getType() == PotionEffectTypes.SATURATION && supports(FoodData.class)) {
                final int amount = potionEffect.getAmplifier() + 1;
                final int food = Math.min(get(Keys.FOOD_LEVEL).get() + amount, get(LanternKeys.MAX_FOOD_LEVEL).get());
                offer(Keys.FOOD_LEVEL, food);
                offer(Keys.SATURATION, Math.min(get(Keys.SATURATION).get() + (amount * 2), food));
            }
        }
        offer(Keys.POTION_EFFECTS, newPotionEffects.build());
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:35,代码来源:LanternLiving.java


示例5: heal

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
/**
 * Heals the entity for the specified amount.
 *
 * <p>Will not heal them if they are dead and will not set
 * them above their maximum health.</p>
 *
 * @param amount The amount to heal for
 * @param source The healing source
 */
public boolean heal(double amount, HealingSource source) {
    if (isDead()) {
        return false;
    }
    final MutableBoundedValue<Double> health = getValue(Keys.HEALTH).orElse(null);
    if (health == null || health.get() >= health.getMaxValue()) {
        return false;
    }
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.pushCause(source);
        frame.addContext(LanternEventContextKeys.HEALING_TYPE, source.getHealingType());

        final HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(
                frame.getCurrentCause(), new ArrayList<>(), this, amount);
        Sponge.getEventManager().post(event);
        if (event.isCancelled()) {
            return false;
        }
        amount = event.getFinalHealAmount();
        if (amount > 0) {
            offer(Keys.HEALTH, Math.min(health.get() + amount, health.getMaxValue()));
        }
    }
    return true;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:36,代码来源:LanternEntity.java


示例6: set

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public MutableBoundedValue<E> set(E value) {
    if (this.comparator.compare(value, this.minimum) >= 0 && this.comparator.compare(value, this.maximum) <= 0) {
        this.actualValue = checkNotNull(value);
    }
    return this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:LanternBoundedValue.java


示例7: showReport

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public void showReport(List<Action> actions, Receiver receiver)
{
    Action action = actions.get(0);
    Optional<BlockSnapshot> orig = action.getCached(BLOCKS_ORIG, Recall::origSnapshot);
    Optional<BlockSnapshot> repl = action.getCached(BLOCKS_REPL, Recall::replSnapshot);

    Text cause = Recall.cause(action);
    if (!repl.isPresent() || !orig.isPresent())
    {
        throw new IllegalStateException();
    }
    Optional<MutableBoundedValue<Integer>> growth = repl.get().getValue(Keys.GROWTH_STAGE);
    if (growth.isPresent())
    {
        if (growth.get().get().equals(growth.get().getMaxValue()))
        {
            receiver.sendReport(this, actions, actions.size(),
                                "{txt} let {txt} grow to maturity",
                                "{txt} let {txt} grow to maturity x{}",
                                cause, name(orig.get(), receiver), actions.size());
            return;
        }
        receiver.sendReport(this, actions, actions.size(),
                            "{txt} let {txt} grow",
                            "{txt} let {txt} grow x{}",
                            cause, name(orig.get(), receiver), actions.size());
        return;
    }
    // TODO other modifyables
    receiver.sendReport(this, actions, actions.size(),
                        "{txt} modified {txt}",
                        "{txt} modified {txt} x{}",
                        cause, name(orig.get(), receiver), actions.size());
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:36,代码来源:ModifyBlockReport.java


示例8: setFuseTicks

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public void setFuseTicks(int fuseTicks) {
    MutableBoundedValue<Integer> value = getHandle().getFuseData().getFuseDuration();
    Preconditions.checkArgument(fuseTicks >= value.getMinValue() && fuseTicks <= value.getMaxValue(),
            "Value for fuse duration is outside acceptable range (" + value.getMinValue() + ", "
                    + value.getMaxValue() + ")");
    getHandle().offer(value.set(fuseTicks));
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:9,代码来源:PoreTNTPrimed.java


示例9: nodeSize

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
default MutableBoundedValue<Integer> nodeSize() {
    return getValue(ThaumicKeys.AURA_NODE_SIZE).get();
}
 
开发者ID:gabizou,项目名称:ThaumicSpongeAPI,代码行数:4,代码来源:AuraNode.java


示例10: pulseFood

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
private void pulseFood() {
    if (!supports(FoodData.class) || get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
        return;
    }
    final Difficulty difficulty = getWorld().getDifficulty();

    MutableBoundedValue<Double> exhaustion = getValue(Keys.EXHAUSTION).get();
    MutableBoundedValue<Double> saturation = getValue(Keys.SATURATION).get();
    MutableBoundedValue<Integer> foodLevel = getValue(Keys.FOOD_LEVEL).get();

    if (exhaustion.get() > 4.0) {
        if (saturation.get() > saturation.getMinValue()) {
            offer(Keys.SATURATION, Math.max(saturation.get() - 1.0, saturation.getMinValue()));
            // Get the updated saturation
            saturation = getValue(Keys.SATURATION).get();
        } else if (!difficulty.equals(Difficulties.PEACEFUL)) {
            offer(Keys.FOOD_LEVEL, Math.max(foodLevel.get() - 1, foodLevel.getMinValue()));
            // Get the updated food level
            foodLevel = getValue(Keys.FOOD_LEVEL).get();
        }
        offer(Keys.EXHAUSTION, Math.max(exhaustion.get() - 4.0, exhaustion.getMinValue()));
        exhaustion = getValue(Keys.EXHAUSTION).get();
    }

    final boolean naturalRegeneration = getWorld().getOrCreateRule(RuleTypes.NATURAL_REGENERATION).getValue();
    final long currentTickTime = LanternGame.currentTimeTicks();

    if (naturalRegeneration && saturation.get() > saturation.getMinValue() && foodLevel.get() >= foodLevel.getMaxValue()) {
        if ((currentTickTime - this.lastFoodTickTime) >= 10) {
            final double amount = Math.min(saturation.get(), 6.0);
            heal(amount / 6.0, HealingSources.FOOD);
            offer(Keys.EXHAUSTION, Math.min(exhaustion.get() + amount, exhaustion.getMaxValue()));
            this.lastFoodTickTime = currentTickTime;
        }
    } else if (naturalRegeneration && foodLevel.get() >= 18) {
        if ((currentTickTime - this.lastFoodTickTime) >= 80) {
            heal(1.0, HealingSources.FOOD);
            offer(Keys.EXHAUSTION, Math.min(6.0 + exhaustion.get(), exhaustion.getMaxValue()));
            this.lastFoodTickTime = currentTickTime;
        }
    } else if (foodLevel.get() <= foodLevel.getMinValue()) {
        if ((currentTickTime - this.lastFoodTickTime) >= 80) {
            final double health = get(Keys.HEALTH).orElse(20.0);
            if ((health > 10.0 && difficulty.equals(Difficulties.EASY))
                    || (health > 1.0 && difficulty.equals(Difficulties.NORMAL))
                    || difficulty.equals(Difficulties.HARD)) {
                damage(1.0, DamageSources.STARVATION);
            }
            this.lastFoodTickTime = currentTickTime;
        }
    } else {
        this.lastFoodTickTime = currentTickTime;
    }

    // Peaceful restoration
    if (naturalRegeneration && difficulty.equals(Difficulties.PEACEFUL)) {
        if (currentTickTime - this.lastPeacefulHealthTickTime >= 20) {
            heal(1.0, HealingSources.MAGIC);
            this.lastPeacefulHealthTickTime = currentTickTime;
        }

        final int oldFoodLevel = get(Keys.FOOD_LEVEL).orElse(0);
        if (currentTickTime - this.lastPeacefulFoodTickTime >= 10
                && oldFoodLevel < get(LanternKeys.MAX_FOOD_LEVEL).orElse(20)) {
            offer(Keys.FOOD_LEVEL, oldFoodLevel + 1);
            this.lastPeacefulFoodTickTime = currentTickTime;
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:70,代码来源:LanternLiving.java


示例11: asMutable

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public MutableBoundedValue<E> asMutable() {
    return new LanternBoundedValue<>(getKey(), getDefault(), getComparator(), getMinValue(), getMaxValue(), get());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:ImmutableLanternBoundedValue.java


示例12: transform

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public MutableBoundedValue<E> transform(Function<E, E> function) {
    return set(checkNotNull(checkNotNull(function).apply(get())));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternBoundedValue.java


示例13: createBoundedValueBuilder

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
@Override
public <E> BoundedValueBuilder<E> createBoundedValueBuilder(Key<MutableBoundedValue<E>> key) {
    return new LanternBoundedValueBuilder<>(checkNotNull(key, "key"));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternValueFactory.java


示例14: makeMutableBoundedValueKey

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
public static <E> Key<MutableBoundedValue<E>> makeMutableBoundedValueKey(TypeToken<E> elementToken,
        DataQuery query, String id, String name) {
    final TypeToken<MutableBoundedValue<E>> valueToken = new TypeToken<MutableBoundedValue<E>>() {}
            .where(new TypeParameter<E>() {}, elementToken);
    return new LanternKeyBuilder<>().type(valueToken).query(query).id(id).name(name).build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternKeyFactory.java


示例15: getTimeLeftAlive

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
/**
 * Gets the time in milliseconds this summon has remaining to live in the world.
 *
 * @return The time left remaining in the world
 */
public MutableBoundedValue<Long> getTimeLeftAlive() {
    return null;
}
 
开发者ID:AfterKraft,项目名称:KraftRPG-API,代码行数:9,代码来源:SummonData.java


示例16: nodeSize

import org.spongepowered.api.data.value.mutable.MutableBoundedValue; //导入依赖的package包/类
MutableBoundedValue<Integer> nodeSize(); 
开发者ID:gabizou,项目名称:ThaumicSpongeAPI,代码行数:2,代码来源:AuraNodeData.java



注:本文中的org.spongepowered.api.data.value.mutable.MutableBoundedValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HasMouseMoveHandlers类代码示例发布时间:2022-05-23
下一篇:
Java DependencyBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap