Java Code Examples for codechicken.lib.packet.PacketCustom#sendToPlayer()

The following examples show how to use codechicken.lib.packet.PacketCustom#sendToPlayer() . 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: WRAddonSPH.java    From WirelessRedstone with MIT License 6 votes vote down vote up
public static void sendTrackerUpdatePacketTo(EntityPlayerMP player, EntityWirelessTracker tracker) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 60);
    packet.writeInt(tracker.getEntityId());
    packet.writeShort(tracker.freq);
    packet.writeBoolean(tracker.isAttachedToEntity());
    if (tracker.isAttachedToEntity()) {
        packet.writeInt(tracker.attachedEntity.getEntityId());
        packet.writeFloat(tracker.attachedX);
        packet.writeFloat(tracker.attachedY);
        packet.writeFloat(tracker.attachedZ);
        packet.writeFloat(tracker.attachedYaw);
    } else {
        packet.writeFloat((float) tracker.posX);
        packet.writeFloat((float) tracker.posY);
        packet.writeFloat((float) tracker.posZ);
        packet.writeFloat((float) tracker.motionX);
        packet.writeFloat((float) tracker.motionY);
        packet.writeFloat((float) tracker.motionZ);
        packet.writeShort(tracker.attachmentCounter);
        packet.writeBoolean(tracker.item);
    }

    packet.sendToPlayer(player);
}
 
Example 2
Source File: ServerUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider, Consumer<MCDataOutput> packetConsumer) {
    if (player.world.isRemote()) {
        return;
    }
    player.closeContainer();
    player.getNextWindowId();
    int containerId = player.currentWindowId;

    Container container = containerProvider.createMenu(containerId, player.inventory, player);
    ContainerType<?> type = container.getType();

    PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_OPEN_CONTAINER);
    packet.writeRegistryIdUnsafe(ForgeRegistries.CONTAINERS, type);
    packet.writeVarInt(containerId);
    packet.writeTextComponent(containerProvider.getDisplayName());
    packetConsumer.accept(packet);

    packet.sendToPlayer(player);
    player.openContainer = container;
    player.openContainer.addListener(player);
    MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}
 
Example 3
Source File: BlockChunkLoader.java    From ChickenChunks with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    int meta = world.getBlockMetadata(x, y, z);
    if (meta != 0 || player.isSneaking())
        return false;

    if (!world.isRemote) {
        TileChunkLoader tile = (TileChunkLoader) world.getTileEntity(x, y, z);
        if (tile.owner == null || tile.owner.equals(player.getCommandSenderName()) ||
                ChunkLoaderManager.opInteract() && ServerUtils.isPlayerOP(player.getCommandSenderName())) {
            PacketCustom packet = new PacketCustom(ChunkLoaderSPH.channel, 12);
            packet.writeCoord(x, y, z);
            packet.sendToPlayer(player);
        } else
            player.addChatMessage(new ChatComponentTranslation("chickenchunks.accessdenied"));
    }
    return true;
}
 
Example 4
Source File: WRCoreSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendSetFreqInfoTo(EntityPlayer player, int freq, String name, int colourid) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 4);
    packet.writeShort(freq);
    packet.writeByte(colourid);
    packet.writeString(name);

    packet.sendToPlayer(player);
}
 
Example 5
Source File: NEISPH.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void sendHasServerSideTo(EntityPlayerMP player) {
    NEIServerConfig.logger.debug("Sending serverside check to: " + player.getCommandSenderName());
    PacketCustom packet = new PacketCustom(channel, 1);
    packet.writeByte(NEIActions.protocol);
    packet.writeString(player.worldObj.getWorldInfo().getWorldName());

    packet.sendToPlayer(player);
}
 
Example 6
Source File: WRAddonSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendUpdateSnifferTo(EntityPlayer player, int freq, boolean on) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 53);
    packet.writeShort((short) freq);
    packet.writeBoolean(on);

    packet.sendToPlayer(player);
}
 
Example 7
Source File: WRCoreSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendFreqOwnerTo(EntityPlayer player, ArrayList<Integer> freqsWithOwners) {
    if (freqsWithOwners.size() == 0)
        return;

    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 10);
    packet.writeShort(freqsWithOwners.size());
    for (int freq : freqsWithOwners) {
        packet.writeShort(freq);
        packet.writeString(RedstoneEther.get(false).getFreqOwner(freq));
    }
    packet.sendToPlayer(player);
}
 
Example 8
Source File: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 5 votes vote down vote up
public void updatePlayer(EntityPlayer player)
{
    PacketCustom packet = new PacketCustom(channel, 6);
    packet.writeString(player.getCommandSenderName());
    packet.writeInt(player.dimension);
    Vector3 pos = Vector3.fromEntity(player);
    packet.writeFloat((float) pos.x);
    packet.writeFloat((float) pos.y);
    packet.writeFloat((float) pos.z);
    
    packet.sendToPlayer(owner);
}
 
