Search in sources :

Example 36 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class EntityToggleGlideListener method entityToggleGlide.

@EventHandler(priority = EventPriority.MONITOR)
public void entityToggleGlide(EntityToggleGlideEvent event) {
    if (!(event.getEntity() instanceof Player))
        return;
    Player player = (Player) event.getEntity();
    if (!isOnPipe(player))
        return;
    // Cancelling can only be done by updating the player's metadata
    if (event.isGliding() && event.isCancelled()) {
        PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_15.ENTITY_METADATA, null, getUserConnection(player));
        try {
            packet.write(Type.VAR_INT, player.getEntityId());
            byte bitmask = 0;
            // Collect other metadata for the mitmask
            if (player.getFireTicks() > 0) {
                bitmask |= 0x01;
            }
            if (player.isSneaking()) {
                bitmask |= 0x02;
            }
            // 0x04 is unused
            if (player.isSprinting()) {
                bitmask |= 0x08;
            }
            if (swimmingMethodExists && player.isSwimming()) {
                bitmask |= 0x10;
            }
            if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                bitmask |= 0x20;
            }
            if (player.isGlowing()) {
                bitmask |= 0x40;
            }
            // leave 0x80 as 0 to stop gliding
            packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, Types1_14.META_TYPES.byteType, bitmask)));
            packet.scheduleSend(Protocol1_15To1_14_4.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) EventHandler(org.bukkit.event.EventHandler)

Example 37 with Metadata

use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.

the class ElytraPatch method onServerConnected.

@EventHandler(priority = EventPriority.HIGH)
public void onServerConnected(ServerConnectedEvent event) {
    UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId());
    if (user == null)
        return;
    try {
        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
            EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
            int entityId = tracker.getProvidedEntityId();
            PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user);
            wrapper.write(Type.VAR_INT, entityId);
            wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));
            wrapper.scheduleSend(Protocol1_9To1_8.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)37 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)21 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)15 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)14 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)11 Item (com.viaversion.viaversion.api.minecraft.item.Item)10 Type (com.viaversion.viaversion.api.type.Type)8 StoredEntityData (com.viaversion.viaversion.api.data.entity.StoredEntityData)6 MetaType (com.viaversion.viaversion.api.minecraft.metadata.MetaType)6 EntityData (com.viaversion.viabackwards.api.entities.storage.EntityData)5 LegacyEntityRewriter (com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter)5 Particle (com.viaversion.viaversion.api.type.types.Particle)5 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)5 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)4 WrappedMetadata (com.viaversion.viabackwards.api.entities.storage.WrappedMetadata)4 Entity1_13Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types)4 DataItem (com.viaversion.viaversion.api.minecraft.item.DataItem)4 ArrayList (java.util.ArrayList)4 EntityPositionHandler (com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler)3 Block (com.viaversion.viabackwards.utils.Block)3