Search in sources :

Example 1 with BossBar

use of com.viaversion.viaversion.api.legacy.bossbar.BossBar in project ViaVersion by ViaVersion.

the class EntityTracker1_9 method removeEntity.

@Override
public void removeEntity(int entityId) {
    super.removeEntity(entityId);
    vehicleMap.remove(entityId);
    uuidMap.remove(entityId);
    validBlocking.remove(entityId);
    knownHolograms.remove(entityId);
    metadataBuffer.remove(entityId);
    BossBar bar = bossBarMap.remove(entityId);
    if (bar != null) {
        bar.hide();
        // Send to provider
        Via.getManager().getProviders().get(BossBarProvider.class).handleRemove(user(), bar.getId());
    }
}
Also used : BossBarProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider) BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar)

Example 2 with BossBar

use of com.viaversion.viaversion.api.legacy.bossbar.BossBar in project ViaVersion by ViaVersion.

the class EntityTracker1_9 method handleMetadata.

public void handleMetadata(int entityId, List<Metadata> metadataList) {
    com.viaversion.viaversion.api.minecraft.entities.EntityType type = entityType(entityId);
    if (type == null) {
        return;
    }
    for (Metadata metadata : new ArrayList<>(metadataList)) {
        // Fix: wither (crash fix)
        if (type == EntityType.WITHER) {
            if (metadata.id() == 10) {
                metadataList.remove(metadata);
            // metadataList.add(new Metadata(10, NewType.Byte.getTypeID(), Type.BYTE, 0));
            }
        }
        // Fix: enderdragon (crash fix)
        if (type == EntityType.ENDER_DRAGON) {
            if (metadata.id() == 11) {
                metadataList.remove(metadata);
            // metadataList.add(new Metadata(11, NewType.Byte.getTypeID(), Type.VAR_INT, 0));
            }
        }
        if (type == EntityType.SKELETON) {
            if ((getMetaByIndex(metadataList, 12)) == null) {
                metadataList.add(new Metadata(12, MetaType1_9.Boolean, true));
            }
        }
        // ECHOPET Patch
        if (type == EntityType.HORSE) {
            // Wrong metadata value from EchoPet, patch since it's discontinued. (https://github.com/DSH105/EchoPet/blob/06947a8b08ce40be9a518c2982af494b3b99d140/modules/API/src/main/java/com/dsh105/echopet/compat/api/entity/HorseArmour.java#L22)
            if (metadata.id() == 16 && (int) metadata.getValue() == Integer.MIN_VALUE)
                metadata.setValue(0);
        }
        if (type == EntityType.PLAYER) {
            if (metadata.id() == 0) {
                // Byte
                byte data = (byte) metadata.getValue();
                if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
                    if ((data & 0x10) == 0x10) {
                        if (validBlocking.contains(entityId)) {
                            Item shield = new DataItem(442, (byte) 1, (short) 0, null);
                            setSecondHand(entityId, shield);
                        } else {
                            setSecondHand(entityId, null);
                        }
                    } else {
                        setSecondHand(entityId, null);
                    }
                }
            }
            if (metadata.id() == 12 && Via.getConfig().isLeftHandedHandling()) {
                // Player model
                metadataList.add(new Metadata(// Main hand
                13, MetaType1_9.Byte, (byte) (((((byte) metadata.getValue()) & 0x80) != 0) ? 0 : 1)));
            }
        }
        if (type == EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
            if (metadata.id() == 0 && getMetaByIndex(metadataList, 10) != null) {
                // Only happens if the armorstand is small
                Metadata meta = getMetaByIndex(metadataList, 10);
                byte data = (byte) metadata.getValue();
                // Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
                Metadata displayName;
                Metadata displayNameVisible;
                if ((data & 0x20) == 0x20 && ((byte) meta.getValue() & 0x01) == 0x01 && (displayName = getMetaByIndex(metadataList, 2)) != null && !((String) displayName.getValue()).isEmpty() && (displayNameVisible = getMetaByIndex(metadataList, 3)) != null && (boolean) displayNameVisible.getValue()) {
                    if (!knownHolograms.contains(entityId)) {
                        knownHolograms.add(entityId);
                        try {
                            // Send movement
                            PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_POSITION, null, user());
                            wrapper.write(Type.VAR_INT, entityId);
                            wrapper.write(Type.SHORT, (short) 0);
                            wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
                            wrapper.write(Type.SHORT, (short) 0);
                            wrapper.write(Type.BOOLEAN, true);
                            wrapper.scheduleSend(Protocol1_9To1_8.class);
                        } catch (Exception ignored) {
                        }
                    }
                }
            }
        }
        // Boss bar
        if (Via.getConfig().isBossbarPatch()) {
            if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
                if (metadata.id() == 2) {
                    BossBar bar = bossBarMap.get(entityId);
                    String title = (String) metadata.getValue();
                    title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? DRAGON_TRANSLATABLE : WITHER_TRANSLATABLE) : title;
                    if (bar == null) {
                        bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, BossColor.PINK, BossStyle.SOLID);
                        bossBarMap.put(entityId, bar);
                        bar.addConnection(user());
                        bar.show();
                        // Send to provider
                        Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
                    } else {
                        bar.setTitle(title);
                    }
                } else if (metadata.id() == 6 && !Via.getConfig().isBossbarAntiflicker()) {
                    // If anti flicker is enabled, don't update health
                    BossBar bar = bossBarMap.get(entityId);
                    // Make health range between 0 and 1
                    float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
                    float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
                    if (bar == null) {
                        String title = type == EntityType.ENDER_DRAGON ? DRAGON_TRANSLATABLE : WITHER_TRANSLATABLE;
                        bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
                        bossBarMap.put(entityId, bar);
                        bar.addConnection(user());
                        bar.show();
                        // Send to provider
                        Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(user(), bar.getId());
                    } else {
                        bar.setHealth(health);
                    }
                }
            }
        }
    }
}
Also used : DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) BossBarProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper)

Aggregations

BossBar (com.viaversion.viaversion.api.legacy.bossbar.BossBar)2 BossBarProvider (com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider)2 DataItem (com.viaversion.viaversion.api.minecraft.item.DataItem)1 Item (com.viaversion.viaversion.api.minecraft.item.Item)1 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)1 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)1