From d667177d6b08576faf2552a62eb96ba9ffab4fb6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 26 Jul 2017 03:45:22 +0200 Subject: [PATCH] Support 16 sign rotations --- mods/ITEMS/mcl_signs/init.lua | 99 +++++++++++++++--- .../mcl_signs/textures/mcl_signs_sign.png | Bin 0 -> 571 bytes 2 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 mods/ITEMS/mcl_signs/textures/mcl_signs_sign.png diff --git a/mods/ITEMS/mcl_signs/init.lua b/mods/ITEMS/mcl_signs/init.lua index aa660447b..a77a3436f 100644 --- a/mods/ITEMS/mcl_signs/init.lua +++ b/mods/ITEMS/mcl_signs/init.lua @@ -27,6 +27,13 @@ local NUMBER_OF_LINES = 4 local LINE_HEIGHT = 14 local CHAR_WIDTH = 5 + +-- Helper functions +local function round(num, idp) + local mult = 10^(idp or 0) + return math.floor(num * mult + 0.5) / mult +end + local string_to_array = function(str) local tab = {} for i=1,string.len(str) do @@ -122,13 +129,13 @@ local signs = { {delta = {x = -n, y = 0, z = 0}, yaw = math.pi / 2}, } -local m = 1/32 + 1/128 +local m = 1/16 + 1/128 local signs_yard = { - {delta = {x = 0, y = 0, z = -m}, yaw = 0}, - {delta = {x = -m, y = 0, z = 0}, yaw = math.pi / -2}, - {delta = {x = 0, y = 0, z = m}, yaw = math.pi}, - {delta = {x = m, y = 0, z = 0}, yaw = math.pi / 2}, + {delta = {x = 0, y = 5/32, z = -m}, yaw = 0}, + {delta = {x = -m, y = 5/32, z = 0}, yaw = math.pi / -2}, + {delta = {x = 0, y = 5/32, z = m}, yaw = math.pi}, + {delta = {x = m, y = 5/32, z = 0}, yaw = math.pi / 2}, } local sign_groups = {handy=1,axey=1, flammable=1, deco_block=1, material_wood=1, attached_node=1} @@ -165,9 +172,10 @@ local update_sign = function(pos, fields, sender) -- if there is no entity local sign_info - if minetest.get_node(pos).name == "mcl_signs:standing_sign" then + local nn = minetest.get_node(pos).name + if nn == "mcl_signs:standing_sign" or nn == "mcl_signs:standing_sign22_5" or nn == "mcl_signs:standing_sign45" or nn == "mcl_signs:standing_sign67_5" then sign_info = signs_yard[minetest.get_node(pos).param2 + 1] - elseif minetest.get_node(pos).name == "mcl_signs:wall_sign" then + elseif nn == "mcl_signs:wall_sign" then sign_info = signs[minetest.get_node(pos).param2 + 1] end if sign_info == nil then @@ -176,6 +184,14 @@ local update_sign = function(pos, fields, sender) local text_entity = minetest.add_entity({x = pos.x + sign_info.delta.x, y = pos.y + sign_info.delta.y, z = pos.z + sign_info.delta.z}, "mcl_signs:text") + if nn == "mcl_signs:standing_sign22_5" then + sign_info.yaw = sign_info.yaw + math.pi / 8 + elseif nn == "mcl_signs:standing_sign45" then + sign_info.yaw = sign_info.yaw + 2 * (math.pi / 8) + elseif nn == "mcl_signs:standing_sign67_5" then + sign_info.yaw = sign_info.yaw + 3 * (math.pi / 8) + end + text_entity:setyaw(sign_info.yaw) end @@ -254,19 +270,49 @@ minetest.register_node("mcl_signs:wall_sign", { local sign_info local place_pos + -- Ceiling if wdir == 0 then --how would you add sign to ceiling? return itemstack + -- Floor elseif wdir == 1 then + -- Standing sign place_pos = above + + -- Determine the sign rotation based on player's yaw local stand = ItemStack(itemstack) - stand:set_name("mcl_signs:standing_sign") + local yaw = math.pi*2 - placer:get_look_horizontal() + + -- Select one of 16 possible rotations (0-15) + local rotation_level = round((yaw / (math.pi*2)) * 16) + + if rotation_level > 15 then + rotation_level = 0 + elseif rotation_level < 0 then + rotation_level = 15 + end + + -- The actual rotation is a combination of predefined mesh and facedir (see node definition) + if rotation_level % 4 == 0 then + stand:set_name("mcl_signs:standing_sign") + elseif rotation_level % 4 == 1 then + stand:set_name("mcl_signs:standing_sign22_5") + elseif rotation_level % 4 == 2 then + stand:set_name("mcl_signs:standing_sign45") + elseif rotation_level % 4 == 3 then + stand:set_name("mcl_signs:standing_sign67_5") + end + fdir = math.floor(rotation_level / 4) + + -- Place the node! local _, success = minetest.item_place_node(stand, placer, pointed_thing, fdir) if not success then return itemstack end sign_info = signs_yard[fdir + 1] + -- Side else + -- Wall sign place_pos = above local _, success = minetest.item_place_node(itemstack, placer, pointed_thing, wdir) if not success then @@ -300,19 +346,23 @@ minetest.register_node("mcl_signs:wall_sign", { _mcl_blast_resistance = 5, }) -minetest.register_node("mcl_signs:standing_sign", { + +-- Standing sign nodes. +-- 4 rotations at 0°, 22.5°, 45° and 67.5°. +-- These are 4 out of 16 possible rotations. +-- With facedir the remaining 12 rotations are constructed. + +-- 0° +local ssign = { paramtype = "light", sunlight_propagates = true, walkable = false, is_ground_content = false, paramtype2 = "facedir", - drawtype = "nodebox", - node_box = {type = "fixed", fixed = { - {-7/16, -1/16, -1/32, 7/16, 7/16, 1/32}, - {-1/16, -0.5, -1/32, 1/16, -1/16, 1/32}, - }}, + drawtype = "mesh", + mesh = "mcl_signs_sign.obj", selection_box = {type = "fixed", fixed = {-7/16, -0.5, -1/32, 7/16, 7/16, 1/32}}, - tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"}, + tiles = {"mcl_signs_sign.png"}, groups = sign_groups, drop = "mcl_signs:wall_sign", stack_max = 16, @@ -327,7 +377,24 @@ minetest.register_node("mcl_signs:standing_sign", { end, _mcl_hardness = 1, _mcl_blast_resistance = 5, -}) +} + +-- 22.5° +minetest.register_node("mcl_signs:standing_sign", ssign) +local ssign22_5 = table.copy(ssign) +ssign22_5.mesh = "mcl_signs_sign22.5.obj" + +-- 45° +minetest.register_node("mcl_signs:standing_sign22_5", ssign22_5) +local ssign45 = table.copy(ssign) +ssign45.mesh = "mcl_signs_sign45.obj" +minetest.register_node("mcl_signs:standing_sign45", ssign45) + +-- 67.5° +local ssign67 = table.copy(ssign) +ssign67.mesh = "mcl_signs_sign67.5.obj" +minetest.register_node("mcl_signs:standing_sign67_5", ssign67) + minetest.register_entity("mcl_signs:text", { collisionbox = { 0, 0, 0, 0, 0, 0 }, diff --git a/mods/ITEMS/mcl_signs/textures/mcl_signs_sign.png b/mods/ITEMS/mcl_signs/textures/mcl_signs_sign.png new file mode 100644 index 0000000000000000000000000000000000000000..e312cb52c6616382714bf98a0295443a89807d34 GIT binary patch literal 571 zcmeAS@N?(olHy`uVBq!ia0vp^4nVBH!3-p)I`?e@QceLrA+A6=$=f>8&D_t)Gh5{r~^p#atUG0wiBASNw5y z!&0CrVkJR-!3;n-6u|HwC^auS$CiPCagwKtV@L&K$t1>ghYdKKyEkuK>iMqzZoc#E zm&#u~y#%{r8)S|rGBRXyc1&#l6S#2)W6bnC$$6hb^VUD{joBk)UNcGm<)g`8vL1Yp z*G%(bll|-7HC2o4-LLAfi90NM!@quCqx6#L=mVSM62+e^%)73B*mc0I&`_fMZpyKl zGuH0T+f>4~w3SVKVfx!lfim9MmVc+;+jb-|oZ0#Pzz5wW@@d&`Z4Lf#y$m<)cy^P6 z*)W~0EvGKC z9BXZDZuPak@2|el4OwH${A|;M;#XT2@I7XkaF4CP=70PIC-3tN z{0zmB2Nts~F}d9Ig#9yty8J;m^#KtdJIpbJFHutLLhBuCeIo0v)eGHmz zjXe?#p}A`(*o!52`5)hr!I-huj{Vs^-Wq@1MtQGZmsvY)Zr=t*5`(9!pUXO@geCxq CT={$e literal 0 HcmV?d00001