當前位置: 首頁>>代碼示例>>Java>>正文


Java WeightedTable類代碼示例

本文整理匯總了Java中org.spongepowered.api.util.weighted.WeightedTable的典型用法代碼示例。如果您正苦於以下問題:Java WeightedTable類的具體用法?Java WeightedTable怎麽用?Java WeightedTable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WeightedTable類屬於org.spongepowered.api.util.weighted包,在下文中一共展示了WeightedTable類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onBlockPlace

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Listener(order = POST)
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player)
{
    EntityArchetype hidden = EntityArchetype.builder().type(SNOWBALL).set(Keys.INVISIBLE, true).build();
    Optional<ItemStackSnapshot> inHand = event.getContext().get(EventContextKeys.USED_ITEM);
    if (inHand.isPresent() &&
        places(event, MOB_SPAWNER) &&
        hasEnchantment(inHand.get(), LURE))
    {
        for (Transaction<BlockSnapshot> trans : event.getTransactions())
        {
            if (trans.getFinal().getState().getType().equals(MOB_SPAWNER))
            {
                BlockSnapshot snap = trans.getFinal();
                snap.getLocation().get().offer(Keys.SPAWNER_ENTITIES, new WeightedTable<>());
                snap.getLocation().get().offer(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN, new WeightedSerializableObject<>(hidden, 1));
                i18n.send(player, POSITIVE, "Inactive Monster Spawner placed!");
                return;
            }
        }
    }
}
 
開發者ID:CubeEngine,項目名稱:modules-extra,代碼行數:23,代碼來源:Spawner.java

示例2: nextWeather

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
/**
 * Gets the next possible {@link LanternWeather}, ignoring
 * the last weather type.
 *
 * @return The next weather type
 */
@SuppressWarnings("unchecked")
private LanternWeather nextWeather() {
    final List<LanternWeather> weathers = new ArrayList(this.world.game.getRegistry().getAllOf(Weather.class));
    final LanternWeather current = this.weatherData.getWeather();
    weathers.remove(current);
    if (weathers.isEmpty()) {
        return current;
    }

    final WeightedTable<LanternWeather> table = new WeightedTable<>();
    weathers.forEach(weather -> table.add(weather, weather.getWeight()));
    return table.get(this.random).get(0);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:20,代碼來源:LanternWeatherUniverse.java

示例3: withElement

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> withElement(TableEntry<E> elements) {
    WeightedTable<E> table = new WeightedTable<>();
    table.addAll(getActualValue());
    table.add(elements);
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), table);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:8,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例4: without

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> without(TableEntry<E> element) {
    final WeightedTable<E> newTable = getActualValue().stream()
            .filter(entry -> !entry.equals(element))
            .map(entry -> element)
            .collect(Collectors.toCollection(WeightedTable::new));
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), newTable);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:9,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例5: withoutAll

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> withoutAll(Iterable<TableEntry<E>> elements) {
    final WeightedTable<E> newTable = new WeightedTable<>();
    getActualValue().stream()
            .filter(entry -> !Iterables.contains(elements, entry))
            .forEach(newTable::add);
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), newTable);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:9,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例6: ImmutableLanternWeightedCollectionValue

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
public ImmutableLanternWeightedCollectionValue(Key<? extends BaseValue<WeightedTable<E>>> key, WeightedTable<E> actualValue) {
    super(key, new WeightedTable<>(), actualValue.stream().collect(Collectors.toCollection(WeightedTable<E>::new)));
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:4,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例7: with

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> with(WeightedTable<E> value) {
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), value);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:5,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例8: transform

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> transform(Function<WeightedTable<E>, WeightedTable<E>> function) {
    final WeightedTable<E> table = getAll();
    final WeightedTable<E> functionTable = function.apply(table);
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), functionTable);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:7,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例9: withAll

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public ImmutableWeightedCollectionValue<E> withAll(Iterable<TableEntry<E>> elements) {
    final WeightedTable<E> newTable = getAll();
    elements.forEach(newTable::add);
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), newTable);
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:7,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例10: getAll

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public WeightedTable<E> getAll() {
    final WeightedTable<E> newTable = new WeightedTable<>();
    newTable.addAll(getActualValue());
    return newTable;
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:7,代碼來源:ImmutableLanternWeightedCollectionValue.java

示例11: LanternWeightedCollectionValue

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
public LanternWeightedCollectionValue(Key<? extends BaseValue<WeightedTable<E>>> key, WeightedTable<E> actualValue) {
    super(key, new WeightedTable<>(), actualValue.stream().collect(Collectors.toCollection(WeightedTable<E>::new)));
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:4,代碼來源:LanternWeightedCollectionValue.java

示例12: filter

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public WeightedCollectionValue<E> filter(Predicate<? super TableEntry<E>> predicate) {
    return set(get().stream().filter(predicate).collect(Collectors.toCollection(WeightedTable<E>::new)));
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:5,代碼來源:LanternWeightedCollectionValue.java

示例13: getAll

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Override
public WeightedTable<E> getAll() {
    return get().stream().collect(Collectors.toCollection(WeightedTable<E>::new));
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:5,代碼來源:LanternWeightedCollectionValue.java

示例14: onInteract

import org.spongepowered.api.util.weighted.WeightedTable; //導入依賴的package包/類
@Listener(order = POST)
public void onInteract(InteractBlockEvent.Secondary event, @First Player player)
{
    // TODO maybe allow multiple spawner eggs /w same weight
    if (!event.getTargetBlock().getLocation().isPresent()) {
        return;
    }
    Location<World> block = event.getTargetBlock().getLocation().get();
    if (block.getBlockType().equals(MOB_SPAWNER)
     && player.getItemInHand(MAIN_HAND).map(i -> i.getType().equals(ItemTypes.SPAWN_EGG)).orElse(false))
    {
        event.setCancelled(true);

        if (block.get(Keys.SPAWNER_ENTITIES).map(RandomObjectTable::isEmpty).orElse(false))
        {
            ItemStack itemInHand = player.getItemInHand(MAIN_HAND).get();
            EntityType type = itemInHand.get(Keys.SPAWNABLE_ENTITY_TYPE).get();

            Permission perm = this.perms.get(type);
            if (perm == null && !player.hasPermission(eggPerms.getId()))
            {
                i18n.send(ACTION_BAR, player, NEGATIVE, "Invalid SpawnEgg!");
                return;
            }
            if (perm != null && !player.hasPermission(perm.getId()))
            {
                i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to change Monster Spawner to this EntityType!");
                return;
            }

            WeightedTable<EntityArchetype> spawns = new WeightedTable<>();
            EntityArchetype nextSpawn = EntityArchetype.builder().type(type).build();
            spawns.add(nextSpawn, 1);
            block.offer(Keys.SPAWNER_ENTITIES, spawns);
            block.offer(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN, new WeightedSerializableObject<>(nextSpawn, 1));

            if (!player.gameMode().get().equals(CREATIVE))
            {
                itemInHand.setQuantity(itemInHand.getQuantity() - 1);
                player.setItemInHand(MAIN_HAND, itemInHand); // TODO check if this sets no item if quantity 0
            }

            i18n.send(ACTION_BAR, player, POSITIVE, "Monster Spawner activated!");
            return;
        }
        i18n.send(ACTION_BAR, player, NEGATIVE, "You can only change inactive Monster Spawner!");
    }
}
 
開發者ID:CubeEngine,項目名稱:modules-extra,代碼行數:49,代碼來源:Spawner.java


注:本文中的org.spongepowered.api.util.weighted.WeightedTable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。