Copyright © Curt Hill Sounds, Resource Packs, JSON What more would you want?
Introduction A resource pack allows replacement of a series of textures, sounds or music to be installed instead of the standard Minecraft versions In order to add new sounds we will put them in a resource pack –Then figure out how to use them We will need JSON as well –That is where we will start Copyright © Curt Hill
What is JSON? JavaScript Object Notation A language for data interchange –Derived from JavaScript (ECMA standard) –Alternative to XML in that respect Both easy for people to read and easy for machines to parse Consists of sequences and attribute- value pairs It is an open standard Copyright © Curt Hill
Simple Types Does not have many Number –A floating point type String –Enclosed in double quotes –Uses UNICODE characters Boolean –May be true or false null –Indicates an empty value Copyright © Curt Hill
Structured Types Only two structuring types Object –Similar to a group, record, or struct, depending on language –Unordered, comma separated list of name value pairs enclosed in braces { } –The key is separated from the value by a colon Array –An ordered, comma separated list of values enclosed in brackets [ ] Copyright © Curt Hill
Commentary White space may be interspersed for readability without changing meaning Hardly any programming language lacks these features –Most have a JSON interface Keys are merely strings –Enclosed in double quotes Copyright © Curt Hill
Example A simple object to contain a name: { “first”:”Bill”, “lastname”: “Smith” } An array of names inside an object: { “employees” : [ {“first”:”Bill”, “last”:“Sam” }, {“first”:”John”, “last”:“Doe” }, {“first”:”Curt”, “last”:“Hill” } ] } We will see two examples in resource packs Copyright © Curt Hill
BSON Binary JSON also exists This is a binary encoded serialization of JSON objects These should be more compact and faster to parse This we will not use in this class Copyright © Curt Hill
Resource Packs A resource pack is a zip file containing a directory tree Various parts of this tree contain the resources that Minecraft will replace its native resources We need to look at several parts of this tree –Starting at the root Copyright © Curt Hill
The root directory Contains three things: An assets directory The pack.mcdata file –The first of our two JSON files in this presentation A pack.png file –For display Copyright © Curt Hill
pack.mcdata A JSON file that identifies the resource pack There may be several things in it, but the required information is the name and format of the pack See the next slide for an example Copyright © Curt Hill
Required Example Copyright © Curt Hill { "pack": { "description": "Curt's Minecraft Resources", "pack_format": 1 }
Other things There may be other things in this file as well The template resource pack contains numerous language types Copyright © Curt Hill
Directory Structure Copyright © Curt Hill
Moving Down The assets directory is rooted in the top level directory It only contains the minecraft directory Inside the minecraft directory are several resource directories There is also the sounds.json file Copyright © Curt Hill
Minecraft directory Contains as many of the following subdirectories as you want to use: –icons –music –records –sounds –textures Today we are only interested in sounds Copyright © Curt Hill
Sounds Directory May contain 15 or more subdirectories Again, these depend on what you want to replace These include: –Damage –Dig –Fire –Mob –Music –Step –Among others Copyright © Curt Hill
Example: Step Directory This contains the noise made when an entity steps on a particular type of block Usually there are several alternatives so the exact same noise is not used for every step In the template there are 4 cloth, 6 grass, 4 gravel etc. Copyright © Curt Hill
Built ins and not Most of the sounds are built-in –Their presence in the correct directory is all that is needed Should you add something another file is needed: sound.json Yet another JSON file that gives additional control information to the game Sounds that are not standard need an entry in this file Copyright © Curt Hill
The sounds.json file First recall that this file is in the assets/minecraft directory It has one or more entries that give a name to a sound and then describe its location –Possibly other things as well Copyright © Curt Hill
Minimal Example File Copyright © Curt Hill { "lightblock": { "category": "neutral", "sounds": [ "step/lightblock" ] }, "step.lightblock": { "category": "neutral", "sounds": [ "step/lightblock" ] }
Commentary This file gave two names for the same file –This is done in two entries First entry is the name –This identifies an object The object may contain two or more entries –Only two were shown: category and sounds Copyright © Curt Hill
Object entries Category determines the volume controls Several options here: –ambient –weather –player –neutral –block –record –Among others Copyright © Curt Hill
Volume Controls Copyright © Curt Hill
Testing Once we have established a named sound in: –The resource pack –sounds.json We should be able to use it In the client we should be able to type: /playsound –The sound should play or the console record the error Copyright © Curt Hill
Playing Copyright © Curt Hill
Played Copyright © Curt Hill
Commentary The screen said it was played, but what he really means is that he tried to play it The console will have a complaint if it tried to play it but could not find it Later we will consider the Java code to play it Before that we continue with the resource pack Copyright © Curt Hill
Template Pack A template resource pack is at: resource-pack-template.7540/ resource-pack-template.7540/ This is the basis of what I have used Download and extract it to a directory –Not your minecraft directory Then modify it to suit Copyright © Curt Hill
Modification Modify the pack.mcdata and pack.png –Only the name of the resource pack Create and edit the new sounds Add these new sounds to whichever directory seems appropriate Create and add the sounds.json file to the minecraft directory Rezip it and copy to the correct directory Copyright © Curt Hill
Rezip There are several zip utilities The built-in in Windows Explorer is the easiest Enter the top level directory Select all of these –assets directory –pack.mcdata –pack.png Right click and choose Send to compressed file Rename it to your own name Copyright © Curt Hill
Getting Minecraft to use it The resource file needs to be in a particular directory This can be easily found by clicking the options and resource buttons Then click on Open Resource Pack folder –This will open a Windows Explorer in the right directory Copyright © Curt Hill
Selected Resource Packs Copyright © Curt Hill
Finding location Copyright © Curt Hill
Selection Once Minecraft knows it is available it should be in the left column Move to right column Make it first Now it should be available when you play Next we consider sounds and playing them at appropriate times Copyright © Curt Hill
Sounds We have already seen the Block method setStepSound It takes as a parameter a Block.SoundType class Up to now we have used one of the constant sounds: –soundTypeAnvil, soundTypeCloth, soundTypeGlass, soundTypeGrass, soundTypeGravel, soundTypeMetal, soundTypeSand, etc. Now we want more Copyright © Curt Hill
Block.SoundType A class in its own right Has three properties: –float frequency –String soundName –float volume The constructor takes all three –Name, frequency, volume Copyright © Curt Hill
Constructor Again The frequency is more like playback speed 1.0F means normal –Less than one means slow it down –More than one speeds it up The volume should be between 0-1 –Moderated by sliders The name is the name in sounds.json This is usually used inside the setStepSound or similar method Copyright © Curt Hill
Ways to play sound Blocks contain the setStepSound –Strangely, there is no setDigSound method The other way is playSound –This is a method in Entity Copyright © Curt Hill
setStepSound We have seen this using a constant sound Here is the example using a new sound: setStepSound( new Block.SoundType ("lightblock",1.0F,1.0F)); The lightblock is in the sounds.json file Copyright © Curt Hill
playSound This one is somewhat different It is a member of Entity The signature is: void playSound(String name, float freq, float vol); – Where Freq is the playback speed Vol is the volume Copyright © Curt Hill
Where? The playSound method may be used in anything with access to an Entity In particular this is usually in event handlers: –onEntityWalking –onEntityCollidedWithBlock These both have a parameter that gives the entity that did the action Copyright © Curt Hill
Finally Now we know about using sounds –Putting them in resource packs –Construction JSON files that describe Time for the demo Copyright © Curt Hill