Added a mod that plays placement sounds place-sounds_v1.0.0

Wed, 02 Jul 2025 23:53:32 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 02 Jul 2025 23:53:32 +0300
changeset 12
2e09a72b2dfa
parent 11
da16c5a08162
child 13
826df96c3720

Added a mod that plays placement sounds

place-sounds/control.lua file | annotate | diff | comparison | revisions
place-sounds/data-final-fixes.lua file | annotate | diff | comparison | revisions
place-sounds/info.json file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/place-sounds/control.lua	Wed Jul 02 23:53:32 2025 +0300
@@ -0,0 +1,43 @@
+script.on_event(defines.events.on_built_entity, function(event)
+	local sound_path = "entity-close/"..event.entity.name
+	if helpers.is_valid_sound_path(sound_path)
+	then
+		event.entity.surface.play_sound{
+			path=sound_path,
+			position=game.players[event.player_index].position,
+		}
+	end
+end)
+
+script.on_event(defines.events.on_robot_built_entity, function(event)
+	local sound_path = "entity-close/"..event.entity.name
+	if helpers.is_valid_sound_path(sound_path)
+	then
+		event.entity.surface.play_sound{
+			path=sound_path,
+			position=event.entity.position,
+		}
+	end
+end)
+
+script.on_event(defines.events.on_player_mined_entity, function(event)
+	local sound_path = "entity-open/"..event.entity.name
+	if helpers.is_valid_sound_path(sound_path)
+	then
+		event.entity.surface.play_sound{
+			path=sound_path,
+			position=game.players[event.player_index].position,
+		}
+	end
+end)
+
+script.on_event(defines.events.on_robot_mined_entity, function(event)
+	local sound_path = "entity-open/"..event.entity.name
+	if helpers.is_valid_sound_path(sound_path)
+	then
+		event.entity.surface.play_sound{
+			path=sound_path,
+			position=event.entity.position,
+		}
+	end
+end)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/place-sounds/data-final-fixes.lua	Wed Jul 02 23:53:32 2025 +0300
@@ -0,0 +1,18 @@
+---@class entity EntityPrototype
+---@class item ItemPrototype
+local function copy_item_sounds_to_entity(item, entity)
+    entity.open_sound = table.deepcopy(item.pick_sound)
+    entity.close_sound = table.deepcopy(item.drop_sound)
+end
+
+-- prevent metallic machine sounds when placing power poles
+local sounds = require("__base__.prototypes.entity.sounds")
+for _, electric_pole in pairs(data.raw["electric-pole"])
+do
+    electric_pole.open_sound = sounds.electric_large_open
+    electric_pole.close_sound = sounds.electric_large_close
+end
+
+-- prevent metallic machine sounds when placing stuff made of bricks
+copy_item_sounds_to_entity(data.raw.item["stone-furnace"], data.raw.furnace["stone-furnace"])
+copy_item_sounds_to_entity(data.raw.item["stone-wall"], data.raw.wall["stone-wall"])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/place-sounds/info.json	Wed Jul 02 23:53:32 2025 +0300
@@ -0,0 +1,9 @@
+{
+	"author": "teemu",
+	"dependencies": ["base"],
+	"description": "Building and mining structures plays their open and closed sounds.",
+	"factorio_version": "2.0",
+	"name": "place-sounds",
+	"title": "Play sounds when placed",
+	"version": "1.0.0"
+}
\ No newline at end of file

mercurial