Skip to content

Commit

Permalink
Add guidebook entries, tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Apr 1, 2022
1 parent 8735c40 commit 598a8ab
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<ItemStack> stacks) {
if (group == this.getGroup() || group == ItemGroup.SEARCH) {
Expand All @@ -31,4 +47,15 @@ public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
stacks.add(chopsticks);
}
}

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ public Player createPlayable(Consumer<Float> 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;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/phonos/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Playing Music",
"name": "Broadcasting Music",
"description": "Broadcasting music from discs or note blocks",
"icon": "phonos:radio_jukebox"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Making Music",
"description": "Create your own songs to be played back later",
"icon": "phonos:player_piano"
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit 598a8ab

Please sign in to comment.