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;
|
2021-04-14 23:40:42 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-03-23 17:04:09 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Maps;
|
2020-02-15 01:57:16 +01:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
import com.google.gson.JsonArray;
|
2021-04-14 23:40:42 +02:00
|
|
|
import com.google.gson.JsonElement;
|
2020-02-15 01:57:16 +01:00
|
|
|
import com.google.gson.JsonObject;
|
2021-04-14 23:40:42 +02:00
|
|
|
import com.simibubi.create.foundation.utility.Couple;
|
|
|
|
import com.simibubi.create.foundation.utility.Pair;
|
2020-03-23 17:04:09 +01:00
|
|
|
|
2020-07-19 17:08:20 +02:00
|
|
|
import net.minecraft.data.DataGenerator;
|
2020-02-15 01:57:16 +01:00
|
|
|
import net.minecraft.data.DirectoryCache;
|
|
|
|
import net.minecraft.data.IDataProvider;
|
2021-04-14 23:40:42 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-02-15 01:57:16 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2021-04-14 23:40:42 +02:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2020-02-15 01:57:16 +01:00
|
|
|
import net.minecraft.util.SoundEvent;
|
|
|
|
import net.minecraft.util.SoundEvents;
|
2021-04-14 23:40:42 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-06-26 19:40:10 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3d;
|
2021-04-14 23:40:42 +02:00
|
|
|
import net.minecraft.world.World;
|
2020-02-15 01:57:16 +01:00
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
//@EventBusSubscriber(bus = Bus.FORGE)
|
|
|
|
public class AllSoundEvents {
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static Map<ResourceLocation, SoundEntry> entries = Maps.newHashMap();
|
|
|
|
public static final SoundEntry
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
SCHEMATICANNON_LAUNCH_BLOCK = create("schematicannon_launch_block").subtitle("Schematicannon fires")
|
|
|
|
.playExisting(SoundEvents.ENTITY_GENERIC_EXPLODE, .1f, 1.1f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
SCHEMATICANNON_FINISH = create("schematicannon_finish").subtitle("Schematicannon dings")
|
|
|
|
.playExisting(SoundEvents.BLOCK_NOTE_BLOCK_BELL, 1, .7f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
DEPOT_SLIDE = create("depot_slide").subtitle("Item slides")
|
|
|
|
.playExisting(SoundEvents.BLOCK_SAND_BREAK, .125f, 1.5f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
DEPOT_PLOP = create("depot_plop").subtitle("Item lands")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, .25f, 1.25f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
FUNNEL_FLAP = create("funnel_flap").subtitle("Funnel Flaps")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_FRAME_ROTATE_ITEM, .125f, 1.5f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOOL_BREAK, .0425f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
SLIME_ADDED = create("slime_added").subtitle("Slime squishes")
|
|
|
|
.playExisting(SoundEvents.BLOCK_SLIME_BLOCK_PLACE)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
MECHANICAL_PRESS_ACTIVATION = create("mechanical_press_activation").subtitle("Mechanical Press clangs")
|
2021-04-16 01:13:46 +02:00
|
|
|
.playExisting(SoundEvents.BLOCK_ANVIL_LAND, .125f, 1f)
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_BREAK, .5f, 1f)
|
2021-04-14 23:40:42 +02:00
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
MECHANICAL_PRESS_ACTIVATION_ON_BELT =
|
|
|
|
create("mechanical_press_activation_belt").subtitle("Mechanical Press bonks")
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOOL_HIT, .75f, 1f)
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_BREAK, .15f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-04-20 17:26:46 +02:00
|
|
|
MIXING = create("mixing").subtitle("Mixing Noises")
|
|
|
|
.playExisting(SoundEvents.BLOCK_GILDED_BLACKSTONE_BREAK, .125f, .5f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_NETHERRACK_BREAK, .125f, .5f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
CRANKING = create("cranking").subtitle("Hand Crank turns")
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOOD_PLACE, .075f, .5f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_OFF, .025f, .5f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-05-01 13:19:01 +02:00
|
|
|
WORLDSHAPER_PLACE = create("worldshaper_place").subtitle("Worldshaper zaps")
|
2021-04-14 23:40:42 +02:00
|
|
|
.playExisting(SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
2021-04-28 17:55:05 +02:00
|
|
|
|
2021-04-20 17:26:46 +02:00
|
|
|
SCROLL_VALUE = create("scroll_value").subtitle("Scroll-input clicks")
|
|
|
|
.playExisting(SoundEvents.BLOCK_NOTE_BLOCK_HAT, .124f, 1f)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
2021-04-14 23:40:42 +02:00
|
|
|
|
2021-05-01 13:19:01 +02:00
|
|
|
CONFIRM = create("confirm").subtitle("Affirmative ding")
|
2021-04-14 23:40:42 +02:00
|
|
|
.playExisting(SoundEvents.BLOCK_NOTE_BLOCK_BELL, 0.5f, 0.8f)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
|
|
|
|
2021-05-01 13:19:01 +02:00
|
|
|
DENY = create("deny").subtitle("Declining boop")
|
2021-04-14 23:40:42 +02:00
|
|
|
.playExisting(SoundEvents.BLOCK_NOTE_BLOCK_BASS, 1f, 0.5f)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
COGS = create("cogs").subtitle("Cogwheels rumble")
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-06-26 01:17:35 +02:00
|
|
|
FWOOMP = create("fwoomp").subtitle("Potato Launcher fwoomps")
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
POTATO_HIT = create("potato_hit").subtitle("Vegetable impacts")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_FRAME_BREAK, .75f, .75f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_WEEPING_VINES_BREAK, .75f, 1.25f)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
|
|
|
|
2021-04-28 17:55:05 +02:00
|
|
|
CONTRAPTION_ASSEMBLE = create("contraption_assemble").subtitle("Contraption moves")
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN, .5f, .5f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_CHEST_OPEN, .045f, .74f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
CONTRAPTION_DISASSEMBLE = create("contraption_disassemble").subtitle("Contraption stops")
|
|
|
|
.playExisting(SoundEvents.BLOCK_IRON_TRAPDOOR_CLOSE, .35f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
WRENCH_ROTATE = create("wrench_rotate").subtitle("Wrench used")
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE, .25f, 1.25f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
WRENCH_REMOVE = create("wrench_remove").subtitle("Component breaks")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_PICKUP, .25f, .75f)
|
|
|
|
.playExisting(SoundEvents.BLOCK_NETHERITE_BLOCK_HIT, .25f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2021-05-01 13:19:01 +02:00
|
|
|
|
2021-04-28 17:55:05 +02:00
|
|
|
CRAFTER_CLICK = create("crafter_click").subtitle("Crafter clicks")
|
|
|
|
.playExisting(SoundEvents.BLOCK_NETHERITE_BLOCK_HIT, .25f, 1)
|
|
|
|
.playExisting(SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN, .125f, 1)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2021-05-01 13:19:01 +02:00
|
|
|
|
2021-04-28 17:55:05 +02:00
|
|
|
CRAFTER_CRAFT = create("crafter_craft").subtitle("Crafter crafts")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_BREAK, .125f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-05-04 18:04:00 +02:00
|
|
|
COPPER_ARMOR_EQUIP = create("copper_armor_equip").subtitle("Diving equipment clinks")
|
|
|
|
.playExisting(SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 1f, 1f)
|
|
|
|
.category(SoundCategory.PLAYERS)
|
|
|
|
.build(),
|
2021-05-31 20:48:22 +02:00
|
|
|
|
2021-05-06 16:40:33 +02:00
|
|
|
AUTO_POLISH = create("deployer_polish").subtitle("Deployer applies polish")
|
|
|
|
.playExisting(SoundEvents.UI_STONECUTTER_TAKE_RESULT, 1f, 1f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2021-05-04 18:04:00 +02:00
|
|
|
|
2021-05-31 20:48:22 +02:00
|
|
|
CONTROLLER_CLICK = create("controller_click").subtitle("Controller clicks")
|
|
|
|
.playExisting(SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, .35f, 1f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
SAW_ACTIVATE_WOOD = create("saw_activate_wood").subtitle("Mechanical Saw activates")
|
|
|
|
.playExisting(SoundEvents.ENTITY_BOAT_PADDLE_LAND, .75f, 1.5f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
SAW_ACTIVATE_STONE = create("saw_activate_stone").subtitle("Mechanical Saw activates")
|
|
|
|
.playExisting(SoundEvents.UI_STONECUTTER_TAKE_RESULT, .125f, 1.25f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
|
|
|
SAW_PROCESS = create("saw_process").subtitle("Mechanical Saw processes")
|
|
|
|
.playExisting(SoundEvents.BLOCK_SAND_PLACE, .075f, .75f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
2021-06-26 01:17:35 +02:00
|
|
|
|
2021-05-31 20:48:22 +02:00
|
|
|
SAW_IDLE = create("saw_idle").subtitle("Mechanical Saw turns")
|
|
|
|
.playExisting(SoundEvents.ENTITY_BOAT_PADDLE_LAND)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build(),
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
BLAZE_MUNCH = create("blaze_munch").subtitle("Blaze Burner munches")
|
|
|
|
.playExisting(SoundEvents.ENTITY_GENERIC_EAT, .5f, 1f)
|
|
|
|
.category(SoundCategory.BLOCKS)
|
|
|
|
.build();
|
2020-08-27 02:35:57 +02:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static SoundEntryBuilder create(String id) {
|
|
|
|
return new SoundEntryBuilder(id);
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static void register(RegistryEvent.Register<SoundEvent> event) {
|
|
|
|
IForgeRegistry<SoundEvent> registry = event.getRegistry();
|
|
|
|
for (SoundEntry entry : entries.values())
|
|
|
|
entry.register(registry);
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
2021-05-31 20:48:22 +02:00
|
|
|
|
2021-05-04 18:04:00 +02:00
|
|
|
public static void prepare() {
|
|
|
|
for (SoundEntry entry : entries.values())
|
|
|
|
entry.prepare();
|
|
|
|
}
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static JsonElement provideLangEntries() {
|
|
|
|
JsonObject object = new JsonObject();
|
|
|
|
for (SoundEntry entry : entries.values())
|
|
|
|
object.addProperty(entry.getSubtitleKey(), entry.getSubtitle());
|
|
|
|
return object;
|
|
|
|
}
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static SoundEntryProvider provider(DataGenerator generator) {
|
|
|
|
return new SoundEntryProvider(generator);
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
// @SubscribeEvent
|
|
|
|
// public static void cancelSubtitlesOfCompoundedSounds(PlaySoundEvent event) {
|
|
|
|
// ResourceLocation soundLocation = event.getSound().getSoundLocation();
|
|
|
|
// if (!soundLocation.getNamespace().equals(Create.ID))
|
|
|
|
// return;
|
|
|
|
// if (soundLocation.getPath().contains("_compounded_")
|
|
|
|
// event.setResultSound();
|
2021-06-26 19:40:10 +02:00
|
|
|
//
|
2021-04-14 23:40:42 +02:00
|
|
|
// }
|
|
|
|
|
|
|
|
private static class SoundEntryProvider implements IDataProvider {
|
|
|
|
|
|
|
|
private DataGenerator generator;
|
|
|
|
|
|
|
|
public SoundEntryProvider(DataGenerator generator) {
|
|
|
|
this.generator = generator;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void act(DirectoryCache cache) throws IOException {
|
|
|
|
generate(generator.getOutputFolder(), cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "Create's Custom Sounds";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void generate(Path path, DirectoryCache cache) {
|
|
|
|
Gson GSON = (new GsonBuilder()).setPrettyPrinting()
|
|
|
|
.disableHtmlEscaping()
|
|
|
|
.create();
|
|
|
|
path = path.resolve("assets/create");
|
|
|
|
|
|
|
|
try {
|
|
|
|
JsonObject json = new JsonObject();
|
|
|
|
entries.entrySet()
|
|
|
|
.stream()
|
|
|
|
.sorted(Map.Entry.comparingByKey())
|
|
|
|
.forEach(entry -> {
|
|
|
|
entry.getValue()
|
|
|
|
.write(json);
|
|
|
|
});
|
|
|
|
IDataProvider.save(GSON, cache, json, path.resolve("sounds.json"));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
static class SoundEntryBuilder {
|
|
|
|
|
|
|
|
protected String id;
|
|
|
|
protected String subtitle = "unregistered";
|
|
|
|
protected SoundCategory category = SoundCategory.BLOCKS;
|
|
|
|
List<Pair<SoundEvent, Couple<Float>>> wrappedEvents;
|
|
|
|
|
|
|
|
public SoundEntryBuilder(String id) {
|
|
|
|
wrappedEvents = Lists.newArrayList();
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SoundEntryBuilder subtitle(String subtitle) {
|
|
|
|
this.subtitle = subtitle;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SoundEntryBuilder category(SoundCategory category) {
|
|
|
|
this.category = category;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SoundEntryBuilder playExisting(SoundEvent event, float volume, float pitch) {
|
|
|
|
wrappedEvents.add(Pair.of(event, Couple.create(volume, pitch)));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SoundEntryBuilder playExisting(SoundEvent event) {
|
|
|
|
return playExisting(event, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SoundEntry build() {
|
|
|
|
SoundEntry entry = wrappedEvents.isEmpty() ? new CustomSoundEntry(id, subtitle, category)
|
|
|
|
: new WrappedSoundEntry(id, subtitle, wrappedEvents, category);
|
|
|
|
entries.put(entry.getLocation(), entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2020-07-19 17:08:20 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public static abstract class SoundEntry {
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
protected String id;
|
|
|
|
protected String subtitle;
|
|
|
|
protected SoundCategory category;
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public SoundEntry(String id, String subtitle, SoundCategory category) {
|
|
|
|
this.id = id;
|
|
|
|
this.subtitle = subtitle;
|
|
|
|
this.category = category;
|
|
|
|
}
|
|
|
|
|
2021-05-04 18:04:00 +02:00
|
|
|
public abstract void prepare();
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public abstract void register(IForgeRegistry<SoundEvent> registry);
|
|
|
|
|
|
|
|
public abstract void write(JsonObject json);
|
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
public abstract SoundEvent getMainEvent();
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
public String getSubtitleKey() {
|
|
|
|
return Create.ID + ".subtitle." + id;
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
2021-04-14 23:40:42 +02:00
|
|
|
|
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResourceLocation getLocation() {
|
|
|
|
return Create.asResource(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubtitle() {
|
|
|
|
return subtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playOnServer(World world, BlockPos pos) {
|
|
|
|
playOnServer(world, pos, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playOnServer(World world, BlockPos pos, float volume, float pitch) {
|
|
|
|
play(world, null, pos, volume, pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void play(World world, PlayerEntity entity, BlockPos pos) {
|
|
|
|
play(world, entity, pos, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playFrom(Entity entity) {
|
|
|
|
playFrom(entity, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playFrom(Entity entity, float volume, float pitch) {
|
|
|
|
if (!entity.isSilent())
|
|
|
|
play(entity.world, null, entity.getBlockPos(), volume, pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void play(World world, PlayerEntity entity, BlockPos pos, float volume, float pitch) {
|
|
|
|
play(world, entity, pos.getX(), pos.getY(), pos.getZ(), volume, pitch);
|
|
|
|
}
|
|
|
|
|
2021-06-26 19:40:10 +02:00
|
|
|
public void play(World world, PlayerEntity entity, Vector3d pos, float volume, float pitch) {
|
|
|
|
play(world, entity, pos.getX(), pos.getY(), pos.getZ(), volume, pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch);
|
2021-04-14 23:40:42 +02:00
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
public void playAt(World world, BlockPos pos, float volume, float pitch, boolean fade) {
|
2021-06-26 19:40:10 +02:00
|
|
|
playAt(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, volume, pitch, fade);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playAt(World world, Vector3d pos, float volume, float pitch, boolean fade) {
|
|
|
|
playAt(world, pos.getX(), pos.getY(), pos.getZ(), volume, pitch, fade);
|
2021-04-20 02:19:12 +02:00
|
|
|
}
|
2021-04-20 17:26:46 +02:00
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
public abstract void playAt(World world, double x, double y, double z, float volume, float pitch, boolean fade);
|
|
|
|
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
static class WrappedSoundEntry extends SoundEntry {
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
private List<Pair<SoundEvent, Couple<Float>>> wrappedEvents;
|
|
|
|
private List<Pair<SoundEvent, Couple<Float>>> compiledEvents;
|
|
|
|
|
|
|
|
public WrappedSoundEntry(String id, String subtitle, List<Pair<SoundEvent, Couple<Float>>> wrappedEvents,
|
|
|
|
SoundCategory category) {
|
|
|
|
super(id, subtitle, category);
|
|
|
|
this.wrappedEvents = wrappedEvents;
|
|
|
|
compiledEvents = Lists.newArrayList();
|
|
|
|
}
|
2021-05-31 20:48:22 +02:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
@Override
|
2021-05-04 18:04:00 +02:00
|
|
|
public void prepare() {
|
2021-04-14 23:40:42 +02:00
|
|
|
for (int i = 0; i < wrappedEvents.size(); i++) {
|
|
|
|
ResourceLocation location = Create.asResource(getIdOf(i));
|
|
|
|
SoundEvent sound = new SoundEvent(location).setRegistryName(location);
|
|
|
|
compiledEvents.add(Pair.of(sound, wrappedEvents.get(i)
|
|
|
|
.getSecond()));
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
2021-04-14 23:40:42 +02:00
|
|
|
}
|
2020-02-15 01:57:16 +01:00
|
|
|
|
2021-05-04 18:04:00 +02:00
|
|
|
@Override
|
|
|
|
public void register(IForgeRegistry<SoundEvent> registry) {
|
2021-05-31 20:48:22 +02:00
|
|
|
for (Pair<SoundEvent, Couple<Float>> pair : compiledEvents)
|
2021-05-04 18:04:00 +02:00
|
|
|
registry.register(pair.getFirst());
|
|
|
|
}
|
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
@Override
|
|
|
|
public SoundEvent getMainEvent() {
|
|
|
|
return compiledEvents.get(0)
|
|
|
|
.getFirst();
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
protected String getIdOf(int i) {
|
|
|
|
return i == 0 ? id : id + "_compounded_" + i;
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
@Override
|
|
|
|
public void write(JsonObject json) {
|
|
|
|
for (int i = 0; i < wrappedEvents.size(); i++) {
|
|
|
|
Pair<SoundEvent, Couple<Float>> pair = wrappedEvents.get(i);
|
|
|
|
JsonObject entry = new JsonObject();
|
|
|
|
JsonArray list = new JsonArray();
|
|
|
|
JsonObject s = new JsonObject();
|
|
|
|
s.addProperty("name", pair.getFirst()
|
|
|
|
.getName()
|
|
|
|
.toString());
|
|
|
|
s.addProperty("type", "event");
|
|
|
|
list.add(s);
|
|
|
|
entry.add("sounds", list);
|
|
|
|
if (i == 0)
|
|
|
|
entry.addProperty("subtitle", getSubtitleKey());
|
|
|
|
json.add(getIdOf(i), entry);
|
|
|
|
}
|
|
|
|
}
|
2020-03-28 02:27:43 +01:00
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
@Override
|
2021-06-26 19:40:10 +02:00
|
|
|
public void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) {
|
2021-04-14 23:40:42 +02:00
|
|
|
for (Pair<SoundEvent, Couple<Float>> pair : compiledEvents) {
|
|
|
|
Couple<Float> volPitch = pair.getSecond();
|
|
|
|
world.playSound(entity, x, y, z, pair.getFirst(), category, volPitch.getFirst() * volume,
|
|
|
|
volPitch.getSecond() * pitch);
|
|
|
|
}
|
|
|
|
}
|
2021-04-20 02:19:12 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void playAt(World world, double x, double y, double z, float volume, float pitch, boolean fade) {
|
|
|
|
for (Pair<SoundEvent, Couple<Float>> pair : compiledEvents) {
|
|
|
|
Couple<Float> volPitch = pair.getSecond();
|
|
|
|
world.playSound(x, y, z, pair.getFirst(), category, volPitch.getFirst() * volume,
|
|
|
|
volPitch.getSecond() * pitch, fade);
|
|
|
|
}
|
|
|
|
}
|
2020-03-28 02:27:43 +01:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:40:42 +02:00
|
|
|
static class CustomSoundEntry extends SoundEntry {
|
|
|
|
|
|
|
|
protected SoundEvent event;
|
|
|
|
|
|
|
|
public CustomSoundEntry(String id, String subtitle, SoundCategory category) {
|
|
|
|
super(id, subtitle, category);
|
|
|
|
}
|
2021-05-31 20:48:22 +02:00
|
|
|
|
2021-05-04 18:04:00 +02:00
|
|
|
@Override
|
|
|
|
public void prepare() {
|
|
|
|
ResourceLocation location = getLocation();
|
|
|
|
event = new SoundEvent(location).setRegistryName(location);
|
|
|
|
}
|
2021-04-14 23:40:42 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void register(IForgeRegistry<SoundEvent> registry) {
|
2021-05-04 18:04:00 +02:00
|
|
|
registry.register(event);
|
2021-04-20 02:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SoundEvent getMainEvent() {
|
|
|
|
return event;
|
2021-04-14 23:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(JsonObject json) {
|
|
|
|
JsonObject entry = new JsonObject();
|
|
|
|
JsonArray list = new JsonArray();
|
|
|
|
list.add(getLocation().toString());
|
|
|
|
entry.add("sounds", list);
|
|
|
|
entry.addProperty("subtitle", getSubtitleKey());
|
|
|
|
json.add(id, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-06-26 19:40:10 +02:00
|
|
|
public void play(World world, PlayerEntity entity, double x, double y, double z, float volume, float pitch) {
|
2021-04-14 23:40:42 +02:00
|
|
|
world.playSound(entity, x, y, z, event, category, volume, pitch);
|
|
|
|
}
|
|
|
|
|
2021-04-20 02:19:12 +02:00
|
|
|
@Override
|
|
|
|
public void playAt(World world, double x, double y, double z, float volume, float pitch, boolean fade) {
|
|
|
|
world.playSound(x, y, z, event, category, volume, pitch, fade);
|
|
|
|
}
|
|
|
|
|
2020-03-28 02:27:43 +01:00
|
|
|
}
|
2021-04-14 23:40:42 +02:00
|
|
|
|
2020-02-15 01:57:16 +01:00
|
|
|
}
|