Search in sources :

Example 1 with ClientboundSetEntityDataPacket

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

the class ServerEntityMixin method impl$createSpoofedPacket.

@Redirect(method = "sendDirtyEntityData", at = @At(value = "NEW", target = "net/minecraft/network/protocol/game/ClientboundSetEntityDataPacket"))
private ClientboundSetEntityDataPacket impl$createSpoofedPacket(int entityId, SynchedEntityData dataManager, boolean p_i46917_3_) {
    if (!(this.entity instanceof ServerPlayerBridge && ((ServerPlayerBridge) this.entity).bridge$isHealthScaled())) {
        return new ClientboundSetEntityDataPacket(entityId, dataManager, p_i46917_3_);
    }
    final float scaledHealth = ((ServerPlayerBridge) this.entity).bridge$getInternalScaledHealth();
    final Float actualHealth = dataManager.get(LivingEntityAccessor.accessor$DATA_HEALTH_ID());
    dataManager.set(LivingEntityAccessor.accessor$DATA_HEALTH_ID(), scaledHealth);
    final ClientboundSetEntityDataPacket spoofed = new ClientboundSetEntityDataPacket(entityId, dataManager, p_i46917_3_);
    dataManager.set(LivingEntityAccessor.accessor$DATA_HEALTH_ID(), actualHealth);
    return spoofed;
}
Also used : ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ClientboundSetEntityDataPacket (net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 ServerPlayerBridge (org.spongepowered.common.bridge.server.level.ServerPlayerBridge)1