Search in sources :

Example 11 with FriendlyByteBuf

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

the class PacketHelperImpl method sendBrand.

@Override
public void sendBrand(Player player, String brand) {
    ResourceLocation packetKey = new ResourceLocation("minecraft", "brand");
    FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
    buf.writeUtf(brand);
    ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(packetKey, buf);
    send(player, packet);
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 12 with FriendlyByteBuf

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

the class DenizenNetworkManagerImpl method copyPacket.

public static FriendlyByteBuf copyPacket(Packet<?> original) {
    try {
        FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
        original.write(copier);
        return copier;
    } catch (Throwable ex) {
        com.denizenscript.denizen.utilities.debugging.Debug.echoError(ex);
        return null;
    }
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf)

Example 13 with FriendlyByteBuf

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

the class PacketHelperImpl method showMobHealth.

@Override
public void showMobHealth(Player player, LivingEntity mob, double health, double maxHealth) {
    AttributeInstance attr = new AttributeInstance(Attributes.MAX_HEALTH, (a) -> {
    });
    attr.setBaseValue(maxHealth);
    send(player, new ClientboundUpdateAttributesPacket(mob.getEntityId(), Collections.singletonList(attr)));
    FriendlyByteBuf healthData = new FriendlyByteBuf(Unpooled.buffer());
    healthData.writeVarInt(mob.getEntityId());
    // health id
    healthData.writeByte(9);
    // type = float
    healthData.writeVarInt(2);
    healthData.writeFloat((float) health);
    // Mark end of packet
    healthData.writeByte(255);
    send(player, new ClientboundSetEntityDataPacket(healthData));
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 14 with FriendlyByteBuf

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

the class PacketHelperImpl method showDebugTestMarker.

@Override
public void showDebugTestMarker(Player player, Location location, ColorTag color, int alpha, String name, int time) {
    ResourceLocation packetKey = new ResourceLocation("minecraft", "debug/game_test_add_marker");
    FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
    buf.writeBlockPos(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
    int colorInt = color.getColor().getBlue() | (color.getColor().getGreen() << 8) | (color.getColor().getRed() << 16) | (alpha << 24);
    buf.writeInt(colorInt);
    buf.writeByteArray(name.getBytes(StandardCharsets.UTF_8));
    buf.writeInt(time);
    ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(packetKey, buf);
    send(player, packet);
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos)

Example 15 with FriendlyByteBuf

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

the class PacketHelperImpl method showMobHealth.

@Override
public void showMobHealth(Player player, LivingEntity mob, double health, double maxHealth) {
    AttributeInstance attr = new AttributeInstance(Attributes.MAX_HEALTH, (a) -> {
    });
    attr.setBaseValue(maxHealth);
    send(player, new ClientboundUpdateAttributesPacket(mob.getEntityId(), Collections.singletonList(attr)));
    FriendlyByteBuf healthData = new FriendlyByteBuf(Unpooled.buffer());
    healthData.writeVarInt(mob.getEntityId());
    // health id
    healthData.writeByte(9);
    // type = float
    healthData.writeVarInt(2);
    healthData.writeFloat((float) health);
    // Mark end of packet
    healthData.writeByte(255);
    send(player, new ClientboundSetEntityDataPacket(healthData));
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Aggregations

FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)21 ResourceLocation (net.minecraft.resources.ResourceLocation)7 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.core.BlockPos)2 AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 BitSet (java.util.BitSet)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 Packet (net.minecraft.network.protocol.Packet)1 ClientboundLevelChunkPacket (net.minecraft.network.protocol.game.ClientboundLevelChunkPacket)1 ClientboundLevelChunkPacketData (net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData)1 ClientboundLevelChunkWithLightPacket (net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket)1 BitStorage (net.minecraft.util.BitStorage)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 Biome (net.minecraft.world.level.biome.Biome)1 PalettedContainer (net.minecraft.world.level.chunk.PalettedContainer)1