mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-28 05:03:03 +00:00
Implement banner rotation with screwdriver
This commit is contained in:
parent
bbcab7275e
commit
643b1e7933
1 changed files with 47 additions and 11 deletions
|
@ -50,6 +50,10 @@ local layer_ratio = 255
|
||||||
local standing_banner_entity_offset = { x=0, y=-0.499, z=0 }
|
local standing_banner_entity_offset = { x=0, y=-0.499, z=0 }
|
||||||
local hanging_banner_entity_offset = { x=0, y=-1.7, z=0 }
|
local hanging_banner_entity_offset = { x=0, y=-1.7, z=0 }
|
||||||
|
|
||||||
|
local rotation_level_to_yaw = function(rotation_level)
|
||||||
|
return (rotation_level * (math.pi/8)) + math.pi
|
||||||
|
end
|
||||||
|
|
||||||
local on_dig_banner = function(pos, node, digger)
|
local on_dig_banner = function(pos, node, digger)
|
||||||
-- Check protection
|
-- Check protection
|
||||||
local name = digger:get_player_name()
|
local name = digger:get_player_name()
|
||||||
|
@ -151,7 +155,7 @@ local spawn_banner_entity = function(pos, hanging, itemstack)
|
||||||
return banner
|
return banner
|
||||||
end
|
end
|
||||||
|
|
||||||
local respawn_banner_entity = function(pos, node)
|
local respawn_banner_entity = function(pos, node, force)
|
||||||
local hanging = node.name == "mcl_banners:hanging_banner"
|
local hanging = node.name == "mcl_banners:hanging_banner"
|
||||||
local offset
|
local offset
|
||||||
if hanging then
|
if hanging then
|
||||||
|
@ -165,26 +169,24 @@ local respawn_banner_entity = function(pos, node)
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
local ent = v:get_luaentity()
|
local ent = v:get_luaentity()
|
||||||
if ent and (ent.name == "mcl_banners:standing_banner" or ent.name == "mcl_banners:hanging_banner") then
|
if ent and (ent.name == "mcl_banners:standing_banner" or ent.name == "mcl_banners:hanging_banner") then
|
||||||
|
if force then
|
||||||
|
v:remove()
|
||||||
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- Spawn new entity
|
-- Spawn new entity
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local banner_item = meta:get_inventory():get_stack("banner", 1)
|
local banner_item = meta:get_inventory():get_stack("banner", 1)
|
||||||
local banner_entity = spawn_banner_entity(bpos, hanging, banner_item)
|
local banner_entity = spawn_banner_entity(bpos, hanging, banner_item)
|
||||||
|
|
||||||
-- Set rotation
|
-- Set rotation
|
||||||
local final_yaw
|
|
||||||
local rotation_level = meta:get_int("rotation_level")
|
local rotation_level = meta:get_int("rotation_level")
|
||||||
final_yaw = (rotation_level * (math.pi/8)) + math.pi
|
local final_yaw = rotation_level_to_yaw(rotation_level)
|
||||||
banner_entity:set_yaw(final_yaw)
|
banner_entity:set_yaw(final_yaw)
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_rotate
|
|
||||||
if minetest.get_modpath("screwdriver") then
|
|
||||||
on_rotate = screwdriver.disallow
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Banner nodes.
|
-- Banner nodes.
|
||||||
-- These are an invisible nodes which are only used to destroy the banner entity.
|
-- These are an invisible nodes which are only used to destroy the banner entity.
|
||||||
-- All the important banner information (such as color) is stored in the entity.
|
-- All the important banner information (such as color) is stored in the entity.
|
||||||
|
@ -229,6 +231,18 @@ S("You can copy the pattern of a banner by placing two banners of the same color
|
||||||
end,
|
end,
|
||||||
_mcl_hardness = 1,
|
_mcl_hardness = 1,
|
||||||
_mcl_blast_resistance = 5,
|
_mcl_blast_resistance = 5,
|
||||||
|
on_rotate = function(pos, node, user, mode, param2)
|
||||||
|
if mode == screwdriver.ROTATE_FACE then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local rot = meta:get_int("rotation_level")
|
||||||
|
rot = (rot - 1) % 16
|
||||||
|
meta:set_int("rotation_level", rot)
|
||||||
|
respawn_banner_entity(pos, node, true)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Hanging banner node
|
-- Hanging banner node
|
||||||
|
@ -261,7 +275,29 @@ minetest.register_node("mcl_banners:hanging_banner", {
|
||||||
end,
|
end,
|
||||||
_mcl_hardness = 1,
|
_mcl_hardness = 1,
|
||||||
_mcl_blast_resistance = 5,
|
_mcl_blast_resistance = 5,
|
||||||
on_rotate = on_rotate,
|
on_rotate = function(pos, node, user, mode, param2)
|
||||||
|
if mode == screwdriver.ROTATE_FACE then
|
||||||
|
local r = screwdriver.rotate.wallmounted(pos, node, mode)
|
||||||
|
node.param2 = r
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local rot = 0
|
||||||
|
if node.param2 == 2 then
|
||||||
|
rot = 12
|
||||||
|
elseif node.param2 == 3 then
|
||||||
|
rot = 4
|
||||||
|
elseif node.param2 == 4 then
|
||||||
|
rot = 0
|
||||||
|
elseif node.param2 == 5 then
|
||||||
|
rot = 8
|
||||||
|
end
|
||||||
|
meta:set_int("rotation_level", rot)
|
||||||
|
respawn_banner_entity(pos, node, true)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
for colorid, colortab in pairs(mcl_banners.colors) do
|
for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
|
@ -410,7 +446,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
if rotation_level >= 16 then
|
if rotation_level >= 16 then
|
||||||
rotation_level = 0
|
rotation_level = 0
|
||||||
end
|
end
|
||||||
final_yaw = (rotation_level * (math.pi/8)) + math.pi
|
final_yaw = rotation_level_to_yaw(rotation_level)
|
||||||
end
|
end
|
||||||
meta:set_int("rotation_level", rotation_level)
|
meta:set_int("rotation_level", rotation_level)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue