Search in sources :

Example 1 with TopHat

use of org.lanternpowered.server.extra.accessory.TopHat in project LanternServer by LanternPowered.

the class PlayerEntityProtocol method spawn.

@Override
protected void spawn(EntityProtocolUpdateContext context) {
    super.spawn(context);
    context.sendToSelf(() -> new MessagePlayOutEntityMetadata(getRootEntityId(), fillParameters(true)));
    final GameMode gameMode = getEntity().get(Keys.GAME_MODE).get();
    context.sendToSelf(() -> new MessagePlayOutSetGameMode((LanternGameMode) gameMode));
    context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(this.entity.get(Keys.IS_FLYING).orElse(false), canFly(), false, gameMode == GameModes.CREATIVE, getFlySpeed(), getFovModifier()));
    final TopHat topHat = getTopHat();
    if (topHat != null && !getEntity().get(Keys.INVISIBLE).get()) {
        sendPassengerStack(context);
        sendHat(context, topHat);
    }
}
Also used : MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) TopHat(org.lanternpowered.server.extra.accessory.TopHat) MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) MessagePlayOutPlayerAbilities(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerAbilities)

Example 2 with TopHat

use of org.lanternpowered.server.extra.accessory.TopHat in project LanternServer by LanternPowered.

the class AccessoryRegistryModule method getCatalogMappings.

