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.json
file, which identifies sound definitions for the various sound events in Minecraft.
-
-
Field Summary
Fields Modifier and Type Field Description private DataGenerator
generator
private static com.google.gson.Gson
GSON
private ExistingFileHelper
helper
private static org.apache.logging.log4j.Logger
LOGGER
private java.lang.String
modId
private java.util.Map<java.lang.String,SoundDefinition>
sounds
-
Fields inherited from interface net.minecraft.data.IDataProvider
SHA1
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SoundDefinitionsProvider(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 void
add(java.lang.String soundEvent, SoundDefinition definition)
Adds theSoundEvent
with the specified name along with itsSoundDefinition
to the list.protected void
add(java.util.function.Supplier<SoundEvent> soundEvent, SoundDefinition definition)
Adds the entry name associated with the suppliedSoundEvent
with the givenSoundDefinition
to the list.protected void
add(ResourceLocation soundEvent, SoundDefinition definition)
protected void
add(SoundEvent soundEvent, SoundDefinition definition)
Adds the entry name associated with the givenSoundEvent
with theSoundDefinition
to the list.private void
addSounds(java.lang.String soundEvent, SoundDefinition definition)
protected static SoundDefinition
definition()
Creates a newSoundDefinition
, which will host a set ofSoundDefinition.Sound
s and the necessary parameters.java.lang.String
getName()
private com.google.gson.JsonObject
mapToJson(java.util.Map<java.lang.String,SoundDefinition> map)
abstract void
registerSounds()
Registers the sound definitions that should be generated via one of theadd
methods.void
run(DirectoryCache cache)
private void
save(DirectoryCache cache, java.nio.file.Path targetFile)
protected static SoundDefinition.Sound
sound(java.lang.String name)
Creates a new sound with the given name andSoundDefinition.SoundType.SOUND
as sound type.protected static SoundDefinition.Sound
sound(java.lang.String name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.protected static SoundDefinition.Sound
sound(ResourceLocation name)
Creates a new sound with the given name andSoundDefinition.SoundType.SOUND
as sound type.protected static SoundDefinition.Sound
sound(ResourceLocation name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.private void
validate()
private boolean
validate(java.lang.String name, SoundDefinition def)
private boolean
validate(java.lang.String name, SoundDefinition.Sound sound)
private boolean
validateEvent(java.lang.String soundName, ResourceLocation name)
private boolean
validateSound(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 theadd
methods.
-
run
public void run(DirectoryCache cache) throws java.io.IOException
- Specified by:
run
in interfaceIDataProvider
- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceIDataProvider
-
definition
protected static SoundDefinition definition()
Creates a newSoundDefinition
, which will host a set ofSoundDefinition.Sound
s 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.SOUND
as 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.SOUND
as 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 suppliedSoundEvent
with the givenSoundDefinition
to the list.This method should be preferred when dealing with a
RegistryObject
orRegistryDelegate
.- Parameters:
soundEvent
- ASupplier
for the givenSoundEvent
.definition
- ASoundDefinition
that defines the given sound.
-
add
protected void add(SoundEvent soundEvent, SoundDefinition definition)
Adds the entry name associated with the givenSoundEvent
with theSoundDefinition
to the list.This method should be preferred when a
SoundEvent
is already available in the method context. If you already have aSupplier
for it, refer toadd(Supplier, SoundDefinition)
.- Parameters:
soundEvent
- ASoundEvent
.definition
- TheSoundDefinition
that defines the given event.
-
add
protected void add(ResourceLocation soundEvent, SoundDefinition definition)
- Parameters:
soundEvent
- TheResourceLocation
that identifies the event.definition
- TheSoundDefinition
that defines the given event.
-
add
protected void add(java.lang.String soundEvent, SoundDefinition definition)
Adds theSoundEvent
with the specified name along with itsSoundDefinition
to 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
- TheSoundDefinition
that 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)
-
-