Package net.minecraftforge.common.data
Class SoundDefinitionsProvider
- java.lang.Object
-
- net.minecraftforge.common.data.SoundDefinitionsProvider
-
- All Implemented Interfaces:
IDataProvider
- Direct Known Subclasses:
DataGeneratorTest.SoundDefinitions
public abstract class SoundDefinitionsProvider extends java.lang.Object implements IDataProvider
Data provider for thesounds.jsonfile, which identifies sound definitions for the various sound events in Minecraft.
-
-
Field Summary
Fields Modifier and Type Field Description private DataGeneratorgeneratorprivate static com.google.gson.GsonGSONprivate ExistingFileHelperhelperprivate static org.apache.logging.log4j.LoggerLOGGERprivate java.lang.StringmodIdprivate java.util.Map<java.lang.String,SoundDefinition>sounds-
Fields inherited from interface net.minecraft.data.IDataProvider
SHA1
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSoundDefinitionsProvider(DataGenerator generator, java.lang.String modId, ExistingFileHelper helper)Creates a new instance of this data provider.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadd(java.lang.String soundEvent, SoundDefinition definition)Adds theSoundEventwith the specified name along with itsSoundDefinitionto the list.protected voidadd(java.util.function.Supplier<SoundEvent> soundEvent, SoundDefinition definition)Adds the entry name associated with the suppliedSoundEventwith the givenSoundDefinitionto the list.protected voidadd(ResourceLocation soundEvent, SoundDefinition definition)protected voidadd(SoundEvent soundEvent, SoundDefinition definition)Adds the entry name associated with the givenSoundEventwith theSoundDefinitionto the list.private voidaddSounds(java.lang.String soundEvent, SoundDefinition definition)protected static SoundDefinitiondefinition()Creates a newSoundDefinition, which will host a set ofSoundDefinition.Sounds and the necessary parameters.java.lang.StringgetName()private com.google.gson.JsonObjectmapToJson(java.util.Map<java.lang.String,SoundDefinition> map)abstract voidregisterSounds()Registers the sound definitions that should be generated via one of theaddmethods.voidrun(DirectoryCache cache)private voidsave(DirectoryCache cache, java.nio.file.Path targetFile)protected static SoundDefinition.Soundsound(java.lang.String name)Creates a new sound with the given name andSoundDefinition.SoundType.SOUNDas sound type.protected static SoundDefinition.Soundsound(java.lang.String name, SoundDefinition.SoundType type)Creates a new sound with the given name and type.protected static SoundDefinition.Soundsound(ResourceLocation name)Creates a new sound with the given name andSoundDefinition.SoundType.SOUNDas sound type.protected static SoundDefinition.Soundsound(ResourceLocation name, SoundDefinition.SoundType type)Creates a new sound with the given name and type.private voidvalidate()private booleanvalidate(java.lang.String name, SoundDefinition def)private booleanvalidate(java.lang.String name, SoundDefinition.Sound sound)private booleanvalidateEvent(java.lang.String soundName, ResourceLocation name)private booleanvalidateSound(java.lang.String soundName, ResourceLocation name)
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
GSON
private static final com.google.gson.Gson GSON
-
generator
private final DataGenerator generator
-
modId
private final java.lang.String modId
-
helper
private final ExistingFileHelper helper
-
sounds
private final java.util.Map<java.lang.String,SoundDefinition> sounds
-
-
Constructor Detail
-
SoundDefinitionsProvider
protected SoundDefinitionsProvider(DataGenerator generator, java.lang.String modId, ExistingFileHelper helper)
Creates a new instance of this data provider.- Parameters:
generator- The data generator instance provided by the event you are initializing this provider in.modId- The mod ID of the current mod.helper- The existing file helper provided by the event you are initializing this provider in.
-
-
Method Detail
-
registerSounds
public abstract void registerSounds()
Registers the sound definitions that should be generated via one of theaddmethods.
-
run
public void run(DirectoryCache cache) throws java.io.IOException
- Specified by:
runin interfaceIDataProvider- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceIDataProvider
-
definition
protected static SoundDefinition definition()
Creates a newSoundDefinition, which will host a set ofSoundDefinition.Sounds and the necessary parameters.
-
sound
protected static SoundDefinition.Sound sound(ResourceLocation name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.- Parameters:
name- The name of the sound to create.type- The type of sound to create.
-
sound
protected static SoundDefinition.Sound sound(ResourceLocation name)
Creates a new sound with the given name andSoundDefinition.SoundType.SOUNDas sound type.- Parameters:
name- The name of the sound to create.
-
sound
protected static SoundDefinition.Sound sound(java.lang.String name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.- Parameters:
name- The name of the sound to create.type- The type of sound to create.
-
sound
protected static SoundDefinition.Sound sound(java.lang.String name)
Creates a new sound with the given name andSoundDefinition.SoundType.SOUNDas sound type.- Parameters:
name- The name of the sound to create.
-
add
protected void add(java.util.function.Supplier<SoundEvent> soundEvent, SoundDefinition definition)
Adds the entry name associated with the suppliedSoundEventwith the givenSoundDefinitionto the list.This method should be preferred when dealing with a
RegistryObjectorRegistryDelegate.- Parameters:
soundEvent- ASupplierfor the givenSoundEvent.definition- ASoundDefinitionthat defines the given sound.
-
add
protected void add(SoundEvent soundEvent, SoundDefinition definition)
Adds the entry name associated with the givenSoundEventwith theSoundDefinitionto the list.This method should be preferred when a
SoundEventis already available in the method context. If you already have aSupplierfor it, refer toadd(Supplier, SoundDefinition).- Parameters:
soundEvent- ASoundEvent.definition- TheSoundDefinitionthat defines the given event.
-
add
protected void add(ResourceLocation soundEvent, SoundDefinition definition)
- Parameters:
soundEvent- TheResourceLocationthat identifies the event.definition- TheSoundDefinitionthat defines the given event.
-
add
protected void add(java.lang.String soundEvent, SoundDefinition definition)Adds theSoundEventwith the specified name along with itsSoundDefinitionto the list.The given sound event must NOT contain the namespace the name is a part of, since the sound definition specification doesn't allow sounds to be defined outside the namespace they're in. For this reason, any namespace will automatically be stripped from the name.
- Parameters:
soundEvent- The name of theSoundEvent.definition- TheSoundDefinitionthat defines the given event.
-
addSounds
private void addSounds(java.lang.String soundEvent, SoundDefinition definition)
-
validate
private void validate()
-
validate
private boolean validate(java.lang.String name, SoundDefinition def)
-
validate
private boolean validate(java.lang.String name, SoundDefinition.Sound sound)
-
validateSound
private boolean validateSound(java.lang.String soundName, ResourceLocation name)
-
validateEvent
private boolean validateEvent(java.lang.String soundName, ResourceLocation name)
-
save
private void save(DirectoryCache cache, java.nio.file.Path targetFile) throws java.io.IOException
- Throws:
java.io.IOException
-
mapToJson
private com.google.gson.JsonObject mapToJson(java.util.Map<java.lang.String,SoundDefinition> map)
-
-