diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2021-02-16 17:53:29 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2021-02-16 17:53:29 +0100 |
commit | 151c6935017d34691d37dcb4b6114f7a09c9aa1a (patch) | |
tree | 086ce14e370b01bdf251cd43677152a45d4e7af3 | |
parent | be1d52685cb3f37ac2e61417481465174ba694b9 (diff) | |
download | moretrains-151c6935017d34691d37dcb4b6114f7a09c9aa1a.tar.gz moretrains-151c6935017d34691d37dcb4b6114f7a09c9aa1a.tar.bz2 moretrains-151c6935017d34691d37dcb4b6114f7a09c9aa1a.zip |
Make the gondola wagons change their texture according to their content
-rw-r--r-- | moretrains_gondola/init.lua | 60 | ||||
-rw-r--r-- | moretrains_gondola/textures/moretrains_wagon_gondola_cobble.png | bin | 52107 -> 51732 bytes |
2 files changed, 58 insertions, 2 deletions
diff --git a/moretrains_gondola/init.lua b/moretrains_gondola/init.lua index 91c9522..b5db28e 100644 --- a/moretrains_gondola/init.lua +++ b/moretrains_gondola/init.lua @@ -6,9 +6,58 @@ else end +local function escape_texture(str) + return str:gsub("\\[", "\\["):gsub(":", "\\:"):gsub("[\\^]", "\\^") +end + +local function set_textures(self, data) + local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id}) + if inv then + if inv:is_empty("box") then + self.object:set_properties({ + mesh="moretrains_gondola.b3d", + }) + return + end + local stack = inv:get_stack("box",1) + local name = stack:get_name() + local ndef = minetest.registered_nodes[name] + if ndef then + local dtype = ndef.drawtype + if dtype == "normal" or dtype == "allfaces" or dtype == "allfaces_optional" or dtype == "glasslike" or dtype == "glasslike_framed" or dtype == "glasslike_framed_optional" or dtype == "liquid" then + local texture = ndef.tiles or "default_cobble.png" + if type(texture) == "table" then + texture = texture[1] or "default_cobble.png" + end + self.object:set_properties({ + mesh="moretrains_gondola_mese.b3d", + textures={"[combine:256x256:0,0=moretrains_wagon_gondola_cobble.png:0,109="..escape_texture(texture).."\\^\\[resize\\:16x16"} + }) + end + else + local idef = minetest.registered_items[name] + if idef and idef.groups.advtrains_trackplacer and idef.groups.advtrains_trackplacer > 0 then + self.object:set_properties({ + mesh="moretrains_gondola_rails.b3d", + textures = {"moretrains_wagon_gondola.png"}, + }) + else + self.object:set_properties({ + mesh="moretrains_gondola_toiletpaper.b3d", + textures = {"moretrains_wagon_gondola.png"}, + }) + end + end + end +end + +local function convert(self, dtime, data, train) + data.type = "advtrains:moretrains_wagon_gondola" +end advtrains.register_wagon("moretrains_wagon_gondola", { mesh="moretrains_gondola.b3d", textures = {"moretrains_wagon_gondola.png"}, + set_textures = set_textures, seats = {}, drives_on={default=true}, max_speed=20, @@ -34,6 +83,7 @@ advtrains.register_wagon("moretrains_wagon_gondola_mese", { textures = {"moretrains_wagon_gondola.png"}, seats = {}, drives_on={default=true}, + custom_on_step = convert, max_speed=20, visual_size = {x=1, y=1}, wagon_span=2.784, @@ -51,10 +101,13 @@ advtrains.register_wagon("moretrains_wagon_gondola_mese", { }, }, S("Gondola wagon with mese"), "moretrains_wagon_gondola_mese_inv.png") + + advtrains.register_wagon("moretrains_wagon_gondola_cobble", { mesh="moretrains_gondola_mese.b3d", - textures = {"moretrains_wagon_gondola_cobble.png"}, + textures = {"[combine:256x256:0,0=moretrains_wagon_gondola_cobble.png:0,109=default_obsidian_glass.png\\^\\[resize\\:16x16"}, seats = {}, + custom_on_step = convert, drives_on={default=true}, max_speed=20, visual_size = {x=1, y=1}, @@ -76,6 +129,8 @@ advtrains.register_wagon("moretrains_wagon_gondola_cobble", { advtrains.register_wagon("moretrains_wagon_gondola_toiletpaper", { mesh="moretrains_gondola_toiletpaper.b3d", textures = {"moretrains_wagon_gondola.png"}, + set_textures = set_textures, + custom_on_step = convert, seats = {}, drives_on={default=true}, max_speed=20, @@ -98,6 +153,7 @@ advtrains.register_wagon("moretrains_wagon_gondola_toiletpaper", { advtrains.register_wagon("moretrains_wagon_gondola_rails", { mesh="moretrains_gondola_rails.b3d", textures = {"moretrains_wagon_gondola.png"}, + custom_on_step = convert, seats = {}, drives_on={default=true}, max_speed=20, @@ -151,4 +207,4 @@ minetest.register_craft({ output = "advtrains:moretrains_wagon_gondola_rails", type = "shapeless", recipe = {"advtrains:moretrains_wagon_gondola", "advtrains:dtrack_placer", "advtrains:dtrack_placer"}, -})
\ No newline at end of file +}) diff --git a/moretrains_gondola/textures/moretrains_wagon_gondola_cobble.png b/moretrains_gondola/textures/moretrains_wagon_gondola_cobble.png Binary files differindex 766a27e..882c4b7 100644 --- a/moretrains_gondola/textures/moretrains_wagon_gondola_cobble.png +++ b/moretrains_gondola/textures/moretrains_wagon_gondola_cobble.png |