Search in sources :

Example 1 with ClientboundUpdateAttributesPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_HealthScale method bridge$refreshScaledHealth.

@Override
public void bridge$refreshScaledHealth() {
    // We need to use the dirty instances to signify that the player needs to have it updated, instead
    // of modifying the attribute instances themselves, we bypass other potentially detrimental logic
    // that would otherwise break the actual health scaling.
    final Set<AttributeInstance> dirtyInstances = this.shadow$getAttributes().getDirtyAttributes();
    this.bridge$injectScaledHealth(dirtyInstances);
    // Send the new information to the client.
    final FoodData foodData = this.shadow$getFoodData();
    this.connection.send(new ClientboundSetHealthPacket(this.bridge$getInternalScaledHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel()));
    this.connection.send(new ClientboundUpdateAttributesPacket(this.shadow$getId(), dirtyInstances));
    // Reset the dirty instances since they've now been manually updated on the client.
    dirtyInstances.clear();
}
Also used : AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ClientboundSetHealthPacket(net.minecraft.network.protocol.game.ClientboundSetHealthPacket) FoodData(net.minecraft.world.food.FoodData) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket)

Example 2 with ClientboundUpdateAttributesPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket in project MinecraftForge by MinecraftForge.

the class VanillaConnectionNetworkFilter method filterEntityProperties.

/**
 * Filter for SEntityPropertiesPacket. Filters out any entity attributes that are not in the "minecraft" namespace.
 * A vanilla client would ignore these with an error log.
 */
@Nonnull
private static ClientboundUpdateAttributesPacket filterEntityProperties(ClientboundUpdateAttributesPacket msg) {
    ClientboundUpdateAttributesPacket newPacket = new ClientboundUpdateAttributesPacket(msg.getEntityId(), Collections.emptyList());
    msg.getValues().stream().filter(snapshot -> {
        ResourceLocation key = ForgeRegistries.ATTRIBUTES.getKey(snapshot.getAttribute());
        return key != null && key.getNamespace().equals("minecraft");
    }).forEach(snapshot -> newPacket.getValues().add(snapshot));
    return newPacket;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) Connection(net.minecraft.network.Connection) Registry(net.minecraft.core.Registry) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull) RootCommandNode(com.mojang.brigadier.tree.RootCommandNode) ClientboundCommandsPacket(net.minecraft.network.protocol.game.ClientboundCommandsPacket) ArgumentTypes(net.minecraft.commands.synchronization.ArgumentTypes) ClientboundUpdateTagsPacket(net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket) ImmutableMap(com.google.common.collect.ImmutableMap) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket) Collectors(java.util.stream.Collectors) ResourceKey(net.minecraft.resources.ResourceKey) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ForgeTagHandler(net.minecraftforge.common.ForgeTagHandler) ChannelHandler(io.netty.channel.ChannelHandler) Packet(net.minecraft.network.protocol.Packet) Collections(java.util.Collections) TagCollection(net.minecraft.tags.TagCollection) LogManager(org.apache.logging.log4j.LogManager) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) NetworkHooks(net.minecraftforge.network.NetworkHooks) ResourceLocation(net.minecraft.resources.ResourceLocation) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket) Nonnull(javax.annotation.Nonnull)

Aggregations

ClientboundUpdateAttributesPacket (net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RootCommandNode (com.mojang.brigadier.tree.RootCommandNode)1 ChannelHandler (io.netty.channel.ChannelHandler)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 SharedSuggestionProvider (net.minecraft.commands.SharedSuggestionProvider)1 ArgumentTypes (net.minecraft.commands.synchronization.ArgumentTypes)1 Registry (net.minecraft.core.Registry)1 Connection (net.minecraft.network.Connection)1 Packet (net.minecraft.network.protocol.Packet)1 ClientboundCommandsPacket (net.minecraft.network.protocol.game.ClientboundCommandsPacket)1 ClientboundSetHealthPacket (net.minecraft.network.protocol.game.ClientboundSetHealthPacket)1 ClientboundUpdateTagsPacket (net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket)1 ResourceKey (net.minecraft.resources.ResourceKey)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1