From 578bd700d1ee414a09cfce9c2cd0d9a1d1536d1b Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Fri, 29 Nov 2024 10:11:33 +0100 Subject: [PATCH] read item meta allowing players to edit existing banners --- init.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/init.lua b/init.lua index d2b06a3..553d301 100644 --- a/init.lua +++ b/init.lua @@ -97,6 +97,7 @@ function banners.creation_form_func(state) state.banner:push_transform(banners.base_transform) histories[state.player] = state.banner end + state.banner:read_item(state.player) state.current_color = state.banner.color state:size(20, 10) state:image(3, 0.4, 4, 2, "banner_preview", nil) @@ -233,6 +234,22 @@ function banners.Banner:get_transform_string() return banners.transform_table_to_string(self.transforms) end +function banners.Banner:read_item(player_name) + local player = core.get_player_by_name(player_name) + local item = player:get_wielded_item() + if "banners:" ~= item:get_name():sub(1, 8) then return end + + local parts, mask, texture + local transforms = banners.transform_string_to_table( + item:get_meta():get_string("")) + local total = #transforms + if 0 == total then return end + + local i = 1 + repeat + self:push_transform(transforms[i]) + i = i + 1 + until i > total end -- helper function for determining the flag's direction