Dynamically add trading tier badge to texture

This commit is contained in:
cora 2022-05-20 00:02:36 +02:00
parent b58422a584
commit 873e018faf
1 changed files with 26 additions and 16 deletions

View File

@ -70,11 +70,11 @@ local tiernames = {
} }
local badges = { local badges = {
"mcl_core:wood", "default_wood.png",
"mcl_core:stone", "default_stone.png",
"mcl_core:goldblock", "default_gold_block.png",
"mcl_core:emeraldblock", "mcl_core_emerald_block.png",
"mcl_core:diamondblock", "default_diamond_block.png",
} }
local professions = { local professions = {
@ -163,7 +163,7 @@ local professions = {
}, },
fletcher = { fletcher = {
name = N("Fletcher"), name = N("Fletcher"),
texture = { textures = {
"mobs_mc_villager_farmer.png", "mobs_mc_villager_farmer.png",
"mobs_mc_villager_farmer.png", "mobs_mc_villager_farmer.png",
}, },
@ -205,7 +205,7 @@ local professions = {
}, },
shepherd ={ shepherd ={
name = N("Shepherd"), name = N("Shepherd"),
texture = { textures = {
"mobs_mc_villager_farmer.png", "mobs_mc_villager_farmer.png",
"mobs_mc_villager_farmer.png", "mobs_mc_villager_farmer.png",
}, },
@ -563,12 +563,18 @@ local function init_trader_vars(self)
end end
end end
local function set_texture(self) local function get_badge_textures(self)
local t = table.copy(professions[self._profession].textures) local t = professions[self._profession].textures
--t[1] = "[combine:<w>x<h>:<x1>,<y1>="..t[1]..":30,50="..badges[self._max_trade_tier].."^[resize:16x16" if self._profession == "unemployed" or self._profession == "nitwit" then return t end
local tier = self._max_trade_tier or 1
return {
self.object:set_properties({textures=t}) "[combine:64x64:0,0="..t[1]..":11,55=".. badges[tier].."\\^[resize\\:2x2",
t[2]
}
end
local function set_textures(self)
self.object:set_properties({textures=get_badge_textures(self)})
end end
local function go_home(entity) local function go_home(entity)
@ -605,7 +611,7 @@ local function employ(self,jobsite_pos)
self._profession=p self._profession=p
m:set_string("villager",self._id) m:set_string("villager",self._id)
self._jobsite = jobsite_pos self._jobsite = jobsite_pos
self.object:set_properties({textures=professions[self._profession].textures}) set_textures(self)
return true return true
end end
end end
@ -1112,6 +1118,10 @@ local trade_inventory = {
-- First-time trade unlock all trades and unlock next trade tier -- First-time trade unlock all trades and unlock next trade tier
if trade.tier + 1 > trader._max_trade_tier then if trade.tier + 1 > trader._max_trade_tier then
trader._max_trade_tier = trader._max_trade_tier + 1 trader._max_trade_tier = trader._max_trade_tier + 1
if trader._max_trade_tier > #professions[trader._profession].trades then
trader._max_trade_tier = #professions[trader._profession].trades
end
set_textures(trader)
update_max_tradenum(trader) update_max_tradenum(trader)
update_formspec = true update_formspec = true
end end
@ -1342,12 +1352,12 @@ mobs:register_mob("mobs_mc:villager", {
on_spawn = function(self) on_spawn = function(self)
if self._id then if self._id then
self.object:set_properties({textures=professions[self._profession].textures}) set_textures(self)
return return
end end
self._id=minetest.sha1(minetest.get_gametime()..minetest.pos_to_string(self.object:get_pos())..tostring(math.random())) self._id=minetest.sha1(minetest.get_gametime()..minetest.pos_to_string(self.object:get_pos())..tostring(math.random()))
self._profession = "unemployed" self._profession = "unemployed"
self.object:set_properties({textures=professions[self._profession].textures}) set_textures(self)
end, end,
on_die = function(self, pos) on_die = function(self, pos)
-- Close open trade formspecs and give input back to players -- Close open trade formspecs and give input back to players