diff --git a/src/main/java/io/github/foundationgames/phonos/block/RadioNoteBlock.java b/src/main/java/io/github/foundationgames/phonos/block/RadioNoteBlock.java index 275084a..a7c92d1 100644 --- a/src/main/java/io/github/foundationgames/phonos/block/RadioNoteBlock.java +++ b/src/main/java/io/github/foundationgames/phonos/block/RadioNoteBlock.java @@ -83,10 +83,10 @@ public void onBlockBreakStart(BlockState state, World world, BlockPos pos, Playe } public boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data) { - int i = state.get(NOTE); - float f = (float)Math.pow(2.0D, (double)(i - 12) / 12.0D); - world.playSound(null, pos, Instrument.fromBlockState(world.getBlockState(pos.down())).getSound(), SoundCategory.RECORDS, 3.0F, f); - world.addParticle(ParticleTypes.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.2D, (double)pos.getZ() + 0.5D, (double)i / 24.0D, 0.0D, 0.0D); + int note = state.get(NOTE); + float pitch = PhonosUtil.pitchFromNote(note); + world.playSound(null, pos, Instrument.fromBlockState(world.getBlockState(pos.down())).getSound(), SoundCategory.RECORDS, 3.0F, pitch); + world.addParticle(ParticleTypes.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.2D, (double)pos.getZ() + 0.5D, (double)note / 24.0D, 0.0D, 0.0D); return true; } diff --git a/src/main/java/io/github/foundationgames/phonos/item/PianoRollItem.java b/src/main/java/io/github/foundationgames/phonos/item/PianoRollItem.java index ce4bed2..277b24a 100644 --- a/src/main/java/io/github/foundationgames/phonos/item/PianoRollItem.java +++ b/src/main/java/io/github/foundationgames/phonos/item/PianoRollItem.java @@ -2,11 +2,18 @@ import io.github.foundationgames.phonos.util.piano.BuiltinPianoRolls; import io.github.foundationgames.phonos.util.piano.PianoRoll; +import net.minecraft.client.item.TooltipContext; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +import java.util.List; public class PianoRollItem extends Item { public PianoRollItem(Settings settings) { @@ -23,6 +30,15 @@ public static PianoRoll getRoll(ItemStack stack) { return PianoRoll.fromNbt(stack.getSubNbt("PianoRoll")); } + public static int getDuration(ItemStack stack) { + var rollNbt = stack.getSubNbt("PianoRoll"); + if (rollNbt != null) { + return rollNbt.getInt("duration"); + } + + return 0; + } + @Override public void appendStacks(ItemGroup group, DefaultedList stacks) { if (group == this.getGroup() || group == ItemGroup.SEARCH) { @@ -31,4 +47,15 @@ public void appendStacks(ItemGroup group, DefaultedList stacks) { stacks.add(chopsticks); } } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + int duration = getDuration(stack); + int sec = (int) Math.floor((double) duration / 20); + int min = (int) Math.floor((double) sec / 60); + sec = sec % 60; + tooltip.add(new TranslatableText("tooltip.phonos.duration", String.format("%02d", min), String.format("%02d", sec)).formatted(Formatting.GRAY)); + + super.appendTooltip(stack, world, tooltip, context); + } } diff --git a/src/main/java/io/github/foundationgames/phonos/util/piano/PianoRoll.java b/src/main/java/io/github/foundationgames/phonos/util/piano/PianoRoll.java index 39aaabb..c3641bb 100644 --- a/src/main/java/io/github/foundationgames/phonos/util/piano/PianoRoll.java +++ b/src/main/java/io/github/foundationgames/phonos/util/piano/PianoRoll.java @@ -24,12 +24,22 @@ public Player createPlayable(Consumer player) { return new Player(new ArrayDeque<>(stages), player); } + public int duration() { + int dur = 0; + for (var stage : this.stages) { + dur += 1 + stage.delay; + } + + return dur; + } + public NbtCompound toNbt() { var nbt = new NbtCompound(); var stageList = new NbtList(); this.stages.forEach(s -> stageList.add(s.toNbt())); nbt.put("stages", stageList); + nbt.putInt("duration", this.duration()); return nbt; } diff --git a/src/main/resources/assets/phonos/lang/en_us.json b/src/main/resources/assets/phonos/lang/en_us.json index 31b3fb9..7184bfd 100644 --- a/src/main/resources/assets/phonos/lang/en_us.json +++ b/src/main/resources/assets/phonos/lang/en_us.json @@ -42,5 +42,6 @@ "message.phonos.mode_0_title": "Apply", "message.phonos.mode_1_title": "Copy", "message.phonos.mode_2_title": "Adjust", + "tooltip.phonos.duration": "Duration: %s:%s", "entity.minecraft.villager.technician": "Technician" } \ No newline at end of file diff --git a/src/main/resources/assets/phonos/textures/gui/gallery/radio_player_piano.png b/src/main/resources/assets/phonos/textures/gui/gallery/radio_player_piano.png new file mode 100644 index 0000000..8986805 Binary files /dev/null and b/src/main/resources/assets/phonos/textures/gui/gallery/radio_player_piano.png differ diff --git a/src/main/resources/assets/phonos/textures/gui/gallery/recorder_finished.png b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_finished.png new file mode 100644 index 0000000..1096476 Binary files /dev/null and b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_finished.png differ diff --git a/src/main/resources/assets/phonos/textures/gui/gallery/recorder_note_blocks.png b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_note_blocks.png new file mode 100644 index 0000000..05b7337 Binary files /dev/null and b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_note_blocks.png differ diff --git a/src/main/resources/assets/phonos/textures/gui/gallery/recorder_powered.png b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_powered.png new file mode 100644 index 0000000..a4cf0ab Binary files /dev/null and b/src/main/resources/assets/phonos/textures/gui/gallery/recorder_powered.png differ diff --git a/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/playing_music.json b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/playing_music.json index 4b48db3..7d844fe 100644 --- a/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/playing_music.json +++ b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/playing_music.json @@ -1,5 +1,5 @@ { - "name": "Playing Music", + "name": "Broadcasting Music", "description": "Broadcasting music from discs or note blocks", "icon": "phonos:radio_jukebox" } \ No newline at end of file diff --git a/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/recording_music.json b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/recording_music.json new file mode 100644 index 0000000..2258073 --- /dev/null +++ b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/categories/recording_music.json @@ -0,0 +1,5 @@ +{ + "name": "Making Music", + "description": "Create your own songs to be played back later", + "icon": "phonos:player_piano" +} \ No newline at end of file diff --git a/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/piano_rolls.json b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/piano_rolls.json new file mode 100644 index 0000000..f01a06a --- /dev/null +++ b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/piano_rolls.json @@ -0,0 +1,34 @@ +{ + "name": "Piano Rolls", + "category": "phonos:recording_music", + "icon": "phonos:piano_roll", + "sortnum": 0, + "pages": [ + { + "type": "spotlight", + "item": "phonos:empty_piano_roll", + "title": "Piano Rolls", + "link_recipe": false, + "text": "To get started recording your own music, craft an Empty Piano Roll and Radio Recorder. Place the roll into the recorder and power it with redstone. Activate a radio note block contraption on the same channel, and un-power the recorder when done to receive your piano roll." + }, + { + "type": "image", + "images": [ + "phonos:textures/gui/gallery/recorder_powered.png", + "phonos:textures/gui/gallery/recorder_note_blocks.png", + "phonos:textures/gui/gallery/recorder_finished.png" + ], + "title": "Gallery", + "border": true, + "text": "The steps to record your own piano roll." + }, + { + "type": "crafting", + "recipe": "phonos:empty_piano_roll" + }, + { + "type": "crafting", + "recipe": "phonos:radio_recorder" + } + ] +} diff --git a/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/player_pianos.json b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/player_pianos.json new file mode 100644 index 0000000..93ed9aa --- /dev/null +++ b/src/main/resources/data/phonos/patchouli_books/phonos_guidebook/en_us/entries/recording_music/player_pianos.json @@ -0,0 +1,32 @@ +{ + "name": "Player Pianos", + "category": "phonos:recording_music", + "icon": "phonos:player_piano", + "sortnum": 1, + "pages": [ + { + "type": "spotlight", + "item": "phonos:player_piano", + "title": "Player Pianos", + "link_recipe": false, + "text": "Once you have created your own song, craft a Player Piano. Your piano roll can be placed into this block, and when powered the piano will play your song. A radio version of this block can be made to broadcast your song to loudspeakers. You can even try to play the piano yourself." + }, + { + "type": "image", + "images": [ + "phonos:textures/gui/gallery/radio_player_piano.png" + ], + "title": "Gallery", + "border": true, + "text": "A Radio Player Piano playing a song." + }, + { + "type": "crafting", + "recipe": "phonos:player_piano" + }, + { + "type": "crafting", + "recipe": "phonos:radio_player_piano" + } + ] +} \ No newline at end of file