Search in sources :

Example 1 with ValueCollection

use of org.lanternpowered.server.data.ValueCollection in project LanternServer by LanternPowered.

the class LanternEntity method registerKeys.

public void registerKeys() {
    final ValueCollection c = getValueCollection();
    c.register(Keys.DISPLAY_NAME, Text.EMPTY);
    c.register(Keys.CUSTOM_NAME_VISIBLE, true);
    c.registerNonRemovable(Keys.VELOCITY, Vector3d.ZERO);
    c.registerNonRemovable(Keys.FIRE_TICKS, 0);
    c.registerNonRemovable(Keys.FALL_DISTANCE, 0f);
    c.registerNonRemovable(Keys.GLOWING, false);
    c.registerNonRemovable(Keys.INVISIBLE, false);
    c.registerNonRemovable(Keys.INVULNERABLE, false);
    c.registerNonRemovable(LanternKeys.PORTAL_COOLDOWN_TICKS, 0);
}
Also used : ValueCollection(org.lanternpowered.server.data.ValueCollection)

Example 2 with ValueCollection

use of org.lanternpowered.server.data.ValueCollection in project LanternServer by LanternPowered.

the class AbstractUser method registerKeys.

@Override
public void registerKeys() {
    super.registerKeys();
    final ValueCollection c = getValueCollection();
    c.register(LanternKeys.ACCESSORIES, new ArrayList<>());
    c.register(LanternKeys.MAX_EXHAUSTION, 40.0, 0.0, Double.MAX_VALUE);
    c.register(Keys.EXHAUSTION, DEFAULT_EXHAUSTION, 0.0, LanternKeys.MAX_EXHAUSTION);
    c.register(LanternKeys.MAX_FOOD_LEVEL, 20, 0, Integer.MAX_VALUE);
    c.register(Keys.FOOD_LEVEL, 20, 0, LanternKeys.MAX_FOOD_LEVEL);
    c.registerWithSuppliedMax(Keys.SATURATION, DEFAULT_SATURATION, 0.0, container -> container.get(Keys.FOOD_LEVEL).orElse(20).doubleValue());
    c.register(Keys.LAST_DATE_PLAYED, null);
    c.register(Keys.FIRST_DATE_PLAYED, null);
    c.registerNonRemovable(Keys.WALKING_SPEED, 0.1);
    c.registerNonRemovable(LanternKeys.FIELD_OF_VIEW_MODIFIER, 1.0);
    c.registerNonRemovable(Keys.IS_FLYING, false);
    c.registerNonRemovable(Keys.IS_SNEAKING, false);
    c.registerNonRemovable(Keys.IS_SPRINTING, false);
    c.registerNonRemovable(Keys.FLYING_SPEED, 0.1);
    c.registerNonRemovable(Keys.CAN_FLY, false);
    c.registerNonRemovable(Keys.RESPAWN_LOCATIONS, new HashMap<>());
    c.registerNonRemovable(Keys.GAME_MODE, GameModes.NOT_SET).addListener((oldElement, newElement) -> {
        ((LanternGameMode) newElement).getAbilityApplier().accept(this);
        // This MUST be updated, unless you want strange behavior on the client,
        // the client has 3 different concepts of 'isCreative', and each combination
        // gives a different outcome...
        // For example:
        // - Disable noClip and glow in spectator, but you can place blocks
        // - NoClip in creative, but you cannot change your hotbar, or drop items
        // Not really worth the trouble right now
        // TODO: Differentiate the 'global tab list entry' and the entry to update
        // TODO: these kind of settings to avoid possible 'strange' behavior.
        GlobalTabList.getInstance().get(getProfile()).ifPresent(e -> e.setGameMode(newElement));
    });
    c.registerNonRemovable(Keys.DOMINANT_HAND, HandPreferences.RIGHT);
    c.registerNonRemovable(LanternKeys.IS_ELYTRA_FLYING, false);
    c.registerNonRemovable(LanternKeys.ELYTRA_GLIDE_SPEED, 0.1);
    c.registerNonRemovable(LanternKeys.ELYTRA_SPEED_BOOST, false);
    c.registerNonRemovable(LanternKeys.SUPER_STEVE, false);
    c.registerNonRemovable(LanternKeys.CAN_WALL_JUMP, false);
    c.registerNonRemovable(LanternKeys.CAN_DUAL_WIELD, false);
    c.registerNonRemovable(LanternKeys.SCORE, 0);
    c.registerNonRemovable(LanternKeys.ACTIVE_HAND, Optional.empty());
    c.registerNonRemovable(LanternKeys.RECIPE_BOOK_FILTER_ACTIVE, false);
    c.registerNonRemovable(LanternKeys.RECIPE_BOOK_GUI_OPEN, false);
    c.registerProcessor(Keys.STATISTICS).add(builder -> builder.offerHandler((key, valueContainer, map) -> {
        this.statisticMap.setStatisticValues(map);
        return DataTransactionResult.successNoData();
    }).retrieveHandler((key, valueContainer) -> Optional.of(this.statisticMap.getStatisticValues())).failAlwaysRemoveHandler());
    c.registerNonRemovable(LanternKeys.OPEN_ADVANCEMENT_TREE, Optional.empty());
}
Also used : LanternKeys(org.lanternpowered.server.data.key.LanternKeys) Keys(org.spongepowered.api.data.key.Keys) HandPreferences(org.spongepowered.api.data.type.HandPreferences) Vector3d(com.flowpowered.math.vector.Vector3d) HashMap(java.util.HashMap) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ValueCollection(org.lanternpowered.server.data.ValueCollection) ArrayList(java.util.ArrayList) ChestInventory(org.lanternpowered.server.inventory.vanilla.block.ChestInventory) SubjectCollection(org.spongepowered.api.service.permission.SubjectCollection) Text(org.spongepowered.api.text.Text) NetworkSession(org.lanternpowered.server.network.NetworkSession) VanillaInventoryArchetypes(org.lanternpowered.server.inventory.vanilla.VanillaInventoryArchetypes) LanternWorld(org.lanternpowered.server.world.LanternWorld) UserStore(org.lanternpowered.server.data.io.store.entity.UserStore) GameProfile(org.spongepowered.api.profile.GameProfile) GlobalTabList(org.lanternpowered.server.entity.living.player.tab.GlobalTabList) SubjectReference(org.spongepowered.api.service.permission.SubjectReference) Nullable(javax.annotation.Nullable) SubjectData(org.spongepowered.api.service.permission.SubjectData) User(org.spongepowered.api.entity.living.player.User) Context(org.spongepowered.api.service.context.Context) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) UUID(java.util.UUID) StatisticMap(org.lanternpowered.server.statistic.StatisticMap) AbstractUserInventory(org.lanternpowered.server.inventory.vanilla.AbstractUserInventory) LanternWorldProperties(org.lanternpowered.server.world.LanternWorldProperties) Tristate(org.spongepowered.api.util.Tristate) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Optional(java.util.Optional) LanternHumanoid(org.lanternpowered.server.entity.LanternHumanoid) ValueCollection(org.lanternpowered.server.data.ValueCollection)