Example 9
Source File: ContainerItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
@Override
public void sendLargeStack(ItemStack stack, int slot, List<EntityPlayerMP> players) {
    PacketCustom packet = new PacketCustom(TranslocatorSPH.channel, 5);
    packet.writeByte(slot);
    packet.writeItemStack(stack, true);

    for (EntityPlayerMP player : players)
        packet.sendToPlayer(player);
}
 
Example 10
Source File: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 5 votes vote down vote up
public void sendChunkChange(ChunkChange change)
{
    PacketCustom packet = new PacketCustom(channel, 4);
    packet.writeInt(change.dimension);
    packet.writeInt(change.chunk.chunkXPos);
    packet.writeInt(change.chunk.chunkZPos);
    packet.writeBoolean(change.add);

    packet.sendToPlayer(owner);
}
 
Example 11
Source File: PlayerChunkViewerTracker.java    From ChickenChunks with MIT License 5 votes vote down vote up
public void unloadDimension(int dim)
{
    PacketCustom packet = new PacketCustom(channel, 3);
    packet.writeInt(dim);
    
    packet.sendToPlayer(owner);
}
 
Example 12
Source File: ContainerSynchronised.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public void sendContainerAndContentsToPlayer(Container container, List<ItemStack> list, List<EntityPlayerMP> playerCrafters)
{
    super.sendContainerAndContentsToPlayer(container, list, playerCrafters);
    for(int i = 0; i < syncVars.size(); i++)
    {
        IContainerSyncVar var = syncVars.get(i);
        PacketCustom packet = createSyncPacket();
        packet.writeByte(i);
        var.writeChange(packet);
        var.reset();
        for(EntityPlayerMP player : playerCrafters)
            packet.sendToPlayer(player);
    }
}
 
Example 13
Source File: WRAddonSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendEtherCopyTo(EntityPlayer player, byte[] ethercopy) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 54);
    packet.writeShort(ethercopy.length);
    packet.writeByteArray(ethercopy);

    packet.sendToPlayer(player);
}
 
Example 14
Source File: TankSynchroniser.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public void sendSyncPacket()
{
    if(!tracking)
        return;
    
    PacketCustom packet = new PacketCustom(EnderStorageSPH.channel, 4);
    packet.writeShort(storage.freq);
    packet.writeString(storage.owner);
    packet.writeFluidStack(s_liquid);
    packet.sendToPlayer(player);
}
 
Example 15
Source File: WRCoreSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendPublicFrequencyTo(EntityPlayer player, int freq) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 2);
    packet.writeShort(freq);
    packet.writeByte(1);

    packet.sendToPlayer(player);
}
 
Example 16
Source File: WRCoreSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendSetFrequencyRangeTo(EntityPlayer player, int startfreq, int endfreq, boolean jam) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 3);
    packet.writeShort((short) startfreq);
    packet.writeShort((short) endfreq);
    packet.writeBoolean(jam);

    packet.sendToPlayer(player);
}
 
Example 17
Source File: NEIServerPacketHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
/**
 * Sends the current protocol version and world to the client.
 * Called every time the player changes dimensions.
 * If successful on the client, it will request a LoginState.
 *
 * @param player The player to send the ServerSide check to.
 */
public static void sendServerSideCheck(EntityPlayerMP player) {
    LogHelper.debug("Sending ServerSide check to: " + player.getName());
    PacketCustom packet = new PacketCustom(channel, 1);
    packet.writeByte(NEIActions.protocol);
    packet.writeString(player.world.getWorldInfo().getWorldName());

    packet.sendToPlayer(player);
}
 
Example 18
Source File: EnderStorageSPH.java    From EnderStorage with MIT License 4 votes vote down vote up
public static void sendOpenUpdateTo(ServerPlayerEntity player, Frequency freq, boolean open) {
    PacketCustom packet = new PacketCustom(EnderStorageNetwork.NET_CHANNEL, 3);
    freq.writeToPacket(packet);
    packet.writeBoolean(open);
    packet.sendToPlayer(player);
}
 
Example 19
Source File: NEISPH.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static void sendAddMagneticItemTo(EntityPlayerMP player, EntityItem item) {
    PacketCustom packet = new PacketCustom(channel, 13);
    packet.writeInt(item.getEntityId());

    packet.sendToPlayer(player);
}
 
Example 20
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Call from {@link Block#addLandingEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 *
 * @param world        The world.
 * @param pos          The position of the block.
 * @param entity       The entity.
 * @param numParticles The number of particles to spawn.
 * @return Always true for this, basically just return the result of this method inside {@link Block#addLandingEffects}
 */
public static boolean handleLandingEffects(ServerWorld world, BlockPos pos, LivingEntity entity, int numParticles) {
    PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_ADD_LANDING_EFFECTS);
    packet.writePos(pos);
    packet.writeVector(Vector3.fromEntity(entity));
    packet.writeVarInt(numParticles);
    packet.sendToPlayer((ServerPlayerEntity) entity);
    return true;
}