Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fix: adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
RitikShah committed Oct 9, 2024
1 parent a470751 commit 8f6fa02
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Auto detect text files and perform LF normalization
* text=auto
*.bolt linguist-language=mcfunction
2 changes: 1 addition & 1 deletion beet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data_pack:
name: nbs-smithed-summit-24
description: "Data pack for NBS on the Smithed Summit 2024"
load:
- "data/nbs/module": src
- data/nbs/module: src

resource_pack:
name: nbs-smithed-summit-24
Expand Down
8 changes: 4 additions & 4 deletions src/generate_songs.bolt
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ for song_stuff in enumerate(SONGS.glob("*.nbs")):
notes = song[1]
function f"nbs:{song_name}":
execute store result storage nbs:main songindex int 1 run scoreboard players get songindex nbs
function ~/chord/tick:
function f"nbs:{song_name}/chord/{tick}":
for note in notes:
instruments.add(note.instrument)
note.play_speakers()
note.play_loudspeakers()
note.play_headphones()
note.play_speakers(ctx)
note.play_loudspeakers(ctx)
note.play_headphones(ctx)

for instrument in instruments:
sound_path = EXTRA_NOTES.get(instrument)
Expand Down
44 changes: 34 additions & 10 deletions src/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from typing import Any, Iterator, List, Tuple

import pynbs
from beet import Context
from beet.core.utils import FileSystemPath
from bolt import Runtime
from mecha import Mecha

NBS_DEFAULT_INSTRUMENTS = [
"block.note_block.harp",
Expand Down Expand Up @@ -61,7 +64,7 @@ class Note:
pitch: float = 1
panning: float = 0

def play_speakers(self, stereo_separation: float = 4):
def play_speakers(self, ctx: Context, stereo_separation: float = 4):
"""
Play a sound that can be heard in a small radius by all players in range.
"""
Expand Down Expand Up @@ -101,11 +104,11 @@ def rolloff_curve(x: float) -> float:
stereo_offset = self.panning * stereo_separation // 2
position = f"^{stereo_offset} ^ ^"

return self.play(
execute_as="@e[tag=nbs_speaker]", radius=radius, position=position
self.play(
ctx, execute_as="@e[tag=nbs_speaker]", radius=radius, position=position
)

def play_loudspeakers(self, stereo_separation: float = 8):
def play_loudspeakers(self, ctx: Context, stereo_separation: float = 8):
"""
Play a sound that can be heard in a large radius by all players in range.
"""
Expand Down Expand Up @@ -133,15 +136,16 @@ def play_loudspeakers(self, stereo_separation: float = 8):
stereo_offset = self.panning * stereo_separation // 2
position = f"^{stereo_offset} ^ ^"

return self.play(
self.play(
ctx,
execute_as="@e[tag=nbs_loudspeaker]",
radius=radius,
volume=volume,
min_volume=min_volume,
position=position,
)

def play_headphones(self):
def play_headphones(self, ctx: Context):
"""
Play a sound that can be globally heard by players with headphones.
"""
Expand All @@ -156,7 +160,8 @@ def play_headphones(self):
tag = "nbs_headphones"
position = f"0 64 {-self.panning * 256}"

return self.play(
self.play(
ctx,
min_volume=min_volume,
volume=volume,
tag=tag,
Expand All @@ -165,14 +170,15 @@ def play_headphones(self):

def play(
self,
ctx: Context,
execute_as: str | None = None,
radius: float | None = None,
tag: str | None = None,
source: str = "record",
position: str = "^ ^ ^",
volume: float = 1,
min_volume: float = 1,
) -> str:
):
"""Return the /playsound command to play the note for the given player."""

selector_arguments = []
Expand All @@ -186,10 +192,28 @@ def play(
if execute_as is not None:
execute_command = f"execute as {execute_as} at @n run"

playsound_command = f"playsound {self.instrument} {source} {target_selector} {position} {volume} {self.pitch} {min_volume}"
if self.pitch > 2:
# print("Warning pitch", self.pitch, "is larger than 2", source)
pitch = 2
else:
pitch = self.pitch

if min_volume > 1:
# print("Warning min_volume", min_volume, "is larger than 1", target_selector)
min_volume = 1

playsound_command = f"playsound {self.instrument} {source} {target_selector} {position} {volume} {pitch} {min_volume}"

full_command = " ".join([execute_command, playsound_command])
return full_command

mc = ctx.inject(Mecha)
runtime = ctx.inject(Runtime)

try:
runtime.commands.append(mc.parse(full_command, using="command"))
except Exception as e:
print(full_command)
raise e


def load_nbs(filename: FileSystemPath) -> Iterator[Tuple[int, List["Note"]]]:
Expand Down

0 comments on commit 8f6fa02

Please sign in to comment.