Search in sources :

Example 1 with SynchedEntityData

use of net.minecraft.network.syncher.SynchedEntityData in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setFakeAbsorption.

@Override
public void setFakeAbsorption(Player player, float value) {
    SynchedEntityData dw = new SynchedEntityData(null);
    dw.define(ENTITY_HUMAN_DATA_WATCHER_ABSORPTION, value);
    send(player, new ClientboundSetEntityDataPacket(player.getEntityId(), dw, true));
}
Also used : SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData)

Example 2 with SynchedEntityData

use of net.minecraft.network.syncher.SynchedEntityData in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method sendEntityMetadataFlagsUpdate.

@Override
public void sendEntityMetadataFlagsUpdate(Player player, Entity entity) {
    SynchedEntityData dw = new SynchedEntityData(null);
    dw.define(ENTITY_DATA_WATCHER_FLAGS, ((CraftEntity) entity).getHandle().getEntityData().get(ENTITY_DATA_WATCHER_FLAGS));
    send(player, new ClientboundSetEntityDataPacket(entity.getEntityId(), dw, true));
}
Also used : SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData)

Example 3 with SynchedEntityData

use of net.minecraft.network.syncher.SynchedEntityData in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method sendRename.

@Override
public void sendRename(Player player, Entity entity, String name, boolean listMode) {
    try {
        if (entity.getType() == EntityType.PLAYER) {
            if (listMode) {
                send(player, new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, ((CraftPlayer) player).getHandle()));
            } else {
                // For player entities, force a respawn packet and let the dynamic intercept correct the details
                ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkProvider().chunkMap;
                ChunkMap.TrackedEntity entityTracker = tracker.G.get(entity.getEntityId());
                if (entityTracker != null) {
                    try {
                        ServerEntity entry = (ServerEntity) ENTITY_TRACKER_ENTRY_GETTER.get(entityTracker);
                        if (entry != null) {
                            entry.removePairing(((CraftPlayer) player).getHandle());
                            entry.addPairing(((CraftPlayer) player).getHandle());
                        }
                    } catch (Throwable ex) {
                        Debug.echoError(ex);
                    }
                }
            }
            return;
        }
        SynchedEntityData fakeData = new SynchedEntityData(((CraftEntity) entity).getHandle());
        ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entity.getEntityId(), fakeData, false);
        List<SynchedEntityData.DataItem<?>> list = new ArrayList<>();
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_METADATA, Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(name, ChatColor.WHITE)))));
        list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_VISIBLE_METADATA, true));
        ENTITY_METADATA_LIST_SETTER.invoke(packet, list);
        send(player, packet);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkMap(net.minecraft.server.level.ChunkMap) ServerEntity(net.minecraft.server.level.ServerEntity) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 4 with SynchedEntityData

use of net.minecraft.network.syncher.SynchedEntityData in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method sendEntityMetadataFlagsUpdate.

@Override
public void sendEntityMetadataFlagsUpdate(Player player, Entity entity) {
    SynchedEntityData dw = new SynchedEntityData(null);
    dw.define(ENTITY_DATA_WATCHER_FLAGS, ((CraftEntity) entity).getHandle().getEntityData().get(ENTITY_DATA_WATCHER_FLAGS));
    send(player, new ClientboundSetEntityDataPacket(entity.getEntityId(), dw, true));
}
Also used : SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData)

Example 5 with SynchedEntityData

use of net.minecraft.network.syncher.SynchedEntityData in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setFakeAbsorption.

@Override
public void setFakeAbsorption(Player player, float value) {
    SynchedEntityData dw = new SynchedEntityData(null);
    dw.define(ENTITY_HUMAN_DATA_WATCHER_ABSORPTION, value);
    send(player, new ClientboundSetEntityDataPacket(player.getEntityId(), dw, true));
}
Also used : SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData)

Aggregations

SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)6 ChunkMap (net.minecraft.server.level.ChunkMap)2 ServerEntity (net.minecraft.server.level.ServerEntity)2 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1