Example 3 with ValueCollection

use of org.lanternpowered.server.data.ValueCollection in project LanternServer by LanternPowered.

the class LanternPlayer method registerKeys.

@Override
public void registerKeys() {
    super.registerKeys();
    final ValueCollection c = getValueCollection();
    ((ElementKeyRegistration<?, Optional<AdvancementTree>>) c.get(LanternKeys.OPEN_ADVANCEMENT_TREE).get()).addListener((oldElement, newElement) -> {
        if (getWorld() != null) {
            this.session.send(new MessagePlayOutSelectAdvancementTree(newElement.map(AdvancementTree::getId).orElse(null)));
        }
    });
}
Also used : AdvancementTree(org.spongepowered.api.advancement.AdvancementTree) MessagePlayOutSelectAdvancementTree(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSelectAdvancementTree) MessagePlayOutSelectAdvancementTree(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSelectAdvancementTree) ValueCollection(org.lanternpowered.server.data.ValueCollection) ElementKeyRegistration(org.lanternpowered.server.data.element.ElementKeyRegistration)

Example 4 with ValueCollection

use of org.lanternpowered.server.data.ValueCollection in project LanternServer by LanternPowered.

the class LanternItem method registerKeys.

@Override
public void registerKeys() {
    super.registerKeys();
    final ValueCollection c = getValueCollection();
    c.register(Keys.REPRESENTED_ITEM, null);
    c.register(Keys.PICKUP_DELAY, 10);
    c.register(Keys.DESPAWN_DELAY, 6000);
    c.register(LanternKeys.GRAVITY_FACTOR, 0.002);
}
Also used : ValueCollection(org.lanternpowered.server.data.ValueCollection)

Example 5 with ValueCollection

use of org.lanternpowered.server.data.ValueCollection in project LanternServer by LanternPowered.

the class LanternLiving method registerKeys.

@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<>());
}
Also used : ValueCollection(org.lanternpowered.server.data.ValueCollection) MutableBoundedValue(org.spongepowered.api.data.value.mutable.MutableBoundedValue) Key(org.spongepowered.api.data.key.Key)

Aggregations

ValueCollection (org.lanternpowered.server.data.ValueCollection)8 Optional (java.util.Optional)3 Lantern (org.lanternpowered.server.game.Lantern)3 VanillaInventoryArchetypes (org.lanternpowered.server.inventory.vanilla.VanillaInventoryArchetypes)3 Keys (org.spongepowered.api.data.key.Keys)3 LanternKeys (org.lanternpowered.server.data.key.LanternKeys)2 ChestInventory (org.lanternpowered.server.inventory.vanilla.block.ChestInventory)2 BlockState (org.spongepowered.api.block.BlockState)2 BlockTypes (org.spongepowered.api.block.BlockTypes)2 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 Random (java.util.Random)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Nullable (javax.annotation.Nullable)1