本文整理汇总了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;
}
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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)));
}
示例7: with
import org.spongepowered.api.util.weighted.WeightedTable; //导入依赖的package包/类
@Override
public ImmutableWeightedCollectionValue<E> with(WeightedTable<E> value) {
return new ImmutableLanternWeightedCollectionValue<>(getKey(), value);
}
示例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);
}
示例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);
}
示例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;
}
示例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)));
}
示例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)));
}
示例13: getAll
import org.spongepowered.api.util.weighted.WeightedTable; //导入依赖的package包/类
@Override
public WeightedTable<E> getAll() {
return get().stream().collect(Collectors.toCollection(WeightedTable<E>::new));
}
示例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!");
}
}