diff --git a/res/content/base/block_materials/glass.json b/res/content/base/block_materials/glass.json new file mode 100644 index 00000000..86693a6e --- /dev/null +++ b/res/content/base/block_materials/glass.json @@ -0,0 +1,5 @@ +{ + "steps-sound": "steps/wood", + "place-sound": "blocks/wood_place", + "break-sound": "blocks/glass_break" +} diff --git a/res/content/base/block_materials/grass.json b/res/content/base/block_materials/grass.json index ed16063e..148c80c0 100644 --- a/res/content/base/block_materials/grass.json +++ b/res/content/base/block_materials/grass.json @@ -1,3 +1,5 @@ { - "steps-sound": "steps/grass" + "steps-sound": "steps/grass", + "place-sound": "steps/grass", + "break-sound": "steps/grass" } diff --git a/res/content/base/block_materials/ground.json b/res/content/base/block_materials/ground.json new file mode 100644 index 00000000..af6eba38 --- /dev/null +++ b/res/content/base/block_materials/ground.json @@ -0,0 +1,5 @@ +{ + "steps-sound": "steps/ground", + "place-sound": "steps/ground_place", + "break-sound": "steps/ground_break" +} diff --git a/res/content/base/block_materials/sand.json b/res/content/base/block_materials/sand.json new file mode 100644 index 00000000..00901142 --- /dev/null +++ b/res/content/base/block_materials/sand.json @@ -0,0 +1,5 @@ +{ + "steps-sound": "steps/sand", + "steps-sound": "blocks/ground_place", + "break-sound": "blocks/ground_break" +} diff --git a/res/content/base/block_materials/stone.json b/res/content/base/block_materials/stone.json index 2d9d5a91..a5b6df37 100644 --- a/res/content/base/block_materials/stone.json +++ b/res/content/base/block_materials/stone.json @@ -1,3 +1,5 @@ { - "steps-sound": "steps/stone" + "steps-sound": "steps/stone", + "place-sound": "blocks/stone_place", + "break-sound": "blocks/stone_break" } diff --git a/res/content/base/block_materials/wood.json b/res/content/base/block_materials/wood.json index 9c6839e2..d29b8a63 100644 --- a/res/content/base/block_materials/wood.json +++ b/res/content/base/block_materials/wood.json @@ -1,3 +1,5 @@ { - "steps-sound": "steps/wood" + "steps-sound": "steps/wood", + "place-sound": "blocks/wood_place", + "break-sound": "blocks/wood_break" } diff --git a/res/content/base/blocks/dirt.json b/res/content/base/blocks/dirt.json index 023bf65f..1495377a 100644 --- a/res/content/base/blocks/dirt.json +++ b/res/content/base/blocks/dirt.json @@ -1,3 +1,4 @@ { - "texture": "dirt" + "texture": "dirt", + "material": "base:ground" } \ No newline at end of file diff --git a/res/content/base/blocks/glass.json b/res/content/base/blocks/glass.json index c56bdd55..902a2cf1 100644 --- a/res/content/base/blocks/glass.json +++ b/res/content/base/blocks/glass.json @@ -1,5 +1,6 @@ { "texture": "glass", + "material": "base:glass", "draw-group": 2, "light-passing": true, "sky-light-passing": true diff --git a/res/content/base/blocks/sand.json b/res/content/base/blocks/sand.json index 46b50319..08a7d4f4 100644 --- a/res/content/base/blocks/sand.json +++ b/res/content/base/blocks/sand.json @@ -1,3 +1,4 @@ { - "texture": "sand" + "texture": "sand", + "material": "base:sand" } \ No newline at end of file diff --git a/res/content/base/sounds/blocks/glass_break.ogg b/res/content/base/sounds/blocks/glass_break.ogg new file mode 100644 index 00000000..1da0b6a4 Binary files /dev/null and b/res/content/base/sounds/blocks/glass_break.ogg differ diff --git a/res/content/base/sounds/blocks/ground_break.ogg b/res/content/base/sounds/blocks/ground_break.ogg new file mode 100644 index 00000000..4a3c1c5e Binary files /dev/null and b/res/content/base/sounds/blocks/ground_break.ogg differ diff --git a/res/content/base/sounds/blocks/ground_place.ogg b/res/content/base/sounds/blocks/ground_place.ogg new file mode 100644 index 00000000..a9cdeccc Binary files /dev/null and b/res/content/base/sounds/blocks/ground_place.ogg differ diff --git a/res/content/base/sounds/blocks/stone_break.ogg b/res/content/base/sounds/blocks/stone_break.ogg new file mode 100644 index 00000000..b54a78a8 Binary files /dev/null and b/res/content/base/sounds/blocks/stone_break.ogg differ diff --git a/res/content/base/sounds/blocks/stone_place.ogg b/res/content/base/sounds/blocks/stone_place.ogg new file mode 100644 index 00000000..12b0a27c Binary files /dev/null and b/res/content/base/sounds/blocks/stone_place.ogg differ diff --git a/res/content/base/sounds/blocks/wood_break.ogg b/res/content/base/sounds/blocks/wood_break.ogg new file mode 100644 index 00000000..d0fa78cc Binary files /dev/null and b/res/content/base/sounds/blocks/wood_break.ogg differ diff --git a/res/content/base/sounds/blocks/wood_place.ogg b/res/content/base/sounds/blocks/wood_place.ogg new file mode 100644 index 00000000..fea80562 Binary files /dev/null and b/res/content/base/sounds/blocks/wood_place.ogg differ diff --git a/src/frontend/LevelFrontend.cpp b/src/frontend/LevelFrontend.cpp index 707699a3..493b4f80 100644 --- a/src/frontend/LevelFrontend.cpp +++ b/src/frontend/LevelFrontend.cpp @@ -23,25 +23,46 @@ LevelFrontend::LevelFrontend(Level* level, Assets* assets) void LevelFrontend::observe(LevelController* controller) { controller->getPlayerController()->listenBlockInteraction( [=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) { - if (type != BlockInteraction::step) { - return; - } auto material = level->content->findBlockMaterial(def->material); if (material == nullptr) { return; } - auto sound = assets->getSound(material->stepsSound); - audio::play( - sound, - glm::vec3(), - true, - 0.333f, - 1.0f, - false, - audio::PRIORITY_LOW, - audio::get_channel_index("regular") - ); + if (type == BlockInteraction::step) { + auto sound = assets->getSound(material->stepsSound); + audio::play( + sound, + glm::vec3(), + true, + 0.333f, + 1.0f + (rand() % 6 - 3) * 0.05f, + false, + audio::PRIORITY_LOW, + audio::get_channel_index("regular") + ); + } else { + audio::Sound* sound = nullptr; + switch (type) { + case BlockInteraction::placing: + sound = assets->getSound(material->placeSound); + break; + case BlockInteraction::destruction: + sound = assets->getSound(material->breakSound); + break; + case BlockInteraction::step: + break; + } + audio::play( + sound, + glm::vec3(pos.x, pos.y, pos.z) + 0.5f, + false, + 1.0f, + 1.0f + (rand() % 6 - 3) * 0.05f, + false, + audio::PRIORITY_NORMAL, + audio::get_channel_index("regular") + ); + } } ); } diff --git a/src/frontend/screens.cpp b/src/frontend/screens.cpp index c127e2a7..468e0ae1 100644 --- a/src/frontend/screens.cpp +++ b/src/frontend/screens.cpp @@ -160,7 +160,7 @@ void LevelScreen::update(float delta) { audio::set_listener( camera->position, player->hitbox->velocity, - camera->position+camera->dir, + camera->dir, camera->up ); diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index adce1ba4..b7cfdffa 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -374,10 +374,6 @@ void PlayerController::updateInteraction(){ uint8_t states = determine_rotation(def, norm, camera->dir); if (lclick && !input.shift && item->rt.funcsset.on_block_break_by) { - onBlockInteraction( - glm::ivec3(x, y, z), def, - BlockInteraction::destruction - ); // TODO: move scripting to interaction callbacks if (scripting::on_item_break_block(player.get(), item, x, y, z)) return; @@ -385,6 +381,10 @@ void PlayerController::updateInteraction(){ Block* target = indices->getBlockDef(vox->id); if (lclick && target->breakable){ + onBlockInteraction( + glm::ivec3(x, y, z), def, + BlockInteraction::destruction + ); blocksController->breakBlock(player.get(), target, x, y, z); } if (rclick && !input.shift) { @@ -421,13 +421,13 @@ void PlayerController::updateInteraction(){ chosenBlock = 0; } if (chosenBlock != vox->id && chosenBlock) { + onBlockInteraction( + glm::ivec3(x, y, z), def, + BlockInteraction::placing + ); chunks->set(x, y, z, chosenBlock, states); lighting->onBlockSet(x,y,z, chosenBlock); if (def->rt.funcsset.onplaced) { - onBlockInteraction( - glm::ivec3(x, y, z), def, - BlockInteraction::placing - ); // TODO: move scripting to interaction callbacks scripting::on_block_placed(player.get(), def, x, y, z); }