diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2059d76 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 whosit + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ddd303 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ + +# compass_rose + +A simple 3x3 node that can be used as a compass rose decal placed on top of other nodes. +Auto-rotates to point in the correct direction, most of the times. + +If anyone finds disabled rotation too limiting, ask Alias to fix it. + +## Thank you + +* Simson (Alias' cat) diff --git a/__pycache__/krita_save_cube_sides.cpython-38.pyc b/__pycache__/krita_save_cube_sides.cpython-38.pyc new file mode 100644 index 0000000..c847cc0 Binary files /dev/null and b/__pycache__/krita_save_cube_sides.cpython-38.pyc differ diff --git a/compass_rose.kra b/compass_rose_decal.kra similarity index 63% rename from compass_rose.kra rename to compass_rose_decal.kra index 4152f8a..c50fc68 100644 Binary files a/compass_rose.kra and b/compass_rose_decal.kra differ diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..cd6499f --- /dev/null +++ b/init.lua @@ -0,0 +1,19 @@ +local mod_start_time = core.get_us_time() +core.log("action", "[MOD] compass_rose loading") + +compass_rose_node = {} +compass_rose_node.error = {} +local modpath = core.get_modpath("compass_rose") .. DIR_DELIM + +compass_rose_node.information = {} +compass_rose_node.information.version = "0.1" +compass_rose_node.information.author = "whosit" +compass_rose_node.information.license = "MIT" +compass_rose_node.information.name = "Adds compass rose blocks" +compass_rose_node.information.source = "https://gitea.your-land.de/whosit/compass_rose" +compass_rose_node.information.additional = "Adds a 'compass rose' decal." + +dofile(modpath .. "internal.lua") + +local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000 +core.log("action", "[MOD] compass_rose loaded in [" .. mod_end_time .. "s]") diff --git a/internal.lua b/internal.lua new file mode 100644 index 0000000..ba630bc --- /dev/null +++ b/internal.lua @@ -0,0 +1,66 @@ +local function on_place(itemstack, placer, pointed_thing) + if not minetest.is_player(placer) then + return minetest.item_place(itemstack, placer, pointed_thing) + end + + local look_dir = placer:get_look_dir() + + if not vector.check(look_dir) then + return minetest.item_place(itemstack, placer, pointed_thing) + end + + local facedir = minetest.dir_to_facedir(look_dir) + local aim_dir = pointed_thing.under - pointed_thing.above + + local param2 = 20 + math.random(0, 3) -- random rotation for the "upside-down" position + if aim_dir.y == -1 then + param2 = 0 + elseif aim_dir.x == 1 then + param2 = 16 + elseif aim_dir.x == -1 then + param2 = 12 + elseif aim_dir.z == 1 then + param2 = 8 + elseif aim_dir.z == -1 then + param2 = 4 + end + + return minetest.item_place(itemstack, placer, pointed_thing, param2) +end + + +minetest.register_node(":compass_rose:decal", { + description = "Compass rose decal", + drawtype = "nodebox", + use_texture_alpha = "blend", + tiles = { + "compass_rose_decal.png", + "blank.png", + "blank.png", + "blank.png", + "blank.png", + "blank.png", + }, + + visual_scale = 3.0, + is_ground_content = false, + inventory_image = "compass_rose_decal.png", + wield_image = "compass_rose_decal.png", + paramtype = "light", + paramtype2 = "facedir", + walkable = false, + climbable = false, + sunlight_propagates = true, + node_box = { + type = "fixed", + -- shift tiny bit upwards (0.49) to prevent z-fighting + fixed = {-1.5/3, -0.5/3, -1.5/3, 1.5/3, -0.49/3, 1.5/3} + }, + selection_box = { + type = "fixed", + fixed = {-1.5, -0.45, -1.5, 1.5, -0.5, 1.5} + }, + groups = {choppy = 3, dig_immediate = 2}, + on_place = on_place, + on_rotate = false, -- probably disable rotations + }) diff --git a/krita_save_cube_sides.py b/krita_save_cube_sides.py deleted file mode 100644 index 2d1382f..0000000 --- a/krita_save_cube_sides.py +++ /dev/null @@ -1,35 +0,0 @@ -# crop 3x3 image into 6: corner, center, and 4 directions (only top-left corner is used) - -import os -print(os.getcwd()) - -import krita -currentDocument = Krita.instance().activeDocument() -import os.path -filepath = currentDocument.fileName() -filename = os.path.splitext(os.path.basename(filepath))[0] -dir = os.path.dirname(filepath) - -print(dir) -currentDocument.setBatchmode(True) -s = 16 -corners = [ - [0,0], [s,0], - [0,s], [s, s], [s*2, s], - [s, s*2], - ] -for i,c in enumerate(corners): - clone = currentDocument.clone() - print(c[0], c[1]) - clone.crop(c[0], c[1], s, s) - exportParameters =krita.InfoObject() - exportParameters.setProperty("alpha", True) - exportParameters.setProperty("compression", 6) # 0-9 - exportParameters.setProperty("indexed", False) - res = clone.exportImage(os.path.join(dir, f"{filename}_side{i}.png"), exportParameters) - clone.close() - print(res) - if not res: - break - -currentDocument.setBatchmode(False) \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..b9cda29 --- /dev/null +++ b/mod.conf @@ -0,0 +1,4 @@ +name = compass_rose +description = Adds a compass rose decal. +author = whosit +title = Compass rose decal \ No newline at end of file diff --git a/textures/compass_rose_decal.png b/textures/compass_rose_decal.png new file mode 100644 index 0000000..95b7595 Binary files /dev/null and b/textures/compass_rose_decal.png differ