diff --git a/init.lua b/init.lua index 145d915..415224d 100644 --- a/init.lua +++ b/init.lua @@ -367,12 +367,12 @@ function airutils.set_paint(self, puncher, itmstck, texture_name) local color, indx, _ if split[1] then _,indx = split[1]:find('dye') end if indx then - for clr,_ in pairs(airutils.colors) do + --[[for clr,_ in pairs(airutils.colors) do local _,x = split[2]:find(clr) if x then color = clr end - end + end]]-- --lets paint!!!! - --local color = item_name:sub(indx+1) + local color = (item_name:sub(indx+1)):gsub(":", "") local colstr = airutils.colors[color] --minetest.chat_send_all(color ..' '.. dump(colstr)) if colstr then @@ -406,22 +406,6 @@ function airutils.paint(self, colstr, texture_name) end end -function airutils.paint_with_mask(self, colstr, target_texture, mask_texture) - if colstr then - self._color = colstr - self._det_color = mask_colstr - local l_textures = self.initial_properties.textures - for _, texture in ipairs(l_textures) do - local indx = texture:find(target_texture) - if indx then - --"("..target_texture.."^[mask:"..mask_texture..")" - l_textures[_] = "("..target_texture.."^[multiply:".. colstr..")^("..target_texture.."^[mask:"..mask_texture..")" - end - end - self.object:set_properties({textures=l_textures}) - end -end - function airutils.getAngleFromPositions(origin, destiny) local angle_north = math.deg(math.atan2(destiny.x - origin.x, destiny.z - origin.z)) if angle_north < 0 then angle_north = angle_north + 360 end diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index f94dd0f..6f43056 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -1,7 +1,7 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua") function lib_change_color(self, colstr) - airutils.paint(self, colstr, self._painting_texture) + airutils.param_paint(self, colstr) end function airutils.get_staticdata(self) -- unloaded/unloads ... is now saved @@ -47,10 +47,11 @@ function airutils.on_activate(self, staticdata, dtime_s) self._register_parts_method(self) end - airutils.paint(self, self._color, self._painting_texture) - if self._alternate_painting_texture and self._mask_painting_texture then + airutils.param_paint(self, self._color) + --TODO + --[[if self._alternate_painting_texture and self._mask_painting_texture then airutils.paint_with_mask(self, self._color, self._alternate_painting_texture, self._mask_painting_texture) - end + end]]-- self.object:set_armor_groups({immortal=1}) @@ -457,7 +458,7 @@ function airutils.logic(self) end function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) - if not puncher or not puncher:is_player() then + if not puncher or not puncher:is_player() then return end @@ -491,14 +492,14 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) --repair if (item_name == "airutils:repair_tool") and self._engine_running == false then - if self.hp_max < 50 then + if self.hp_max < self._max_plane_hp then local inventory_item = "default:steel_ingot" local inv = puncher:get_inventory() if inv:contains_item("main", inventory_item) then local stack = ItemStack(inventory_item .. " 1") inv:remove_item("main", stack) self.hp_max = self.hp_max + 10 - if self.hp_max > 50 then self.hp_max = 50 end + if self.hp_max > self._max_plane_hp then self.hp_max = self._max_plane_hp end airutils.setText(self, self.infotext) else minetest.chat_send_player(puncher:get_player_name(), "You need steel ingots in your inventory to perform this repair.") @@ -509,8 +510,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) -- deal with painting or destroying if itmstck then - - if airutils.set_paint(self, puncher, itmstck, self._painting_texture) == false then + if airutils.set_param_paint(self, puncher, itmstck) == false then if not self.driver and toolcaps and toolcaps.damage_groups and toolcaps.damage_groups.fleshy and item_name ~= airutils.fuel then --airutils.hurt(self,toolcaps.damage_groups.fleshy - 1) diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index d027d8b..7fd4295 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -329,4 +329,98 @@ function airutils.engine_set_sound_and_animation(self) end end +function airutils.add_paintable_part(self, entity_ref) + if not self._paintable_parts then self._paintable_parts = {} end + table.insert(self._paintable_parts, entity_ref:get_luaentity()) +end + +function airutils.set_param_paint(self, puncher, itmstck) + local item_name = "" + if itmstck then item_name = itmstck:get_name() end + + if item_name == "automobiles_lib:painter" or item_name == "bike:painter" then + --painting with bike painter + local meta = itmstck:get_meta() + local colstr = meta:get_string("paint_color") + airutils.param_paint(self, colstr) + return true + else + --painting with dyes + local split = string.split(item_name, ":") + local color, indx, _ + if split[1] then _,indx = split[1]:find('dye') end + if indx then + --[[for clr,_ in pairs(airutils.colors) do + local _,x = split[2]:find(clr) + if x then color = clr end + end]]-- + --lets paint!!!! + local color = (item_name:sub(indx+1)):gsub(":", "") + local colstr = airutils.colors[color] + --minetest.chat_send_all(color ..' '.. dump(colstr)) + --minetest.chat_send_all(dump(airutils.colors)) + if colstr then + airutils.param_paint(self, colstr) + itmstck:set_count(itmstck:get_count()-1) + if puncher ~= nil then puncher:set_wielded_item(itmstck) end + return true + end + -- end painting + end + end + return false +end + +local function _paint(self, l_textures, colstr, paint_list, mask_associations) + paint_list = paint_list or self._painting_texture + mask_associations = mask_associations or self._mask_painting_associations + for _, texture in ipairs(l_textures) do + for i, texture_name in ipairs(paint_list) do --textures list + local indx = texture:find(texture_name) + if indx then + l_textures[_] = texture_name.."^[multiply:".. colstr --paint it normally + local mask_texture = mask_associations[texture_name] --check if it demands a maks too + if mask_texture then --so it then + l_textures[_] = "("..l_textures[_]..")^("..texture_name.."^[mask:"..mask_texture..")" --add the mask + end + end + end + end + return l_textures +end + +--painting +function airutils.param_paint(self, colstr) + if not self then return end + if colstr then + self._color = colstr + local l_textures = self.initial_properties.textures + l_textures = _paint(self, l_textures, colstr) --paint the main plane + self.object:set_properties({textures=l_textures}) + + if self._paintable_parts then --paint individual parts + for i, part_entity in ipairs(self._paintable_parts) do + local p_textures = part_entity.initial_properties.textures + p_textures = _paint(part_entity, p_textures, colstr, self._painting_texture, self._mask_painting_associations) + part_entity.object:set_properties({textures=p_textures}) + end + end + end +end + +function airutils.paint_with_mask(self, colstr, target_texture, mask_texture) + if colstr then + self._color = colstr + self._det_color = mask_colstr + local l_textures = self.initial_properties.textures + for _, texture in ipairs(l_textures) do + local indx = texture:find(target_texture) + if indx then + --"("..target_texture.."^[mask:"..mask_texture..")" + l_textures[_] = "("..target_texture.."^[multiply:".. colstr..")^("..target_texture.."^[mask:"..mask_texture..")" + end + end + self.object:set_properties({textures=l_textures}) + end +end