Search in sources :

Example 76 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project bewitchment by MoriyaShiine.

the class SpawnSpecterBangleParticlesPacket method send.

public static void send(PlayerEntity player, Entity entity) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(entity.getId());
    ServerPlayNetworking.send((ServerPlayerEntity) player, ID, buf);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 77 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project bewitchment by MoriyaShiine.

the class SyncContractsPacket method handle.

public static void handle(MinecraftClient client, ClientPlayNetworkHandler network, PacketByteBuf buf, PacketSender sender) {
    NbtCompound contractsCompound = buf.readNbt();
    client.execute(new Runnable() {

        @Override
        public void run() {
            if (client.player != null) {
                BWComponents.CONTRACTS_COMPONENT.maybeGet(client.player).ifPresent(contractsComponent -> {
                    contractsComponent.getContracts().clear();
                    NbtList contractsList = contractsCompound.getList("Contracts", NbtType.COMPOUND);
                    for (int i = 0; i < contractsList.size(); i++) {
                        NbtCompound contractCompound = contractsList.getCompound(i);
                        contractsComponent.addContract(new Contract.Instance(BWRegistries.CONTRACTS.get(new Identifier(contractCompound.getString("Contract"))), contractCompound.getInt("Duration"), contractCompound.getInt("Cost")));
                    }
                });
            }
        }
    });
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Contract(moriyashiine.bewitchment.api.registry.Contract) NbtList(net.minecraft.nbt.NbtList) PacketByteBuf(net.minecraft.network.PacketByteBuf) Unpooled(io.netty.buffer.Unpooled) BWRegistries(moriyashiine.bewitchment.common.registry.BWRegistries) NbtCompound(net.minecraft.nbt.NbtCompound) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) NbtType(net.fabricmc.fabric.api.util.NbtType) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) BWComponents(moriyashiine.bewitchment.common.registry.BWComponents) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Bewitchment(moriyashiine.bewitchment.common.Bewitchment) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 78 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project bewitchment by MoriyaShiine.

the class SyncHornedSpearPacket method send.

public static void send(PlayerEntity player, HornedSpearEntity entity) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(entity.getId());
    buf.writeItemStack(entity.spear);
    ServerPlayNetworking.send((ServerPlayerEntity) player, ID, buf);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 79 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project MCDoom by AzureDoom.

the class Ballista method inventoryTick.

@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
    if (world.isClient) {
        if (((PlayerEntity) entity).getMainHandStack().getItem() instanceof Ballista && ClientInit.reload.isPressed() && selected) {
            PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
            passedData.writeBoolean(true);
            ClientPlayNetworking.send(DoomMod.BALLISTA, passedData);
        }
    }
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 80 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project MCDoom by AzureDoom.

the class Chaingun method inventoryTick.

@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
    if (world.isClient) {
        if (((PlayerEntity) entity).getMainHandStack().getItem() instanceof Chaingun && ClientInit.reload.isPressed() && selected) {
            PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
            passedData.writeBoolean(true);
            ClientPlayNetworking.send(DoomMod.CHAINGUN, passedData);
        }
    }
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)117 PlayerEntity (net.minecraft.entity.player.PlayerEntity)21 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)14 Identifier (net.minecraft.util.Identifier)8 NbtCompound (net.minecraft.nbt.NbtCompound)7 Environment (net.fabricmc.api.Environment)5 CustomPayloadC2SPacket (net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)5 CustomPayloadS2CPacket (net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket)4 Nullable (org.jetbrains.annotations.Nullable)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 JSONSource (de.modprog.blockmeter.util.JSONSource)2 Map (java.util.Map)2 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)2 LivingEntity (net.minecraft.entity.LivingEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ParticleType (net.minecraft.particle.ParticleType)2 LiteralText (net.minecraft.text.LiteralText)2