-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update icon.png to the old one
- Loading branch information
Showing
8 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 39 additions & 1 deletion
40
src/main/java/mc/duzo/timeless/datagen/TimelessDataGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,49 @@ | ||
package mc.duzo.timeless.datagen; | ||
|
||
import mc.duzo.timeless.datagen.provider.lang.LanguageProvider; | ||
import mc.duzo.timeless.datagen.provider.lang.LanguageType; | ||
import mc.duzo.timeless.datagen.provider.sound.BasicSoundProvider; | ||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | ||
|
||
public class TimelessDataGenerator implements DataGeneratorEntrypoint { | ||
@Override | ||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { | ||
public void onInitializeDataGenerator(FabricDataGenerator gen) { | ||
FabricDataGenerator.Pack pack = gen.createPack(); | ||
|
||
genLang(pack); | ||
genSounds(pack); | ||
} | ||
|
||
private void genLang(FabricDataGenerator.Pack pack) { | ||
genEnglish(pack); | ||
} | ||
|
||
private void genEnglish(FabricDataGenerator.Pack pack) { | ||
pack.addProvider((((output, registriesFuture) -> { | ||
LanguageProvider provider = new LanguageProvider(output, LanguageType.EN_US); | ||
|
||
return provider; | ||
}))); | ||
} | ||
|
||
private void genSounds(FabricDataGenerator.Pack pack) { | ||
pack.addProvider((((output, registriesFuture) -> { | ||
BasicSoundProvider provider = new BasicSoundProvider(output); | ||
|
||
|
||
|
||
return provider; | ||
}))); | ||
} | ||
|
||
private static String convertToName(String str) { | ||
String[] split = str.split("_"); | ||
|
||
for (int i = 0; i < split.length; i++) { | ||
split[i] = split[i].substring(0, 1).toUpperCase() + split[i].substring(1).toLowerCase(); | ||
} | ||
|
||
return String.join(" ", split); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/mc/duzo/timeless/datagen/provider/lang/LanguageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package mc.duzo.timeless.datagen.provider.lang; | ||
|
||
import mc.duzo.timeless.Timeless; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.Item; | ||
|
||
import java.util.HashMap; | ||
|
||
public class LanguageProvider extends FabricLanguageProvider { | ||
|
||
public HashMap<String, String> translations = new HashMap<>(); | ||
|
||
public LanguageType languageType; | ||
private final FabricDataOutput dataGenerator; | ||
|
||
public LanguageProvider(FabricDataOutput dataOutput, LanguageType languageType) { | ||
super(dataOutput, languageType.name().toLowerCase()); | ||
this.languageType = languageType; | ||
this.dataGenerator = dataOutput; | ||
} | ||
|
||
@Override | ||
public void generateTranslations(TranslationBuilder translationBuilder) { | ||
for (String key : translations.keySet()) { | ||
translationBuilder.add(key, translations.get(key)); | ||
} | ||
|
||
dataGenerator.getModContainer().findPath("assets/" + Timeless.MOD_ID + "/lang/" + languageType.name().toLowerCase() + ".existing.json").ifPresent(existingFilePath -> { | ||
try { | ||
translationBuilder.add(existingFilePath); | ||
} catch (Exception e) { | ||
LOGGER.warn("Failed to add existing language file! " + "(" + languageType.name().toLowerCase() + ") | ", e); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Adds a translation to the language file. | ||
* | ||
* @param item The item to add the translation for. | ||
* @param translation The translation. | ||
*/ | ||
public void addTranslation(Item item, String translation) { | ||
translations.put(item.getTranslationKey(), translation); | ||
} | ||
|
||
/** | ||
* Adds a translation to the language file. | ||
* | ||
* @param key The key to add the translation for. | ||
* @param translation The translation. | ||
*/ | ||
public void addTranslation(String key, String translation) { | ||
translations.put(key, translation); | ||
} | ||
|
||
/** | ||
* Adds a translation to the language file | ||
* | ||
* @param block The block to add the translation for | ||
* @param translation The translation | ||
*/ | ||
public void addTranslation(Block block, String translation) { | ||
translations.put(block.getTranslationKey(), translation); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/mc/duzo/timeless/datagen/provider/lang/LanguageType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mc.duzo.timeless.datagen.provider.lang; | ||
|
||
|
||
public enum LanguageType { | ||
EN_US, | ||
EN_UK, | ||
FR_CA, | ||
FR_FR, | ||
ES_AR, | ||
ES_CL, | ||
ES_EC, | ||
ES_ES, | ||
ES_MX, | ||
ES_UY, | ||
ES_VE, | ||
EN_AU, | ||
EN_CA, | ||
EN_GB, | ||
EN_NZ, | ||
DE_AT, | ||
DE_CH, | ||
DE_DE, | ||
NDS_DE, | ||
PT_BR, | ||
RU_RU, | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/mc/duzo/timeless/datagen/provider/lang/Translatable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mc.duzo.timeless.datagen.provider.lang; | ||
|
||
public interface Translatable { | ||
String getTranslationKey(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/mc/duzo/timeless/datagen/provider/sound/BasicSoundProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mc.duzo.timeless.datagen.provider.sound; | ||
|
||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
import net.minecraft.sound.SoundEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class BasicSoundProvider extends SoundProvider { | ||
private final FabricDataOutput dataGenerator; | ||
|
||
private final HashMap<String, SoundEvent[]> soundEventList = new HashMap<>(); | ||
|
||
public BasicSoundProvider(FabricDataOutput dataOutput) { | ||
super(dataOutput); | ||
this.dataGenerator = dataOutput; | ||
} | ||
|
||
@Override | ||
public void generateSoundsData(SoundBuilder builder) { | ||
soundEventList.forEach(builder::add); | ||
} | ||
|
||
public void addSound(String soundName, SoundEvent sound) { | ||
soundEventList.put(soundName, new SoundEvent[]{sound}); | ||
} | ||
|
||
public void addSound(String soundName, SoundEvent[] soundEvents) { | ||
soundEventList.put(soundName, soundEvents); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/mc/duzo/timeless/datagen/provider/sound/SoundBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mc.duzo.timeless.datagen.provider.sound; | ||
|
||
import net.minecraft.sound.SoundEvent; | ||
|
||
@FunctionalInterface | ||
public interface SoundBuilder { | ||
void add(String soundName, SoundEvent[] soundEvents); | ||
|
||
default void add(String soundName, SoundEvent soundEvent) { | ||
add(soundName, new SoundEvent[]{soundEvent}); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/mc/duzo/timeless/datagen/provider/sound/SoundProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package mc.duzo.timeless.datagen.provider.sound; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
import net.minecraft.data.DataOutput; | ||
import net.minecraft.data.DataProvider; | ||
import net.minecraft.data.DataWriter; | ||
import net.minecraft.sound.SoundEvent; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public abstract class SoundProvider implements DataProvider { | ||
protected final FabricDataOutput dataOutput; | ||
|
||
protected SoundProvider(FabricDataOutput dataOutput) { | ||
this.dataOutput = dataOutput; | ||
} | ||
|
||
public abstract void generateSoundsData(SoundBuilder customSoundBuilder); | ||
|
||
@Override | ||
public CompletableFuture<?> run(DataWriter writer) { | ||
HashMap<String, SoundEvent[]> soundEventsHashMap = new HashMap<>(); | ||
|
||
generateSoundsData(((soundName, soundEvents) -> { | ||
if (soundEventsHashMap.containsKey(soundName)) { | ||
throw new RuntimeException("Duplicate sound event: " + soundName + " - Duplicate will be ignored!"); | ||
} else if (soundName.contains(" ")) { | ||
throw new RuntimeException("Sound event name cannot contain spaces: " + soundName); | ||
} else { | ||
for (Character character : soundName.toCharArray()) { | ||
if (Character.isTitleCase(character)) { | ||
throw new RuntimeException("Sound event name cannot contain capital letters: " + soundName); | ||
} else if (Character.isUpperCase(character)) { | ||
throw new RuntimeException("Sound event name cannot contain capital letters: " + soundName); | ||
} | ||
} | ||
soundEventsHashMap.put(soundName, soundEvents); | ||
} | ||
})); | ||
JsonObject soundJsonObject = new JsonObject(); | ||
|
||
soundEventsHashMap.forEach((soundName, soundEvents) -> { | ||
soundJsonObject.add(soundName, createJsonObjectForSoundEvent(soundEvents)); | ||
}); | ||
|
||
|
||
return DataProvider.writeToPath(writer, soundJsonObject, getOutputPath()); | ||
} | ||
|
||
public Path getOutputPath() { | ||
return dataOutput.resolvePath(DataOutput.OutputType.RESOURCE_PACK).resolve(dataOutput.getModId()).resolve("sounds.json"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Sound Definitions"; | ||
} | ||
|
||
public JsonObject createJsonObjectForSoundEvent(SoundEvent[] soundEvents) { | ||
JsonObject soundEventJsonObject = new JsonObject(); | ||
JsonArray soundsJsonObject = new JsonArray(); | ||
|
||
for (SoundEvent soundEvent : soundEvents) { | ||
soundsJsonObject.add(soundEvent.getId().toString()); | ||
} | ||
|
||
soundEventJsonObject.add("sounds", soundsJsonObject); | ||
return soundEventJsonObject; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.