From bf60a423419cf9a28d4728c53f662ff2ed2e15ba Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 11 Feb 2017 04:26:00 +0100 Subject: [PATCH] Different pillar rotation algorithm, fixes pillar shading issues --- mods/mcl_end/depends.txt | 1 + mods/mcl_end/init.lua | 4 +- mods/mcl_util/description.txt | 1 + mods/mcl_util/init.lua | 90 +++++++++++++++++++++++++++++++++++ mods/mcl_util/mod.conf | 1 + 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 mods/mcl_util/description.txt create mode 100644 mods/mcl_util/init.lua create mode 100644 mods/mcl_util/mod.conf diff --git a/mods/mcl_end/depends.txt b/mods/mcl_end/depends.txt index e0f1bd69d..0fa73873d 100644 --- a/mods/mcl_end/depends.txt +++ b/mods/mcl_end/depends.txt @@ -1,2 +1,3 @@ mcl_core mcl_throwing +mcl_util diff --git a/mods/mcl_end/init.lua b/mods/mcl_end/init.lua index 5c6de3797..06e36e6ea 100644 --- a/mods/mcl_end/init.lua +++ b/mods/mcl_end/init.lua @@ -30,7 +30,9 @@ minetest.register_node("mcl_end:purpur_pillar", { stack_max = 64, paramtype2 = "facedir", is_ground_content = false, - on_place = minetest.rotate_node, + on_place = function(itemstack, player, pointed_thing) + mcl_util.axis_place(itemstack, player, pointed_thing, minetest.setting_getbool("creative_mode"), player:get_player_control().sneak) + end, tiles = {"mcl_end_purpur_pillar_top.png", "mcl_end_purpur_pillar_top.png", "mcl_end_purpur_pillar.png"}, groups = {cracky=3,building_block=1}, sounds = mcl_core.node_sound_stone_defaults(), diff --git a/mods/mcl_util/description.txt b/mods/mcl_util/description.txt new file mode 100644 index 000000000..c778045c1 --- /dev/null +++ b/mods/mcl_util/description.txt @@ -0,0 +1 @@ +Helper functions for MineClone 2. diff --git a/mods/mcl_util/init.lua b/mods/mcl_util/init.lua new file mode 100644 index 000000000..bdc92a6cc --- /dev/null +++ b/mods/mcl_util/init.lua @@ -0,0 +1,90 @@ +mcl_util = {} + +-- Based on minetest.rotate_and_place + +--[[ +Attempt to predict the desired orientation of the pillar-like node +defined by `itemstack`, and place it accordingly in one of 3 possible +orientations (X, Y or Z). + +Stacks are handled normally if the `infinitestacks` +field is false or omitted (else, the itemstack is not changed). +* `invert_wall`: if `true`, place wall-orientation on the ground and ground- + orientation on wall + +This function is a simplified version of minetest.rotate_and_place. +The Minetest function is seen as inappropriate because this includes mirror +images of possible orientations, causing problems with pillar shadings. +]] +function mcl_util.axis_place(itemstack, placer, pointed_thing, infinitestacks, invert_wall) + local unode = minetest.get_node_or_nil(pointed_thing.under) + if not unode then + return + end + local undef = minetest.registered_nodes[unode.name] + if undef and undef.on_rightclick then + undef.on_rightclick(pointed_thing.under, unode, placer, + itemstack, pointed_thing) + return + end + local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local wield_name = itemstack:get_name() + + local above = pointed_thing.above + local under = pointed_thing.under + local is_x = (above.x ~= under.x) + local is_y = (above.y ~= under.y) + local is_z = (above.z ~= under.z) + + local anode = minetest.get_node_or_nil(above) + if not anode then + return + end + local pos = pointed_thing.above + local node = anode + + if undef and undef.buildable_to then + pos = pointed_thing.under + node = unode + end + + if minetest.is_protected(pos, placer:get_player_name()) then + minetest.record_protection_violation(pos, placer:get_player_name()) + return + end + + local ndef = minetest.registered_nodes[node.name] + if not ndef or not ndef.buildable_to then + return + end + + local p2 + if is_y then + if invert_wall then + if fdir == 3 or fdir == 1 then + p2 = 12 + else + p2 = 6 + end + end + elseif is_x then + if invert_wall then + p2 = 0 + else + p2 = 12 + end + elseif is_z then + if invert_wall then + p2 = 0 + else + p2 = 6 + end + end + minetest.set_node(pos, {name = wield_name, param2 = p2}) + + if not infinitestacks then + itemstack:take_item() + return itemstack + end +end + diff --git a/mods/mcl_util/mod.conf b/mods/mcl_util/mod.conf new file mode 100644 index 000000000..e45f9124e --- /dev/null +++ b/mods/mcl_util/mod.conf @@ -0,0 +1 @@ +name = mcl_util