-
-
Notifications
You must be signed in to change notification settings - Fork 51
Datapack export improvements #84
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
Datapack export improvements #84
Conversation
Loader was treating nbt format v3 like v2
Merge changes from v3.6.0
- Added option to export out of range notes - Added enable loop option - Optimized song playback using binary encoding - Allows any tempo under 20 t/s - Pitch values are more accurate
- Implement custom namespace and path - Update datapack window to accommodate fields - Use same random number in tag and objective - Remove bad tempo popup for tempo <= 20
- Move string manipulation functions to their own scripts to make code more tidy - Remove dat_inittempo
- Add ZipWriter extension - Implement option to export as ZIP instead of a folder - Move file writing to its own script - Move folder structure creation to its own script
- Truncate command preview when it's too long - Minor grammar fixes in the datapack window - Change input box IDs (were conflicting with the ones in song info) - Attempts to grab name from the song_name property; if none, tries to grab from filename - Selectively exports function files by ensuring the columns in each branch contain notes (reduces function count if the song has "gaps") - Fix extra slash at the end of function directory when exporting as ZIP
- Add button to save resouce pack containing out of range notes - Only unlocks when that option is checked on the datapack window - Fix playspeed not being set correctly
- Added support to any tempo up to 30.00 t/s - Optimized code of the binary tree - Fixed a bug with the 'play' command - Unified tag and objective names (both start with 'song')
- Split compatibility indicator into "schematic" and "data pack" to make it clearer when you can export to each one - Moved some stuff around in the datapack window - Made namespace and path gray out to tell when they're not used - Made default source "record" instead of "block" - Changed spelling to "data pack" as in the game
Moved from ZipWriter extension to a 7-Zip executable (couldn't get function tags to work for some reason)
- Include song name in pack description - Show commands to play the song in the "saved successfully" popup - Tag and objective now uses first 10 characters of song name (easier to remove stray data after removing a datapack)
Re #91: It might also be necessary to include 7-Zip's license, see section "Can I use the EXE or DLL files from 7-Zip in a Commercial Application?" on https://www.7-zip.org/faq.html
Even though this is not a commercial application, this probably still applies. And giving credit is also good manners. |
I planned to add credits from the very beginning of this update, but since this isn't a commercial application (as you mentioned), I didn't make it a priority. I'll make sure to add it to the 'About' section before the next release. |
|
||
// Add command to result | ||
if(o.dat_enableradius) str += "execute at @s run playsound "+ soundname +" "+source+" @a ~ ~ ~ " + string(o.dat_radiusvalue) + " " + string(pitch) + br | ||
else str += "playsound "+ soundname +" "+source+" @s ^" + string(blockposition*2) + " ^ ^ "+string(blockvolume)+ " " + string(pitch) + " 1" + br |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears Minecraft determines the volume based on the camera position, compare:
/execute anchored eyes run playsound minecraft:block.note_block.banjo ambient @s ^ ^ ^ 0.25
/playsound minecraft:block.note_block.banjo ambient @s ~ ~ ~ 0.25
Though the difference might be negligible (if there is actually a difference).
Edit: Nevermind, when the sound is played at eyelevel, it is not stereo: MC-164575
The changes proposed in this PR bring many new possibilities to the data pack export feature, optimizing the playback to run only a few commands at a time, allowing songs that were previously incompatible to be played in Minecraft, allowing more flexibility in regard to how the folders are arranged in the pack, adding the option to export to ZIP and much more!
Optimized song playback using binary encoding
Uses binary search (splits the range in half every iteration) to find which tick to play at a given moment
i.e. to play tick 3 in a 64-tick song, will look for players in range 1-32, then 1-16, then 1-8, 1-4, 3-4 and finally reach 3.
For a song with 4000 ticks, this reduces the amount of commands running every tick from 4000 to a mere 24 (
log2(4000) ≈ 12
), which is to say two commands are added for each power of 2 less than the song lengthMakes performance impact negligible. Below is a ms/tick comparison for a song with 2500 ticks (top is a data pack generated with the latest version of Note Block Studio; bottom is the new version):

On the other hand, the number of generated functions can easily reach the thousands (which shouldn't be too big a of a deal).
Now allows any tempo
speed
in the song's objective. This value is added to the total count every tick and, every time it accumulates to 80, the next tick is playedspeed
value in-game, which is obtained by multiplying it by 4 (this way 0.25 t/s becomes 1, 20 t/s becomes 80 and so on)speed
score, but it will get reset on reloadnbs_<songname>
andnbs_<songname>_t
Added option to export out of range notes
_-1
or_1
to the sound eventAdded option to export as ZIP
Added enable loop option
Redesigned compatibility indicator and window
Added fields to set custom namespace and path to function folder
dat_makefolders()
is responsible for recursively creating the necessary foldersAdded command preview
string_path()
, while path is processed bydat_getpath()
Tags and objectives are now
nbs_<songname>
instead of a random numberPitch values are now 1000x more accurate, making song less out of tune
string_format()
rather thanstring()
when converting the pitch value to string, which rounds to five decimal places instead of twoAttempts to grab name from the 'Song name' field in the song properties; if none, tries to grab from the file name
Moved file writing to a separate script (
dat_writefile()
) to avoid repetitionAdded box surrounding the window's content to make layout consistent with schematic export
Changed spelling to "data pack" instead of "datapack", as in the game
The commands used to control the song are shown in the popup at the end of export

Sound source hover descriptions now show the slider which the source is controlled by

Default sound source was changed to
record
(corresponds to 'Jukebox/Note Blocks')Includes song name in the pack description