net.minecraft.network.IPacket Java Examples

The following examples show how to use net.minecraft.network.IPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void sendToPlayer(IPacket<?> packet, ServerPlayerEntity player) {
    if (player == null) {
        sendToClients(packet);
    } else {
        player.connection.sendPacket(packet);
    }
}
 
Example #2
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void sendToOps(IPacket<?> packet) {
    OpList opList = ServerUtils.getServer().getPlayerList().getOppedPlayers();
    for (ServerPlayerEntity player : ServerUtils.getServer().getPlayerList().getPlayers()) {
        if (opList.hasEntry(player.getGameProfile())) {
            sendToPlayer(packet, player);
        }
    }
}
 
Example #3
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IPacket<?> toPacket(NetworkDirection direction) {
    return toPacket(direction, 0);
}
 
Example #4
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IPacket<?> toPacket(NetworkDirection direction, int index) {
    if (incoming()) {
        throw new IllegalStateException("Tried to write an incoming packet");
    }
    return direction.buildPacket(Pair.of(toPacketBuffer(), index), channel).getThis();
}
 
Example #5
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToClients(IPacket<?> packet) {
    ServerUtils.getServer().getPlayerList().sendPacketToAllPlayers(packet);
}
 
Example #6
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToAllAround(IPacket<?> packet, double x, double y, double z, double range, DimensionType dim) {
    ServerUtils.getServer().getPlayerList().sendToAllNearExcept(null, x, y, z, range, dim, packet);
}
 
Example #7
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToDimension(IPacket<?> packet, DimensionType dim) {
    ServerUtils.getServer().getPlayerList().sendPacketToAllPlayersInDimension(packet, dim);
}
 
Example #8
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToChunk(IPacket<?> packet, World world, BlockPos blockPos) {
    sendToChunk(packet, world, blockPos.getX() >> 4, blockPos.getZ() >> 4);
}
 
Example #9
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToChunk(IPacket<?> packet, World world, int chunkX, int chunkZ) {
    sendToChunk(packet, world, new ChunkPos(chunkX, chunkZ));
}
 
Example #10
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void sendToChunk(IPacket<?> packet, World world, ChunkPos pos) {
    ServerWorld serverWorld = (ServerWorld) world;
    serverWorld.getChunkProvider().chunkManager.getTrackingPlayers(pos, false).forEach(e -> e.connection.sendPacket(packet));
}
 
Example #11
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void sendToServer(IPacket<?> packet) {
    Minecraft.getInstance().getConnection().sendPacket(packet);
}
 
Example #12
Source File: RockEntity.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public IPacket<?> createSpawnPacket()
{
    return NetworkHooks.getEntitySpawningPacket(this);
}
 
Example #13
Source File: PayloadBuilder.java    From BoundingBoxOutlineReloaded with MIT License 4 votes vote down vote up
private PayloadBuilder(ResourceLocation name, BiFunction<ResourceLocation, PacketBuffer, IPacket<?>> packetBuilder) {
    this.name = name;
    this.buffer = new PacketBuffer(Unpooled.buffer());
    this.packetBuilder = packetBuilder;
}
 
Example #14
Source File: PayloadBuilder.java    From BoundingBoxOutlineReloaded with MIT License 4 votes vote down vote up
public IPacket<?> build() {
    if (packet == null)
        packet = packetBuilder.apply(name, buffer);
    return packet;
}