Verified Commit 5ad92c80 authored by Dirk's avatar Dirk

implement automatic Moreblocks rotation

Slabs and stairs are now properly rotated again as if they are when
Moreblocks is not used. The rotation functionality was derived from the
original stairs mod that comes with Minetest Game.
parent 5f140aed
Changes smaller things that are issues for either [Minetest](https://github.com/minetest/minetest) or [Minetest Game](https://github.com/minetest/minetest_game) that are technically fixable but won’t be fixed due to several non-technical reasons.
Changes smaller things that are issues for either [Minetest](https://github.com/minetest/minetest), [Minetest Game](https://github.com/minetest/minetest_game), and some well-known mods that are technically fixable but won’t be fixed due to several non-technical reasons.
## Configuration
......@@ -12,7 +12,7 @@ The configurations can be set in the global `minetest.conf` file as well as in a
* setting: `redef_3d_ladders = true`
* disable: set to `false`
* fixes: [2423]
* fixes: [mtg2423]
* default: no 3D ladders
Redefining the 2D ladders so that they use a 3D model. No new textures are needed since he normal textures are used. Only works properly if using the 16x16 default textures or texture packs that use the same size and shape for the ladders.
......@@ -23,7 +23,7 @@ Redefining the 2D ladders so that they use a 3D model. No new textures are neede
* setting: `redef_stack_max = 100`
* disable: set to 0
* fixes: [1843], [5730], [1724], [394]
* fixes: [mtg1843], [mtg5730], [mtg1724], [mt394]
* default: stack size at 99
It changes the maximum stack size of all registered things whose stack size is 99 to the given `redef_stack_max` value. Unfortunately the maximum stack size of 99 is hardcoded in some places and can’t be changed using a mod.
......@@ -34,7 +34,7 @@ It changes the maximum stack size of all registered things whose stack size is 9
* setting: `redef_grass_box_height = 2`
* disable: set to 0
* fixes: [1980]
* fixes: [mtg1980]
* default: various heights for grass selection boxes
Make grass selection box x/16 high for easy building or punching through regardless of actual height of the box.
......@@ -45,19 +45,29 @@ Make grass selection box x/16 high for easy building or punching through regardl
* setting: `redef_aligned_textures = true`
* disable: set to `false`
* fixes: [2287], [1931], [5222]
* fixes: [mtg2287], [mtg1931], [mt5222]
* default: textures not aligned for most relevant nodes
This fixes the texture orientation of stairs and slabs regardless of how they were defined to achieve a clean look. This redefinition also world-alignes moreblocks nodes that are nodeboxes (world-alignment of textures only works on nodeboxes).
[2423]: https://github.com/minetest/minetest_game/issues/2423
[1843]: https://github.com/minetest/minetest/pull/1843
[5730]: https://github.com/minetest/minetest/issues/5730
[1724]: https://github.com/minetest/minetest_game/issues/1724
[394]: https://github.com/minetest/minetest/issues/394
[1980]: https://github.com/minetest/minetest_game/issues/1980
[5214]: https://github.com/minetest/minetest/issues/5214
[4050]: https://github.com/minetest/minetest/issues/4050
[2287]: https://github.com/minetest/minetest_game/issues/2287
[1931]: https://github.com/minetest/minetest_game/issues/1931
[5222]: https://github.com/minetest/minetest/issues/5222
### Moreblocks Rotation
![Result](screenshots/redef_moreblocks_rotation.png)
* setting: `redef_moreblocks_rotation = true`
* disable: set to `false`
* fixes: [moreblocks138]
* default: slabs and stairs do not align properly on placement
Moreblocks re-implements all stairs and slabs for unknown reason and thus breaking their placement and auto-rotation. By enabling this, the original functionality is replicated.
[mtg2423]: https://github.com/minetest/minetest_game/issues/2423
[mtg1843]: https://github.com/minetest/minetest/pull/1843
[mtg5730]: https://github.com/minetest/minetest/issues/5730
[mtg1724]: https://github.com/minetest/minetest_game/issues/1724
[mt394]: https://github.com/minetest/minetest/issues/394
[mtg1980]: https://github.com/minetest/minetest_game/issues/1980
[mtg2287]: https://github.com/minetest/minetest_game/issues/2287
[mtg1931]: https://github.com/minetest/minetest_game/issues/1931
[mt5222]: https://github.com/minetest/minetest/issues/5222
[moreblocks138]: https://github.com/minetest-mods/moreblocks/issues/138
......@@ -28,7 +28,8 @@ minetest.register_on_mods_loaded(function()
['3D Ladders'] = minetest.is_yes(g('3d_ladders', true)),
['Maximum Stack Size'] = tonumber(g('stack_max', 100)) >= 1,
['Grass Box Height'] = tonumber(g('grass_box_height', 2)) >= 1,
['Aligned Textures'] = minetest.is_yes(g('aligned_textures', true))
['Aligned Textures'] = minetest.is_yes(g('aligned_textures', true)),
['Moreblocks Rotation'] = minetest.is_yes(g('moreblocks_rotation',true))
}
for name,use in pairs(redefinitions) do
......
local override_item = minetest.override_item
local pointed_thing_to_face_pos = minetest.pointed_thing_to_face_pos
local dir_to_facedir = minetest.dir_to_facedir
local is_creative_enabled = minetest.is_creative_enabled
local item_place_node = minetest.item_place_node
local stairs = {}
local slabs = {}
-- Correct stairs placement
--
-- Derived from the original stairs on_place function of Minetest Game.
--
-- @param itemstack An itemstack according to Minetest API
-- @param placer A placer object according to Minetest API
-- @param pointed_thing A pointed_thing according to Minetest API
-- @return mixed itemstack and position according to Minetest API
local properly_rotate = function (itemstack, placer, pointed_thing)
local under = pointed_thing.under
local above = pointed_thing.above
local param2 = 0
if placer then
local placer_pos = placer:get_pos()
local finepos = pointed_thing_to_face_pos(placer, pointed_thing)
local fpos = finepos.y % 1
local under_above = under.y - 1 == above.y
local fpos_perimeter = (fpos > 0 and fpos < 0.5)
local fpos_limit = (fpos < -0.5 and fpos > -0.999999999)
if placer_pos then
param2 = dir_to_facedir(vector.subtract(above, placer_pos))
end
if under_above or fpos_perimeter or fpos_limit then
param2 = param2 + 20
if param2 == 21 then
param2 = 23
elseif param2 == 23 then
param2 = 21
end
end
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end
-- Correct slabs placement
--
-- Derived from the original stairs on_place function of Minetest Game.
--
-- @param itemstack An itemstack according to Minetest API
-- @param placer A placer object according to Minetest API
-- @param pointed_thing A pointed_thing according to Minetest API
-- @return mixed itemstack and position according to Minetest API
local on_place_slabs = function (itemstack, placer, pointed_thing)
local under = minetest.get_node(pointed_thing.under)
local wield_item = itemstack:get_name()
local player_name = placer and placer:get_player_name() or ''
-- Special behavior if placed on a slab
if under and under.name:find(':slab_') then
local pt_above = pointed_thing.above
local pt_under = pointed_thing.under
local fdir = dir_to_facedir(vector.subtract(pt_above, pt_under), true)
local p2 = under.param2
-- Slab placement based on upside-down slabs or below slabs
--
-- ┌────────┐
-- │ │
-- ┢━━━━━━━━┪ <-- Slab A (bottom half of the node seen sideways)
-- ┃ ┃
-- ┈┈┈┈┣━━━━━━━━┫┈┈┈┈
-- ┃ ┃
-- ┡━━━━━━━━┩ <-- Slab B (top half of the node, seen sideways)
-- │ │
-- └────────┘
--
-- Slabs A and B are rotated according slab B or A on placement so that
-- slabs placed on regular slabs from below automatically become
-- upside-down slabs and slabs placed on top of upside-down slabs are
-- not rotated into the same position.
if p2 >= 20 and fdir == 8 then p2 = p2 - 20 end -- Slab A rotation
if p2 <= 3 and fdir == 4 then p2 = p2 + 20 end -- Slab B rotation
-- Place node usind the calculated rotation
item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
-- Remove one item if not in creative and return the itemstack
if not is_creative_enabled(player_name) then itemstack:take_item() end
return itemstack
end
-- When not placed on a slab just properly rotate the slab
return properly_rotate(itemstack, placer, pointed_thing)
end
-- Determine all stairs and slabs and put them into the respective tables.
for name,definition in pairs(minetest.registered_nodes) do
local from_moreblocks = definition.mod_origin == 'moreblocks'
local stair = definition.groups.stair
  • Maintainer

    This was changed in f78340a2 to also use string-based detection because groups seem to be unreliable for properly detecting all stairs.

Please register or sign in to reply
local slab = string.match(name, ':slab_') ~= nil
if stair and from_moreblocks then table.insert(stairs, name) end
if slab and from_moreblocks then table.insert(slabs, name) end
end
-- Iterate over all stairs and override the broken on_place function.
for _,name in pairs(stairs) do
override_item(name, {
on_place = function (itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then return itemstack end
return properly_rotate(itemstack, placer, pointed_thing)
end
})
end
-- Iterate over all slabs and override the broken on_place function.
for _,name in pairs(slabs) do
override_item(name, {
on_place = function (itemstack, placer, pointed_thing)
return on_place_slabs(itemstack, placer, pointed_thing)
end
})
end
screenshots/redef_moreblocks_rotation.png

103 KB

Please register or sign in to reply
Please register or sign in to reply
Please register or sign in to reply
Please register or sign in to reply
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment