Search in sources :

Example 1 with Key

use of org.spongepowered.api.data.key.Key in project SpongeCommon by SpongePowered.

the class MobSpawnerDataProcessor method getValues.

@Override
protected Map<Key<?>, ?> getValues(IMixinMobSpawner spawner) {
    MobSpawnerBaseLogic logic = spawner.getLogic();
    Map<Key<?>, Object> values = Maps.newIdentityHashMap();
    values.put(Keys.SPAWNER_REMAINING_DELAY, (short) logic.spawnDelay);
    values.put(Keys.SPAWNER_MINIMUM_DELAY, (short) logic.minSpawnDelay);
    values.put(Keys.SPAWNER_MAXIMUM_DELAY, (short) logic.maxSpawnDelay);
    values.put(Keys.SPAWNER_SPAWN_COUNT, (short) logic.spawnCount);
    values.put(Keys.SPAWNER_MAXIMUM_NEARBY_ENTITIES, (short) logic.maxNearbyEntities);
    values.put(Keys.SPAWNER_REQUIRED_PLAYER_RANGE, (short) logic.activatingRangeFromPlayer);
    values.put(Keys.SPAWNER_SPAWN_RANGE, (short) logic.spawnRange);
    values.put(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN, SpawnerUtils.getNextEntity(logic));
    values.put(Keys.SPAWNER_ENTITIES, SpawnerUtils.getEntities(logic));
    return values;
}
Also used : MobSpawnerBaseLogic(net.minecraft.tileentity.MobSpawnerBaseLogic) Key(org.spongepowered.api.data.key.Key)

Example 2 with Key

use of org.spongepowered.api.data.key.Key in project SpongeCommon by SpongePowered.

the class AreaEffectCloudDataProcessor method getValues.

@Override
protected Map<Key<?>, ?> getValues(EntityAreaEffectCloud dataHolder) {
    final HashMap<Key<?>, Object> map = new HashMap<>();
    map.put(Keys.AREA_EFFECT_CLOUD_AGE, dataHolder.ticksExisted);
    map.put(Keys.AREA_EFFECT_CLOUD_COLOR, Color.ofRgb(dataHolder.getColor()));
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS, dataHolder.getRadius());
    final IMixinAreaEffectCloud mixinAreaEffect = (IMixinAreaEffectCloud) dataHolder;
    final List<net.minecraft.potion.PotionEffect> potionEffects = mixinAreaEffect.getPotionEffects();
    final List<PotionEffect> effects = new ArrayList<>(potionEffects.size());
    for (net.minecraft.potion.PotionEffect potionEffect : potionEffects) {
        effects.add((PotionEffect) potionEffect);
    }
    map.put(Keys.POTION_EFFECTS, effects);
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS_ON_USE, mixinAreaEffect.getRadiusOnUse());
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS_PER_TICK, mixinAreaEffect.getRadiusPerTick());
    map.put(Keys.AREA_EFFECT_CLOUD_DURATION, dataHolder.getDuration());
    map.put(Keys.AREA_EFFECT_CLOUD_DURATION_ON_USE, mixinAreaEffect.getDurationOnUse());
    map.put(Keys.AREA_EFFECT_CLOUD_REAPPLICATION_DELAY, mixinAreaEffect.getReapplicationDelay());
    map.put(Keys.AREA_EFFECT_CLOUD_WAIT_TIME, mixinAreaEffect.getWaitTime());
    map.put(Keys.AREA_EFFECT_CLOUD_PARTICLE_TYPE, ParticleTypes.MOB_SPELL);
    return map;
}
Also used : HashMap(java.util.HashMap) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ArrayList(java.util.ArrayList) IMixinAreaEffectCloud(org.spongepowered.common.mixin.core.entity.IMixinAreaEffectCloud) Key(org.spongepowered.api.data.key.Key)

Example 3 with Key

use of org.spongepowered.api.data.key.Key in project SpongeCommon by SpongePowered.

the class EntityCommandDataProcessor method getValues.

@Override
protected Map<Key<?>, ?> getValues(EntityMinecartCommandBlock entity) {
    CommandBlockBaseLogic logic = entity.getCommandBlockLogic();
    Map<Key<?>, Object> values = Maps.newHashMapWithExpectedSize(4);
    Optional<Text> lastCommandOutput = logic.getLastOutput() != null ? Optional.of(SpongeTexts.toText(logic.getLastOutput())) : Optional.empty();
    values.put(Keys.LAST_COMMAND_OUTPUT, lastCommandOutput);
    values.put(Keys.COMMAND, logic.commandStored);
    values.put(Keys.SUCCESS_COUNT, logic.successCount);
    values.put(Keys.TRACKS_OUTPUT, logic.shouldTrackOutput());
    return values;
}
Also used : CommandBlockBaseLogic(net.minecraft.tileentity.CommandBlockBaseLogic) Text(org.spongepowered.api.text.Text) Key(org.spongepowered.api.data.key.Key)

Example 4 with Key

use of org.spongepowered.api.data.key.Key in project SpongeCommon by SpongePowered.

the class MixinWorld_Data method getKeys.

@Override
public Set<Key<?>> getKeys(int x, int y, int z) {
    final ImmutableSet.Builder<Key<?>> builder = ImmutableSet.builder();
    final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
    builder.addAll(blockState.getKeys());
    final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
    if (tileEntity.isPresent()) {
        builder.addAll(tileEntity.get().getKeys());
    }
    return builder.build();
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) ImmutableSet(com.google.common.collect.ImmutableSet) Key(org.spongepowered.api.data.key.Key)

Example 5 with Key

use of org.spongepowered.api.data.key.Key in project SpongeCommon by SpongePowered.

the class MixinStateImplementation method cycleValue.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public BlockState cycleValue(Key<? extends BaseValue<? extends Cycleable<?>>> key) {
    if (supports(key)) {
        final Cycleable value = (Cycleable) get((Key) key).get();
        final Cycleable next = value.cycleNext();
        return with((Key<? extends BaseValue<Object>>) (Key<?>) key, next).get();
    }
    throw new IllegalArgumentException("Used an invalid cyclable key! Check with supports in the future!");
}
Also used : BaseValue(org.spongepowered.api.data.value.BaseValue) Cycleable(org.spongepowered.api.util.Cycleable) Key(org.spongepowered.api.data.key.Key)

Aggregations

Key (org.spongepowered.api.data.key.Key)28 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 BlockState (org.spongepowered.api.block.BlockState)7 BaseValue (org.spongepowered.api.data.value.BaseValue)7 List (java.util.List)6 Optional (java.util.Optional)6 Sponge (org.spongepowered.api.Sponge)5 Text (org.spongepowered.api.text.Text)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collection (java.util.Collection)4 BlockType (org.spongepowered.api.block.BlockType)4 ImmutableValue (org.spongepowered.api.data.value.immutable.ImmutableValue)4 World (org.spongepowered.api.world.World)4 Set (java.util.Set)3 DataTypeSerializer (org.lanternpowered.server.data.persistence.DataTypeSerializer)3 CommandContext (org.spongepowered.api.command.args.CommandContext)3 CommandElement (org.spongepowered.api.command.args.CommandElement)3 DataView (org.spongepowered.api.data.DataView)3