fixes + more materials

This commit is contained in:
MihailRis 2024-03-09 04:04:53 +03:00
parent f4cc413f61
commit 3ee350fc0c
19 changed files with 73 additions and 28 deletions

View File

@ -0,0 +1,5 @@
{
"steps-sound": "steps/wood",
"place-sound": "blocks/wood_place",
"break-sound": "blocks/glass_break"
}

View File

@ -1,3 +1,5 @@
{ {
"steps-sound": "steps/grass" "steps-sound": "steps/grass",
"place-sound": "steps/grass",
"break-sound": "steps/grass"
} }

View File

@ -0,0 +1,5 @@
{
"steps-sound": "steps/ground",
"place-sound": "steps/ground_place",
"break-sound": "steps/ground_break"
}

View File

@ -0,0 +1,5 @@
{
"steps-sound": "steps/sand",
"steps-sound": "blocks/ground_place",
"break-sound": "blocks/ground_break"
}

View File

@ -1,3 +1,5 @@
{ {
"steps-sound": "steps/stone" "steps-sound": "steps/stone",
"place-sound": "blocks/stone_place",
"break-sound": "blocks/stone_break"
} }

View File

@ -1,3 +1,5 @@
{ {
"steps-sound": "steps/wood" "steps-sound": "steps/wood",
"place-sound": "blocks/wood_place",
"break-sound": "blocks/wood_break"
} }

View File

@ -1,3 +1,4 @@
{ {
"texture": "dirt" "texture": "dirt",
"material": "base:ground"
} }

View File

@ -1,5 +1,6 @@
{ {
"texture": "glass", "texture": "glass",
"material": "base:glass",
"draw-group": 2, "draw-group": 2,
"light-passing": true, "light-passing": true,
"sky-light-passing": true "sky-light-passing": true

View File

@ -1,3 +1,4 @@
{ {
"texture": "sand" "texture": "sand",
"material": "base:sand"
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -23,25 +23,46 @@ LevelFrontend::LevelFrontend(Level* level, Assets* assets)
void LevelFrontend::observe(LevelController* controller) { void LevelFrontend::observe(LevelController* controller) {
controller->getPlayerController()->listenBlockInteraction( controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) { [=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
if (type != BlockInteraction::step) {
return;
}
auto material = level->content->findBlockMaterial(def->material); auto material = level->content->findBlockMaterial(def->material);
if (material == nullptr) { if (material == nullptr) {
return; return;
} }
auto sound = assets->getSound(material->stepsSound); if (type == BlockInteraction::step) {
audio::play( auto sound = assets->getSound(material->stepsSound);
sound, audio::play(
glm::vec3(), sound,
true, glm::vec3(),
0.333f, true,
1.0f, 0.333f,
false, 1.0f + (rand() % 6 - 3) * 0.05f,
audio::PRIORITY_LOW, false,
audio::get_channel_index("regular") 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")
);
}
} }
); );
} }

View File

@ -160,7 +160,7 @@ void LevelScreen::update(float delta) {
audio::set_listener( audio::set_listener(
camera->position, camera->position,
player->hitbox->velocity, player->hitbox->velocity,
camera->position+camera->dir, camera->dir,
camera->up camera->up
); );

View File

@ -374,10 +374,6 @@ void PlayerController::updateInteraction(){
uint8_t states = determine_rotation(def, norm, camera->dir); uint8_t states = determine_rotation(def, norm, camera->dir);
if (lclick && !input.shift && item->rt.funcsset.on_block_break_by) { 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 // TODO: move scripting to interaction callbacks
if (scripting::on_item_break_block(player.get(), item, x, y, z)) if (scripting::on_item_break_block(player.get(), item, x, y, z))
return; return;
@ -385,6 +381,10 @@ void PlayerController::updateInteraction(){
Block* target = indices->getBlockDef(vox->id); Block* target = indices->getBlockDef(vox->id);
if (lclick && target->breakable){ if (lclick && target->breakable){
onBlockInteraction(
glm::ivec3(x, y, z), def,
BlockInteraction::destruction
);
blocksController->breakBlock(player.get(), target, x, y, z); blocksController->breakBlock(player.get(), target, x, y, z);
} }
if (rclick && !input.shift) { if (rclick && !input.shift) {
@ -421,13 +421,13 @@ void PlayerController::updateInteraction(){
chosenBlock = 0; chosenBlock = 0;
} }
if (chosenBlock != vox->id && chosenBlock) { if (chosenBlock != vox->id && chosenBlock) {
onBlockInteraction(
glm::ivec3(x, y, z), def,
BlockInteraction::placing
);
chunks->set(x, y, z, chosenBlock, states); chunks->set(x, y, z, chosenBlock, states);
lighting->onBlockSet(x,y,z, chosenBlock); lighting->onBlockSet(x,y,z, chosenBlock);
if (def->rt.funcsset.onplaced) { if (def->rt.funcsset.onplaced) {
onBlockInteraction(
glm::ivec3(x, y, z), def,
BlockInteraction::placing
);
// TODO: move scripting to interaction callbacks // TODO: move scripting to interaction callbacks
scripting::on_block_placed(player.get(), def, x, y, z); scripting::on_block_placed(player.get(), def, x, y, z);
} }