Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate tags command clipboard text within 32k string limit #1546

Conversation

sciwhiz12
Copy link
Member

@sciwhiz12 sciwhiz12 commented Sep 15, 2024

This PR fixes #1543 by truncating the number of lines in the copy-to-clipboard text of the /neoforge tags command to as much entries as can fit within the (artificial) limit of 32.6k characters for elements (plus some allowance for the explanatory text for the truncation).

Tested by modifying the list subcommand temporarily to have 30,000+ dummy entries (adding to the count and using Stream.concat), and it works.

A previous version of this PR artifically constrained the number of entries to 1,000 entries (approximately the number of 32-character-long entries that fits into 32,767--the limit of strings in FriendlyByteBuf--and rounded down the nearest hundreds). At @Technici4n's prompting (in Discord), I've changed the strategy to instead fit as much of the entries as possible by counting their lengths as they're added to the text, and cutting off when the text is about to reach a limit, which is current 32,600 characters. That leaves about ~167 characters room for the explanatory note for the truncation, which should be plenty.


We could perhaps consider adding a new subcommand to /neoforge dump which exports the list of tags for registries (or elements in a tag, or tags of an element). Should that be added, we may also remove the functionality of the copy-on-clipboard for /neoforge tags, and perhaps even have it instead give the appropriate /neoforge dump command to the user with arguments filled in.

@sciwhiz12 sciwhiz12 added bug A bug or error 1.21.1 Targeted at Minecraft 1.21.1 labels Sep 15, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Sep 15, 2024

  • Publish PR to GitHub Packages

Last commit published: 297c5cee1c93bb61f93d067837d7c1a1eaf49ede.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1546' // https://github.com/neoforged/NeoForge/pull/1546
        url 'https://prmaven.neoforged.net/NeoForge/pr1546'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1546.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1546
cd NeoForge-pr1546
curl -L https://prmaven.neoforged.net/NeoForge/pr1546/net/neoforged/neoforge/21.3.38-beta-pr-1546-1.21.1-GH-1543-tags-command-clipboard-truncation/mdk-pr1546.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@HenryLoenwind
Copy link
Contributor

One thought: Does this really need to run as a server command? Those registries are synced to the client, aren't they?

@lukebemish
Copy link
Contributor

Not necessarily -- afaik that command dumps tags for any registry, including server only ones? Registries can have tags and not be synced.

@sciwhiz12 sciwhiz12 added 1.21.3 Targeted at Minecraft 1.21.3 and removed 1.21.1 Targeted at Minecraft 1.21.1 labels Nov 2, 2024
This may be less elegant to look at and read, but it fits more into the
32.6k limit we (artificially) set for the clipboard text by actually
measuring the text as we go add more elements, until no more can fit
within the limit.
@sciwhiz12 sciwhiz12 changed the title Truncate tags command clipboard text to 1000 entries Truncate tags command clipboard text within 32k string limit Nov 18, 2024
@sciwhiz12
Copy link
Member Author

Updated to use a new truncation strategy that fits as much text as possible into the clipboard text, rather than constraining the amount of elements based on a precalculated heuristic on element lengths. See updated PR description for details.

@sciwhiz12 sciwhiz12 merged commit 5ae8211 into neoforged:1.21.x Nov 19, 2024
6 checks passed
@neoforged-releases
Copy link

🚀 This PR has been released as NeoForge version 21.3.35-beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.3 Targeted at Minecraft 1.21.3 bug A bug or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running command /neoforge tags <registry> list could kick player when there are too many tags
5 participants