@Override
public List<CatalogMappingData> getCatalogMappings() {
    final ImmutableList.Builder<CatalogMappingData> mappingData = ImmutableList.builder();
    mappingData.addAll(super.getCatalogMappings());
    final ImmutableMap.Builder<String, Accessory> topHatMappings = ImmutableMap.builder();
    getAll().stream().filter(accessory -> accessory instanceof TopHat).forEach(accessory -> topHatMappings.put(accessory.getName().replace("_top_hat", ""), accessory));
    mappingData.add(new CatalogMappingData(TopHats.class, topHatMappings.build()));
    return mappingData.build();
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PluginCatalogRegistryModule(org.lanternpowered.server.game.registry.PluginCatalogRegistryModule) DyeColors(org.spongepowered.api.data.type.DyeColors) ImmutableMap(com.google.common.collect.ImmutableMap) TopHats(org.lanternpowered.server.extra.accessory.TopHats) RegistrationDependency(org.spongepowered.api.registry.util.RegistrationDependency) CatalogMappingData(org.lanternpowered.server.game.registry.CatalogMappingData) TopHat(org.lanternpowered.server.extra.accessory.TopHat) DyeColorRegistryModule(org.lanternpowered.server.game.registry.type.data.DyeColorRegistryModule) LanternTopHat(org.lanternpowered.server.extra.accessory.LanternTopHat) Accessory(org.lanternpowered.server.extra.accessory.Accessory) TopHat(org.lanternpowered.server.extra.accessory.TopHat) LanternTopHat(org.lanternpowered.server.extra.accessory.LanternTopHat) Accessory(org.lanternpowered.server.extra.accessory.Accessory) ImmutableList(com.google.common.collect.ImmutableList) TopHats(org.lanternpowered.server.extra.accessory.TopHats) CatalogMappingData(org.lanternpowered.server.game.registry.CatalogMappingData) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with TopHat

use of org.lanternpowered.server.extra.accessory.TopHat in project LanternServer by LanternPowered.

the class PlayerEntityProtocol method update.

@Override
protected void update(EntityProtocolUpdateContext context) {
    final GameMode gameMode = this.entity.get(Keys.GAME_MODE).get();
    final boolean canFly = canFly();
    final float flySpeed = getFlySpeed();
    final float fieldOfView = getFovModifier();
    if (gameMode != this.lastGameMode) {
        context.sendToSelf(() -> new MessagePlayOutSetGameMode((LanternGameMode) gameMode));
        context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(this.entity.get(Keys.IS_FLYING).orElse(false), canFly, false, gameMode == GameModes.CREATIVE, flySpeed, fieldOfView));
        this.lastGameMode = gameMode;
        this.lastCanFly = canFly;
        this.lastFlySpeed = flySpeed;
        this.lastFieldOfView = fieldOfView;
    } else if (canFly != this.lastCanFly || flySpeed != this.lastFlySpeed || fieldOfView != this.lastFieldOfView) {
        context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(this.entity.get(Keys.IS_FLYING).orElse(false), canFly, false, gameMode == GameModes.CREATIVE, flySpeed, fieldOfView));
        this.lastCanFly = canFly;
        this.lastFlySpeed = flySpeed;
        this.lastFieldOfView = fieldOfView;
    }
    final float health = this.entity.get(Keys.HEALTH).get().floatValue();
    final int foodLevel = this.entity.get(Keys.FOOD_LEVEL).get();
    final float saturation = this.entity.get(Keys.SATURATION).get().floatValue();
    if (health != this.lastHealth || foodLevel != this.lastFoodLevel || saturation == 0.0f != this.lastHungry) {
        context.sendToSelf(() -> new MessagePlayOutPlayerHealthUpdate(health, foodLevel, saturation));
        this.lastHealth = health;
        this.lastFoodLevel = foodLevel;
        this.lastHungry = saturation == 0.0f;
    }
    super.update(context);
    final TopHat topHat = getTopHat();
    if (topHat != this.lastTopHat) {
        if (this.lastTopHat == null) {
            sendPassengerStack(context);
            sendHat(context, topHat);
        } else if (topHat == null) {
            removePassengerStack(context);
        } else {
            sendHat(context, topHat);
        }
        this.lastTopHat = topHat;
    }
    if (this.lastYaw0 != this.lastYaw || this.lastPitch0 != this.lastPitch || this.lastFlags0 != this.lastFlags) {
        for (final int id : this.passengerStack) {
            context.sendToSelf(() -> new MessagePlayOutEntityLook(id, this.lastYaw, this.lastPitch, this.entity.isOnGround()));
        }
        if (this.lastTopHat != null) {
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[10], this.lastYaw));
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[11], this.lastYaw));
            context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[12], this.lastYaw));
            // context.sendToSelf(() -> new MessagePlayOutEntityHeadLook(this.passengerStack[14], this.lastYaw));
            if (this.lastFlags0 != this.lastFlags) {
                final boolean glow = (this.lastFlags & 0x40) != 0;
                final ParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
                parameterList.add(EntityParameters.Base.FLAGS, (byte) (0x20 | (glow ? 0x40 : 0x00)));
                context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.passengerStack[10], parameterList));
                context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.passengerStack[11], parameterList));
            }
        }
        this.lastYaw0 = this.lastYaw;
        this.lastPitch0 = this.lastPitch;
        this.lastFlags0 = this.lastFlags;
    }
    // Some 1.11.2 magic, ultra secret stuff...
    final boolean elytraFlying = this.entity.get(LanternKeys.IS_ELYTRA_FLYING).orElse(false);
    final boolean elytraSpeedBoost = this.entity.get(LanternKeys.ELYTRA_SPEED_BOOST).orElse(false);
    if (this.lastElytraFlying != elytraFlying || this.lastElytraSpeedBoost != elytraSpeedBoost) {
        if (this.lastElytraFlying && this.lastElytraSpeedBoost) {
            context.sendToAll(() -> new MessagePlayOutDestroyEntities(this.elytraRocketId));
        } else if (elytraFlying && elytraSpeedBoost) {
            // Create the fireworks data item
            final LanternItemStack itemStack = new LanternItemStack(ItemTypes.FIREWORKS);
            // Write the item to a parameter list
            final ByteBufParameterList parameterList = new ByteBufParameterList(ByteBufferAllocator.unpooled());
            parameterList.add(EntityParameters.Fireworks.ITEM, itemStack);
            parameterList.add(EntityParameters.Fireworks.ELYTRA_BOOST_PLAYER, getRootEntityId());
            context.sendToAll(() -> new MessagePlayOutSpawnObject(this.elytraRocketId, UUID.randomUUID(), 76, 0, this.entity.getPosition(), 0, 0, Vector3d.ZERO));
            context.sendToAll(() -> new MessagePlayOutEntityMetadata(this.elytraRocketId, parameterList));
        }
        this.lastElytraSpeedBoost = elytraSpeedBoost;
        this.lastElytraFlying = elytraFlying;
    }
}
Also used : TopHat(org.lanternpowered.server.extra.accessory.TopHat) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) MessagePlayOutSpawnObject(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnObject) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) LanternGameMode(org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) MessagePlayOutPlayerHealthUpdate(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerHealthUpdate) MessagePlayOutEntityLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityLook) MessagePlayOutSetGameMode(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode) MessagePlayOutDestroyEntities(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutDestroyEntities) ParameterList(org.lanternpowered.server.network.entity.parameter.ParameterList) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) MessagePlayOutPlayerAbilities(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerAbilities) MessagePlayOutEntityHeadLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)

Aggregations

TopHat (org.lanternpowered.server.extra.accessory.TopHat)3 LanternGameMode (org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode)2 MessagePlayOutEntityMetadata (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata)2 MessagePlayOutPlayerAbilities (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerAbilities)2 MessagePlayOutSetGameMode (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetGameMode)2 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 List (java.util.List)1 Accessory (org.lanternpowered.server.extra.accessory.Accessory)1 LanternTopHat (org.lanternpowered.server.extra.accessory.LanternTopHat)1 TopHats (org.lanternpowered.server.extra.accessory.TopHats)1 CatalogMappingData (org.lanternpowered.server.game.registry.CatalogMappingData)1 PluginCatalogRegistryModule (org.lanternpowered.server.game.registry.PluginCatalogRegistryModule)1 DyeColorRegistryModule (org.lanternpowered.server.game.registry.type.data.DyeColorRegistryModule)1 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)1 ByteBufParameterList (org.lanternpowered.server.network.entity.parameter.ByteBufParameterList)1 ParameterList (org.lanternpowered.server.network.entity.parameter.ParameterList)1 MessagePlayOutDestroyEntities (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutDestroyEntities)1 MessagePlayOutEntityHeadLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)1