Skip to content

Commit 61e6e7b

Browse files
committed
Update SoundManager
1 parent 45e83cd commit 61e6e7b

27 files changed

Lines changed: 104 additions & 95 deletions

logics/src/main/java/dev/stashy/extrasounds/logics/Mixers.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ public final class Mixers implements CategoryLoader {
77
@Register(master = true, defaultLevel = 0.33f, preview = ExtraSounds.MODID + ":item.pickup_all")
88
public static SoundSource MASTER;
99

10-
@Register(preview = ExtraSounds.MODID + ":item.pickup_all")
11-
public static SoundSource INVENTORY;
10+
@Register(preview = ExtraSounds.MODID + ":generic.scroll")
11+
public static SoundSource SCREENS;
1212

13-
@Register(preview = ExtraSounds.MODID + ":hotbar_scroll")
13+
@Register(preview = {
14+
ExtraSounds.MODID + ":item.category.gear.generic",
15+
ExtraSounds.MODID + ":item.category.gear.leather",
16+
ExtraSounds.MODID + ":item.category.gear.stone",
17+
ExtraSounds.MODID + ":item.category.gear.iron",
18+
ExtraSounds.MODID + ":item.category.gear.copper",
19+
ExtraSounds.MODID + ":item.category.gear.golden",
20+
ExtraSounds.MODID + ":item.category.gear.diamond",
21+
ExtraSounds.MODID + ":item.category.gear.netherite"
22+
})
1423
public static SoundSource HOTBAR;
1524

1625
@Register(preview = ExtraSounds.MODID + ":chat.message")

logics/src/main/java/dev/stashy/extrasounds/logics/SoundManager.java

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.minecraft.world.item.Items;
2424
import org.apache.logging.log4j.LogManager;
2525
import org.apache.logging.log4j.Logger;
26+
import org.jetbrains.annotations.Nullable;
2627

2728
import java.util.HashSet;
2829
import java.util.Objects;
@@ -108,7 +109,7 @@ public void handleInventorySlot(Player player, InventoryClickState state) {
108109
switch (actionType) {
109110
case PICKUP_ALL -> {
110111
if (hasCursor) {
111-
this.playSound(Sounds.ITEM_PICK_ALL, SoundType.PICKUP);
112+
this.playSound2D(Sounds.ITEM_PICK_ALL, SoundType.GRAB);
112113
}
113114
}
114115
case THROW -> {
@@ -132,9 +133,9 @@ public void handleInventorySlot(Player player, InventoryClickState state) {
132133
* --> PICKUP
133134
*/
134135
if (!hasSlot || hasCursor && ExtraSounds.MAIN.canItemsCombine(slotStack, cursorStack)) {
135-
this.playSound(cursorStack.getItem(), SoundType.PLACE);
136+
this.playSound2D(cursorStack.getItem(), SoundType.PLACE);
136137
} else {
137-
this.playSound(slotStack.getItem(), SoundType.PICKUP);
138+
this.playSound2D(slotStack.getItem(), SoundType.GRAB);
138139
}
139140
}
140141
}
@@ -153,27 +154,27 @@ public void hotbar(int i) {
153154

154155
ItemStack stack = player.getInventory().getItem(i);
155156
if (stack.isEmpty()) {
156-
this.playSound(Sounds.HOTBAR_SCROLL, SoundType.HOTBAR);
157+
this.playSound2D(Sounds.HOTBAR_SCROLL, SoundType.HOTBAR);
157158
} else {
158-
this.playSound(stack.getItem(), SoundType.HOTBAR);
159+
this.playSound2D(stack.getItem(), SoundType.HOTBAR);
159160
}
160161
}
161162

162163
public void blockInteract(VersionedSoundEventWrapper snd, BlockPos position) {
163164
SoundType blockIntr = SoundType.BLOCK_INTR;
164-
this.playSound(snd, blockIntr, 1f, blockIntr.pitch, position);
165+
this.playSound(snd, blockIntr.category, 1f, blockIntr.pitch, position);
165166
}
166167

167168
public void blockInteract(Item item, BlockPos position) {
168-
this.blockInteract(this.getSoundByItem(item, SoundType.PICKUP), position);
169+
this.blockInteract(this.getSoundByItem(item, SoundType.DEFAULT), position);
169170
}
170171

171-
public void playSound(VersionedSoundEventWrapper snd, SoundType type) {
172-
this.playSound(snd, type.pitch, type.category);
172+
public void playSound2D(VersionedSoundEventWrapper snd, SoundType type) {
173+
this.playSound2D(snd, type.category, type.pitch);
173174
}
174175

175-
public void playSound(Item item, SoundType type) {
176-
this.playSound(this.getSoundByItem(item, type), type.pitch, type.category);
176+
public void playSound2D(Item item, SoundType type) {
177+
this.playSound2D(this.getSoundByItem(item, type), type.category, type.pitch);
177178
}
178179

179180
/**
@@ -189,45 +190,47 @@ private void handleQuickMoveSound(Item item) {
189190
}
190191
long now = System.currentTimeMillis();
191192
if (now - this.lastPlayed > 10 || item != this.quickMovingItem) {
192-
this.playSound(item, SoundType.PICKUP);
193+
this.playSound2D(item, SoundType.GRAB);
193194
this.lastPlayed = now;
194195
this.quickMovingItem = item;
195196
}
196197
}
197198

198-
public void playSound(VersionedSoundEventWrapper snd, float pitch, SoundSource category, SoundSource... optionalVolumes) {
199-
float volume = ExtraSounds.MAIN.getSoundVolume(Mixers.MASTER);
199+
public void playSound2D(VersionedSoundEventWrapper snd, SoundSource category) {
200+
this.playSound2D(snd, category, 1);
201+
}
202+
203+
public void playSound2D(VersionedSoundEventWrapper snd, SoundSource category, float pitch, SoundSource... optionalVolumes) {
204+
float volume = 1;
200205
if (optionalVolumes != null) {
201206
for (SoundSource cat : optionalVolumes) {
202207
volume = Math.min(ExtraSounds.MAIN.getSoundVolume(cat), volume);
203208
}
204209
}
205-
if (volume == 0 || this.isMuted(category)) {
206-
// skip reflection when volume is zero.
207-
if (DebugUtils.DEBUG) {
208-
this.logZeroVolume(snd);
209-
}
210-
return;
211-
}
212-
final var soundInstance = VersionedPositionedSoundInstanceWrapper.newInstance(
213-
snd.getId(), category, volume, pitch, false, 0, SoundInstance.Attenuation.NONE,
214-
0.0D, 0.0D, 0.0D, true
215-
);
216-
this.playSound(Objects.requireNonNull(soundInstance));
210+
this.playSound(snd, category, volume, pitch, null);
217211
}
218212

219-
public void playSound(VersionedSoundEventWrapper snd, SoundType type, float volume, float pitch, BlockPos position) {
213+
public void playSound(VersionedSoundEventWrapper snd, SoundSource category, float volume, float pitch, @Nullable BlockPos position) {
220214
volume *= ExtraSounds.MAIN.getSoundVolume(Mixers.MASTER);
221-
if (volume == 0 || this.isMuted(type.category)) {
215+
if (volume == 0 || this.isMuted(category)) {
222216
// skip reflection when volume is zero.
223217
if (DebugUtils.DEBUG) {
224218
this.logZeroVolume(snd);
225219
}
226220
return;
227221
}
228-
final var soundInstance = VersionedPositionedSoundInstanceWrapper.newInstance(
229-
snd, type.category, volume, pitch, position
230-
);
222+
final VersionedPositionedSoundInstanceWrapper soundInstance;
223+
if (position == null) {
224+
soundInstance = VersionedPositionedSoundInstanceWrapper.newInstance(
225+
snd.getId(), category, volume, pitch, false, 0, SoundInstance.Attenuation.NONE,
226+
0.0D, 0.0D, 0.0D, true
227+
);
228+
} else {
229+
soundInstance = VersionedPositionedSoundInstanceWrapper.newInstance(
230+
snd.getId(), category, volume, pitch, false, 0, SoundInstance.Attenuation.LINEAR,
231+
position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, false
232+
);
233+
}
231234
this.playSound(Objects.requireNonNull(soundInstance));
232235
}
233236

@@ -263,7 +266,7 @@ private void playSound(SoundInstance instance) {
263266
}
264267

265268
public void playThrow(ItemStack itemStack) {
266-
this.playThrow(itemStack, Mixers.INVENTORY);
269+
this.playThrow(itemStack, Mixers.SCREENS);
267270
}
268271

269272
/**
@@ -284,7 +287,7 @@ public void playThrow(ItemStack itemStack, SoundSource category) {
284287
final float maxPitch = 2f;
285288
final float pitch = (!itemStack.isStackable()) ? maxPitch :
286289
Mth.lerp((itemStack.getCount() - 1f) / (itemStack.getItem().getDefaultMaxStackSize() - 1f), maxPitch, 1.5f);
287-
this.playSound(Sounds.ITEM_DROP, pitch, category, Mixers.ITEM_DROP);
290+
this.playSound2D(Sounds.ITEM_DROP, category, pitch, Mixers.ITEM_DROP);
288291
}
289292

290293
public void stopSound(VersionedSoundEventWrapper e, SoundType type) {

logics/src/main/java/dev/stashy/extrasounds/logics/entry/SoundPackLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ private static void processSounds(Map<String, SoundGenerator> soundGenerator, Ma
183183
definition = SoundDefinition.of(fallbackSoundEntry);
184184
}
185185

186-
final Identifier pickupClickId = ExtraSounds.getClickId(itemId, SoundType.PICKUP);
187-
final SoundDefinition filled = definition.fill(Sounds.aliased(ExtraSounds.createEvent(pickupClickId)));
188-
generateSoundEntry(pickupClickId, filled.pickup, resource);
186+
final Identifier grabId = ExtraSounds.getClickId(itemId, SoundType.GRAB);
187+
final SoundDefinition filled = definition.fill(Sounds.aliased(ExtraSounds.createEvent(grabId)));
188+
generateSoundEntry(grabId, filled.pickup, resource);
189189
generateSoundEntry(ExtraSounds.getClickId(itemId, SoundType.PLACE), filled.place, resource);
190190
generateSoundEntry(ExtraSounds.getClickId(itemId, SoundType.HOTBAR), filled.hotbar, resource);
191191

192192
if (DebugUtils.SEARCH_UNDEF_SOUND) {
193193
final boolean isFallbackSoundEntry = Objects.equals(GSON.toJson(definition.pickup), fallbackSoundJson);
194-
final boolean notIncludeSoundsJson = !inSoundsJsonIds.contains(pickupClickId.getPath());
194+
final boolean notIncludeSoundsJson = !inSoundsJsonIds.contains(grabId.getPath());
195195
if (isFallbackSoundEntry && notIncludeSoundsJson) {
196196
LOGGER.warn("unregistered sound was found: '{}'", itemId);
197197
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/AbstractCreativeInventoryHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ public void onClick(Player player, @Nullable Slot slot, int slotId, int button,
4848
// With holding the Shift key; (slotActionType == QUICK_MOVE)
4949
if (bOnCreativeTab && bOnHotbar && slot.hasItem()) {
5050
// Quick move from Hotbar to Creative slots; stack will be deleted.
51-
ExtraSounds.MANAGER.playSound(Sounds.ITEM_DELETE_PARTIAL, SoundType.PICKUP);
51+
ExtraSounds.MANAGER.playSound2D(Sounds.ITEM_DELETE_PARTIAL, SoundType.DEFAULT);
5252
return;
5353
}
5454
if (bMatchDeleteSlot) {
5555
// Shift + Click on deleteItemSlot; clearing Inventory.
56-
ExtraSounds.MANAGER.playSound(Sounds.ITEM_DELETE_ALL, SoundType.PICKUP);
56+
ExtraSounds.MANAGER.playSound2D(Sounds.ITEM_DELETE_ALL, SoundType.DEFAULT);
5757
return;
5858
}
5959
}
6060

6161
if (!state.cursorStack.isEmpty()) {
6262
if (bMatchDeleteSlot) {
6363
// Clicked deleteItemSlot.
64-
ExtraSounds.MANAGER.playSound(Sounds.ITEM_DELETE_PARTIAL, SoundType.PICKUP);
64+
ExtraSounds.MANAGER.playSound2D(Sounds.ITEM_DELETE_PARTIAL, SoundType.DEFAULT);
6565
return;
6666
}
6767

@@ -74,11 +74,11 @@ public void onClick(Player player, @Nullable Slot slot, int slotId, int button,
7474
if (bOnCreativeTab && !bOnHotbar) {
7575
if (ExtraSounds.MAIN.canItemsCombine(state.getSlotStack(), state.cursorStack) && !state.isRMB) {
7676
// Left Mouse Clicked on the same slot in CreativeInventory tab except Hotbar.
77-
ExtraSounds.MANAGER.playSound(state.cursorStack.getItem(), SoundType.PICKUP);
77+
ExtraSounds.MANAGER.playSound2D(state.cursorStack.getItem(), SoundType.DEFAULT);
7878
return;
7979
} else if (slotId >= 0) {
8080
// Clicking on another slot will delete or decrement the cursor stack.
81-
ExtraSounds.MANAGER.playSound(Sounds.ITEM_DELETE_PARTIAL, SoundType.PICKUP);
81+
ExtraSounds.MANAGER.playSound2D(Sounds.ITEM_DELETE_PARTIAL, SoundType.DEFAULT);
8282
return;
8383
}
8484
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/ChatSoundHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public void onMessage(Player player, String text) {
2121
}
2222

2323
if (containsPlName && !ExtraSounds.MANAGER.isMuted(SoundType.CHAT_MENTION)) {
24-
ExtraSounds.MANAGER.playSound(Sounds.CHAT_MENTION, SoundType.CHAT_MENTION);
24+
ExtraSounds.MANAGER.playSound2D(Sounds.CHAT_MENTION, SoundType.CHAT_MENTION);
2525
} else if (!containsScreenshot || ExtraSounds.MANAGER.isMuted(SoundType.SCREENSHOT)) {
26-
ExtraSounds.MANAGER.playSound(Sounds.CHAT, SoundType.CHAT);
26+
ExtraSounds.MANAGER.playSound2D(Sounds.CHAT, SoundType.CHAT);
2727
}
2828
}
2929

3030
public void onScroll(int line) {
3131
if (line != this.currentLines) {
32-
ExtraSounds.MANAGER.playSound(Sounds.INVENTORY_SCROLL, SoundType.CHAT);
32+
ExtraSounds.MANAGER.playSound2D(Sounds.INVENTORY_SCROLL, SoundType.CHAT);
3333
this.currentLines = line;
3434
}
3535
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/EntitySoundHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ public void onEffectChanged(MobEffect effect, EffectType type) {
4242
return;
4343
}
4444

45-
ExtraSounds.MANAGER.playSound(sound, SoundType.EFFECTS);
45+
ExtraSounds.MANAGER.playSound2D(sound, SoundType.EFFECTS);
4646
}
4747

4848
public void onDeath(Entity entity, BlockPos blockPos) {
4949
final float flu = (float) ((Math.random() - 0.5f) * 0.333333f);
5050
final float pitch = flu + (float) Mth.clampedLerp(Math.sqrt(entity.getBbHeight() * entity.getBbWidth()) * 0.4f, 2f, 0.65f);
51-
ExtraSounds.MANAGER.playSound(Sounds.Entities.POOF, SoundType.ENTITY, .7f, pitch, blockPos);
51+
ExtraSounds.MANAGER.playSound(Sounds.Entities.POOF, SoundType.ENTITY.category, .7f, pitch, blockPos);
5252
}
5353

5454
public void onItemUse(Item item) {
5555
if (item == Items.AIR) {
5656
return;
5757
}
5858

59-
ExtraSounds.MANAGER.playSound(ExtraSounds.MANAGER.getSoundByItem(item, SoundType.PICKUP), SoundType.ENTITY);
59+
ExtraSounds.MANAGER.playSound2D(ExtraSounds.MANAGER.getSoundByItem(item, SoundType.DEFAULT), SoundType.ENTITY);
6060
}
6161
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/ScreenScrollHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ public void onScroll(int row) {
3838
final long now = System.currentTimeMillis();
3939
final long timeDiff = now - this.lastScrollTime;
4040
if (timeDiff > 20 && this.lastScrollPos != row) {
41-
ExtraSounds.MANAGER.playSound(
41+
ExtraSounds.MANAGER.playSound2D(
4242
Sounds.INVENTORY_SCROLL,
43-
(1f - 0.1f + 0.1f * Math.min(1, 50f / timeDiff)),
44-
Mixers.INVENTORY);
43+
Mixers.SCREENS,
44+
(1f - 0.1f + 0.1f * Math.min(1, 50f / timeDiff))
45+
);
4546
this.lastScrollTime = now;
4647
this.lastScrollPos = row;
4748
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/TextFieldHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public void onKey(KeyType type) {
9191
}
9292

9393
switch (type) {
94-
case ERASE -> ExtraSounds.MANAGER.playSound(Sounds.KEYBOARD_ERASE, SoundType.TYPING);
95-
case CUT -> ExtraSounds.MANAGER.playSound(Sounds.KEYBOARD_CUT, SoundType.TYPING);
96-
case CURSOR, RETURN -> ExtraSounds.MANAGER.playSound(Sounds.KEYBOARD_MOVE, SoundType.TYPING);
97-
case INSERT -> ExtraSounds.MANAGER.playSound(Sounds.KEYBOARD_TYPE, SoundType.TYPING);
98-
case PASTE -> ExtraSounds.MANAGER.playSound(Sounds.KEYBOARD_PASTE, SoundType.TYPING);
94+
case ERASE -> ExtraSounds.MANAGER.playSound2D(Sounds.KEYBOARD_ERASE, SoundType.TYPING);
95+
case CUT -> ExtraSounds.MANAGER.playSound2D(Sounds.KEYBOARD_CUT, SoundType.TYPING);
96+
case CURSOR, RETURN -> ExtraSounds.MANAGER.playSound2D(Sounds.KEYBOARD_MOVE, SoundType.TYPING);
97+
case INSERT -> ExtraSounds.MANAGER.playSound2D(Sounds.KEYBOARD_TYPE, SoundType.TYPING);
98+
case PASTE -> ExtraSounds.MANAGER.playSound2D(Sounds.KEYBOARD_PASTE, SoundType.TYPING);
9999
}
100100
}
101101
}

logics/src/main/java/dev/stashy/extrasounds/logics/impl/VersionedHotbarSoundHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static VersionedHotbarSoundHandler newInstance() {
3333

3434
public void onSwap(Item mainHand, Item offHand) {
3535
if (offHand != ITEM_EMPTY) {
36-
ExtraSounds.MANAGER.playSound(offHand, SoundType.PICKUP);
36+
ExtraSounds.MANAGER.playSound2D(offHand, SoundType.HOTBAR);
3737
} else if (mainHand != ITEM_EMPTY) {
38-
ExtraSounds.MANAGER.playSound(mainHand, SoundType.PICKUP);
38+
ExtraSounds.MANAGER.playSound2D(mainHand, SoundType.HOTBAR);
3939
}
4040
}
4141

@@ -59,7 +59,7 @@ public void onChange(int newSlot) {
5959
}
6060

6161
public void spectatorHotbar() {
62-
ExtraSounds.MANAGER.playSound(Sounds.HOTBAR_SCROLL, SoundType.HOTBAR);
62+
ExtraSounds.MANAGER.playSound2D(Sounds.HOTBAR_SCROLL, SoundType.HOTBAR);
6363
}
6464

6565
public void doItemPick(Item item) {
@@ -79,7 +79,7 @@ public void onItemPick() {
7979

8080
final Item item = this.popPickingItem();
8181
if (!player.getMainHandItem().is(item) && item != ITEM_EMPTY) {
82-
ExtraSounds.MANAGER.playSound(item, SoundType.HOTBAR);
82+
ExtraSounds.MANAGER.playSound2D(item, SoundType.HOTBAR);
8383
}
8484
}
8585

logics/src/main/java/dev/stashy/extrasounds/logics/mixin/action/item/LocalPlayerMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public LocalPlayerMixin(ClientLevel level, GameProfile gameProfile) {
3030
return;
3131
}
3232

33-
ExtraSounds.MANAGER.playSound(Sounds.Actions.BOW_PULL, SoundType.ITEM_INTR);
33+
ExtraSounds.MANAGER.playSound2D(Sounds.Actions.BOW_PULL, SoundType.ITEM_INTR);
3434
}
3535

3636
@Inject(method = "stopUsingItem", at = @At(value = "HEAD"))

0 commit comments

Comments
 (0)