Search in sources :

Example 6 with MessagePlayOutEntityMetadata

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata in project LanternServer by LanternPowered.

the class PlayerEntityProtocol method sendHat.

private void sendHat(EntityProtocolUpdateContext context, TopHat hat) {
    final LanternItemStack paneItem;
    final LanternItemStack blockItem;
    final Optional<DyeColor> dyeColor = hat.getDyeColor();
    if (dyeColor.isPresent()) {
        paneItem = new LanternItemStack(BlockTypes.CARPET);
        paneItem.offer(Keys.DYE_COLOR, dyeColor.get());
        blockItem = new LanternItemStack(BlockTypes.WOOL);
        blockItem.offer(Keys.DYE_COLOR, dyeColor.get());
    } else if (hat == TopHats.GOLD) {
        paneItem = new LanternItemStack(BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.GOLD_BLOCK);
    } else if (hat == TopHats.IRON) {
        paneItem = new LanternItemStack(BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.IRON_BLOCK);
    } else if (hat == TopHats.WOOD) {
        paneItem = new LanternItemStack(BlockTypes.WOODEN_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.PLANKS);
    } else if (hat == TopHats.STONE) {
        paneItem = new LanternItemStack(BlockTypes.STONE_PRESSURE_PLATE);
        blockItem = new LanternItemStack(BlockTypes.STONE);
    } else if (hat == TopHats.SNOW) {
        paneItem = new LanternItemStack(BlockTypes.SNOW_LAYER);
        blockItem = new LanternItemStack(BlockTypes.SNOW);
    } else {
        throw new IllegalStateException();
    }
    byte flags = 0x20;
    if (getEntity().get(Keys.GLOWING).get()) {
        flags |= 0x40;
    }
    final ParameterList parameterList1 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
    parameterList1.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10));
    parameterList1.add(EntityParameters.Base.FLAGS, flags);
    final int id1 = this.passengerStack[10];
    context.sendToAll(() -> new MessagePlayOutSpawnObject(id1, UUID.randomUUID(), 78, 0, getEntity().getPosition(), 0, 0, Vector3d.ZERO));
    context.sendToAll(() -> new MessagePlayOutEntityMetadata(id1, parameterList1));
    context.sendToAll(() -> new MessagePlayOutEntityEquipment(id1, 5, paneItem));
    final ParameterList parameterList2 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
    parameterList2.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10 | 0x01));
    parameterList2.add(EntityParameters.Base.FLAGS, flags);
    final int id2 = this.passengerStack[11];
    context.sendToAll(() -> new MessagePlayOutSpawnObject(id2, UUID.randomUUID(), 78, 0, getEntity().getPosition(), 0, 0, Vector3d.ZERO));
    context.sendToAll(() -> new MessagePlayOutEntityMetadata(id2, parameterList2));
    context.sendToAll(() -> new MessagePlayOutEntityEquipment(id2, 5, blockItem));
    sendPassengers(context, 8, 10);
    sendPassengers(context, 9, 11);
/*
        final LanternItemStack boneItem = new LanternItemStack(ItemTypes.BONE);

        float angleA = 250f;
        float angleB = 250f;
        for (int i = 12; i <= 14; i++) {
            final ParameterList parameterList3 = new ByteBufParameterList(ByteBufferAllocator.unpooled());
            parameterList3.add(EntityParameters.ArmorStand.FLAGS, (byte) (0x08 | 0x10 | 0x01 | 0x04));
            parameterList3.add(EntityParameters.ArmorStand.LEFT_ARM_ROTATION, new Vector3f(50f, 360f - angleA, angleB));
            parameterList3.add(EntityParameters.ArmorStand.RIGHT_ARM_ROTATION, new Vector3f(50f, angleA, 360f - angleB));
            parameterList3.add(EntityParameters.Base.FLAGS, flags);
            final int id3 = this.passengerStack[i];

            context.sendToAll(() -> new MessagePlayOutSpawnObject(id3, UUID.randomUUID(), 78, 0,
                    getEntity().getPosition(), 0, 0, Vector3d.ZERO));
            context.sendToAll(() -> new MessagePlayOutEntityMetadata(id3, parameterList3));
            context.sendToAll(() -> new MessagePlayOutEntityEquipment(id3, 0, boneItem));
            context.sendToAll(() -> new MessagePlayOutEntityEquipment(id3, 1, boneItem));

            angleA -= 15f;
            angleB -= 15f;
        }

        sendPassengers(context, 7, 9, 12, 13, 14);
        */
}
Also used : ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) 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) MessagePlayOutEntityEquipment(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityEquipment) DyeColor(org.spongepowered.api.data.type.DyeColor) MessagePlayOutSpawnObject(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnObject) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Aggregations

MessagePlayOutEntityMetadata (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata)6 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)4 ByteBufParameterList (org.lanternpowered.server.network.entity.parameter.ByteBufParameterList)4 ParameterList (org.lanternpowered.server.network.entity.parameter.ParameterList)4 Vector3d (com.flowpowered.math.vector.Vector3d)3 MessagePlayOutSpawnObject (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnObject)3 LanternGameMode (org.lanternpowered.server.entity.living.player.gamemode.LanternGameMode)2 TopHat (org.lanternpowered.server.extra.accessory.TopHat)2 MessagePlayOutEntityEquipment (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityEquipment)2 MessagePlayOutEntityHeadLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)2 MessagePlayOutEntityLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityLook)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 Vector3f (com.flowpowered.math.vector.Vector3f)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 LanternNotePitch (org.lanternpowered.server.data.type.LanternNotePitch)1 LanternParticleEffect (org.lanternpowered.server.effect.particle.LanternParticleEffect)1 LanternParticleType (org.lanternpowered.server.effect.particle.LanternParticleType)1