2020-02-15 01:57:16 +01:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2020-03-23 17:04:09 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
2020-02-15 01:57:16 +01:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
import com.google.gson.JsonObject;
|
2020-02-15 19:02:35 +01:00
|
|
|
import com.simibubi.create.foundation.utility.Lang;
|
2020-03-23 17:04:09 +01:00
|
|
|
|
2020-02-15 01:57:16 +01:00
|
|
|
import net.minecraft.data.DirectoryCache;
|
|
|
|
import net.minecraft.data.IDataProvider;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.SoundEvent;
|
|
|
|
import net.minecraft.util.SoundEvents;
|
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
|
|
|
2020-03-28 02:27:43 +01:00
|
|
|
public enum AllSoundEvents implements IDataProvider {
|
2020-02-15 01:57:16 +01:00
|
|
|
|
|
|
|
CUCKOO_PIG("creeperclock"),
|
|
|
|
CUCKOO_CREEPER("pigclock"),
|
|
|
|
|
|
|
|
SCHEMATICANNON_LAUNCH_BLOCK(SoundEvents.ENTITY_GENERIC_EXPLODE),
|
|
|
|
SCHEMATICANNON_FINISH(SoundEvents.BLOCK_NOTE_BLOCK_BELL),
|
|
|
|
SLIME_ADDED(SoundEvents.BLOCK_SLIME_BLOCK_PLACE),
|
|
|
|
MECHANICAL_PRESS_ACTIVATION(SoundEvents.BLOCK_ANVIL_LAND),
|
|
|
|
MECHANICAL_PRESS_ITEM_BREAK(SoundEvents.ENTITY_ITEM_BREAK),
|
|
|
|
BLOCKZAPPER_PLACE(SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM),
|
|
|
|
BLOCKZAPPER_CONFIRM(SoundEvents.BLOCK_NOTE_BLOCK_BELL),
|
|
|
|
BLOCKZAPPER_DENY(SoundEvents.BLOCK_NOTE_BLOCK_BASS),
|
|
|
|
BLOCK_FUNNEL_EAT(SoundEvents.ENTITY_GENERIC_EAT),
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
String id;
|
|
|
|
SoundEvent event, child;
|
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
// For adding our own sounds at assets/create/sounds/name.ogg
|
|
|
|
AllSoundEvents() {
|
|
|
|
id = Lang.asId(name());
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
2020-02-15 19:02:35 +01:00
|
|
|
|
|
|
|
AllSoundEvents(String name) {
|
2020-02-15 01:57:16 +01:00
|
|
|
id = name;
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
// For wrapping a existing sound with new subtitle
|
|
|
|
AllSoundEvents(SoundEvent child) {
|
|
|
|
this();
|
2020-02-15 01:57:16 +01:00
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
// subtitles are taken from the lang file (create.subtitle.sound_event_name)
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
public SoundEvent get() {
|
2020-02-15 01:57:16 +01:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2020-03-28 02:27:43 +01:00
|
|
|
private String getEventName() {
|
2020-02-15 01:57:16 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void register(RegistryEvent.Register<SoundEvent> event) {
|
|
|
|
IForgeRegistry<SoundEvent> registry = event.getRegistry();
|
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
for (AllSoundEvents entry : values()) {
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2020-03-28 02:27:43 +01:00
|
|
|
ResourceLocation rec = new ResourceLocation(Create.ID, entry.getEventName());
|
2020-02-15 01:57:16 +01:00
|
|
|
SoundEvent sound = new SoundEvent(rec).setRegistryName(rec);
|
|
|
|
registry.register(sound);
|
|
|
|
entry.event = sound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:02:35 +01:00
|
|
|
public void generate(Path path, DirectoryCache cache) {
|
2020-02-15 01:57:16 +01:00
|
|
|
Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
|
|
|
path = path.resolve("assets/create");
|
|
|
|
|
|
|
|
try {
|
|
|
|
JsonObject json = new JsonObject();
|
2020-02-15 19:02:35 +01:00
|
|
|
for (AllSoundEvents soundEvent : values()) {
|
2020-02-15 01:57:16 +01:00
|
|
|
JsonObject entry = new JsonObject();
|
|
|
|
JsonArray arr = new JsonArray();
|
2020-02-15 19:02:35 +01:00
|
|
|
if (soundEvent.child != null) {
|
|
|
|
// wrapper
|
2020-02-15 01:57:16 +01:00
|
|
|
JsonObject s = new JsonObject();
|
|
|
|
s.addProperty("name", soundEvent.child.getName().toString());
|
|
|
|
s.addProperty("type", "event");
|
|
|
|
arr.add(s);
|
2020-02-15 19:02:35 +01:00
|
|
|
} else {
|
|
|
|
// own sound
|
2020-03-28 02:27:43 +01:00
|
|
|
arr.add(Create.ID + ":" + soundEvent.getEventName());
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
entry.add("sounds", arr);
|
2020-03-28 02:27:43 +01:00
|
|
|
entry.addProperty("subtitle", Create.ID + ".subtitle." + soundEvent.getEventName());
|
|
|
|
json.add(soundEvent.getEventName(), entry);
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
IDataProvider.save(GSON, cache, json, path.resolve("sounds.json"));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-03-28 02:27:43 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void act(DirectoryCache cache) throws IOException {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return null;
|
|
|
|
}
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|