Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Commit

Permalink
[xdecor] Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymkwi committed Nov 1, 2016
1 parent 86fda5f commit bac450a
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 70 deletions.
25 changes: 20 additions & 5 deletions mods/xdecor/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
## Generic ignorable patterns and files
## Files related to minetest development cycle
/*.patch
# GNU Patch reject file
*.rej

## Editors and Development environments
*~
.*.swp
*bak*
tags
*.swp
*.bak*
*.orig
# Vim
*.vim

# Kate
.*.kate-swp
.swp.*
# Eclipse (LDT)
.project
.settings/
.buildpath
.metadata
# Idea IDE
.idea/*
9 changes: 9 additions & 0 deletions mods/xdecor/.luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
unused_args = false
allow_defined_top = true

read_globals = {
"minetest",
"vector", "ItemStack",
"default",
"stairs", "doors", "xpanes",
}
7 changes: 5 additions & 2 deletions mods/xdecor/chess.lua
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, _, player

meta:set_string("playerWhite", playerWhite)
meta:set_string("playerBlack", playerBlack)
meta:set_string("lastMove", thisMove)
lastMove = thisMove
meta:set_string("lastMove", lastMove)
meta:set_int("lastMoveTime", minetest.get_gametime())
local lastMove = meta:get_string("lastMove")

if lastMove == "black" then
minetest.chat_send_player(playerWhite, "["..os.date("%H:%M:%S").."] "..
Expand Down Expand Up @@ -556,6 +556,9 @@ function realchess.fields(pos, _, fields, sender)
end

function realchess.dig(pos, player)
if not player then
return false
end
local meta = minetest.get_meta(pos)
local playerName = player:get_player_name()
local timeout_limit = meta:get_int("lastMoveTime") + 300
Expand Down
2 changes: 1 addition & 1 deletion mods/xdecor/cooking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function cauldron.filling(pos, node, clicker, itemstack)
else
minetest.chat_send_player(clicker:get_player_name(),
"No room in your inventory to add a bucket of water.")
return
return itemstack
end
else
itemstack:replace("bucket:bucket_water")
Expand Down
20 changes: 9 additions & 11 deletions mods/xdecor/craftguide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ function craftguide:set_formspec(player_name, pagenum, recipe_num)
"field[0.3,0.32;2.6,1;filter;;"..data.filter.."]"..
default.gui_bg..default.gui_bg_img

local i, s = 0, 0
for _, name in pairs(data.items) do
if s < (pagenum - 1) * npp then
s = s + 1
else if i >= npp then break end
local X = i % 8
local Y = ((i-X) / 8) + 1
local first_item = (pagenum - 1) * npp
for i = first_item, first_item + npp - 1 do
local name = data.items[i + 1]
if not name then break end -- last page

formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..
name..";"..name..";]"
i = i + 1
end
local X = i % 8
local Y = ((i % npp - X) / 8) + 1

formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..
name..";"..name..";]"
end

if data.item and minetest.registered_items[data.item] then
Expand Down
8 changes: 6 additions & 2 deletions mods/xdecor/enchanting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ function enchanting.on_put(pos, listname, _, stack)
end

function enchanting.fields(pos, _, fields, sender)
if fields.quit then return end
if not next(fields) or fields.quit then
return
end
local inv = minetest.get_meta(pos):get_inventory()
local tool = inv:get_stack("tool", 1)
local mese = inv:get_stack("mese", 1)
local orig_wear = tool:get_wear()
local mod, name = tool:get_name():match("(.*):(.*)")
if not mod or not name then return end
local enchanted_tool = (mod or "")..":enchanted_"..(name or "").."_"..next(fields)

if mese:get_count() >= mese_cost and minetest.registered_tools[enchanted_tool] then
Expand All @@ -84,6 +85,9 @@ function enchanting.dig(pos)
end

local function allowed(tool)
if not tool then
return false
end
for item in pairs(minetest.registered_tools) do
if tool and item:find("enchanted_"..tool) then return true end
end
Expand Down
10 changes: 3 additions & 7 deletions mods/xdecor/handlers/animations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ function xdecor.sit(pos, node, clicker, pointed_thing)
end
end

function xdecor.sit_dig(pos, player)
local pname = player:get_player_name()
local objs = minetest.get_objects_inside_radius(pos, 0.1)

for _, p in pairs(objs) do
if not player or not player:is_player() or p:get_player_name() or
default.player_attached[pname] then
function xdecor.sit_dig(pos, digger)
for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
if player:is_player() and default.player_attached[player:get_player_name()] then
return false
end
end
Expand Down
17 changes: 13 additions & 4 deletions mods/xdecor/handlers/registration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ local default_can_dig = function(pos)
end

function xdecor.register(name, def)
def.drawtype = def.drawtype or (def.node_box and "nodebox")
def.paramtype = def.paramtype or "light"
def.drawtype = def.drawtype
or (def.mesh and "mesh")
or (def.node_box and "nodebox")

def.sounds = def.sounds or default.node_sound_defaults()

if not (def.drawtype == "normal" or def.drawtype == "signlike" or
Expand All @@ -53,11 +55,18 @@ function xdecor.register(name, def)
def.paramtype2 = def.paramtype2 or "facedir"
end

if def.drawtype == "plantlike" or def.drawtype == "torchlike" or
def.drawtype == "signlike" or def.drawtype == "fencelike" then
if def.sunlight_propagates ~= false and
(def.drawtype == "plantlike" or def.drawtype == "torchlike" or
def.drawtype == "signlike" or def.drawtype == "fencelike") then
def.sunlight_propagates = true
end

if not def.paramtype and
(def.light_source or def.sunlight_propagates or
def.drawtype == "nodebox" or def.drawtype == "mesh") then
def.paramtype = "light"
end

local infotext = def.infotext
local inventory = def.inventory
def.inventory = nil
Expand Down
8 changes: 5 additions & 3 deletions mods/xdecor/itemframe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ function itemframe.rightclick(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
local owner = meta:get_string("owner")
if player ~= owner or not itemstack then return end
if player ~= owner or not itemstack then
return itemstack
end

drop_item(pos, node)
local itemstring = itemstack:take_item():to_string()
Expand All @@ -92,10 +94,10 @@ end

function itemframe.dig(pos, player)
local meta = minetest.get_meta(pos)
local pname = player:get_player_name()
local pname = player and player:get_player_name()
local owner = meta:get_string("owner")

return player and pname == owner
return pname == owner
end

xdecor.register("itemframe", {
Expand Down
7 changes: 4 additions & 3 deletions mods/xdecor/mailbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ end
function mailbox.dig(pos, player)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local player_name = player:get_player_name()
local player_name = player and player:get_player_name()
local inv = meta:get_inventory()

return inv:is_empty("mailbox") and player and player_name == owner
return inv:is_empty("mailbox") and player_name == owner
end

function mailbox.after_place_node(pos, placer)
Expand All @@ -96,7 +96,7 @@ function mailbox.after_place_node(pos, placer)
inv:set_size("drop", 1)
end

function mailbox.rightclick(pos, _, clicker)
function mailbox.rightclick(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
local owner = meta:get_string("owner")
Expand All @@ -106,6 +106,7 @@ function mailbox.rightclick(pos, _, clicker)
else
minetest.show_formspec(player, "xdecor:mailbox", mailbox:formspec(pos, owner, 0))
end
return itemstack
end

function mailbox.put(pos, listname, _, stack, player)
Expand Down
7 changes: 5 additions & 2 deletions mods/xdecor/mechanisms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ xdecor.register("lever_off", {
sounds = default.node_sound_stone_defaults(),
sunlight_propagates = true,
on_rotate = screwdriver.rotate_simple,
on_rightclick = function(pos, node, clicker)
if not doors.get then return end
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not doors.get then
return itemstack
end
local minp = {x=pos.x-2, y=pos.y-1, z=pos.z-2}
local maxp = {x=pos.x+2, y=pos.y+1, z=pos.z+2}
local doors = minetest.find_nodes_in_area(minp, maxp, "group:door")

for i = 1, #doors do
door_toggle(pos, doors[i], clicker)
end
return itemstack
end
})

Expand Down
29 changes: 12 additions & 17 deletions mods/xdecor/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ xdecor.register("chair", {
{11, 0, 3, 2, 6, 2}, {3, 6, 3, 10, 2, 8}
}),
can_dig = xdecor.sit_dig,
on_rightclick = function(pos, node, clicker, _, pointed_thing)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
pos.y = pos.y + 0 -- Sitting position.
xdecor.sit(pos, node, clicker, pointed_thing)
return itemstack
end
})

Expand Down Expand Up @@ -175,8 +176,9 @@ for _, c in pairs({"red"}) do -- Add more curtains colors simply here.
paramtype2 = "wallmounted",
groups = {dig_immediate=3, flammable=3},
selection_box = {type="wallmounted"},
on_rightclick = function(pos, node)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
minetest.set_node(pos, {name="xdecor:curtain_open_"..c, param2=node.param2})
return itemstack
end
})

Expand All @@ -188,8 +190,9 @@ for _, c in pairs({"red"}) do -- Add more curtains colors simply here.
groups = {dig_immediate=3, flammable=3, not_in_creative_inventory=1},
selection_box = {type="wallmounted"},
drop = "xdecor:curtain_"..c,
on_rightclick = function(pos, node)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
minetest.set_node(pos, {name="xdecor:curtain_"..c, param2=node.param2})
return itemstack
end
})

Expand All @@ -207,9 +210,10 @@ xdecor.register("cushion", {
on_place = minetest.rotate_node,
node_box = xdecor.nodebox.slab_y(0.5),
can_dig = xdecor.sit_dig,
on_rightclick = function(pos, node, clicker, _, pointed_thing)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
pos.y = pos.y + 0 -- Sitting position.
xdecor.sit(pos, node, clicker, pointed_thing)
return itemstack
end
})

Expand Down Expand Up @@ -354,27 +358,18 @@ xdecor.register("painting_1", {
inventory_image = "xdecor_painting_empty.png",
wield_image = "xdecor_painting_empty.png",
paramtype2 = "wallmounted",
wield_image = "xdecor_painting_empty.png",
sunlight_propagates = true,
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=2, attached_node=1},
sounds = default.node_sound_wood_defaults(),
node_box = painting_box,
node_placement_prediction = "",
on_place = function(itemstack, placer, pointed_thing)
local player_name = placer:get_player_name()
local pos = pointed_thing.above

if not minetest.is_protected(pos, player_name) then
local num = math.random(4)
local dir = minetest.dir_to_wallmounted(placer:get_look_dir())
minetest.set_node(pos, {name="xdecor:painting_"..num, param2=dir})
else
minetest.chat_send_player(player_name, "This area is protected")
end
if not minetest.setting_getbool("creative_mode") then
local num = math.random(4)
local leftover = minetest.item_place_node(ItemStack("xdecor:painting_"..num), placer, pointed_thing)
if leftover:get_count() == 0 and not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
return itemstack
end
return itemstack
end
})

Expand Down
25 changes: 13 additions & 12 deletions mods/xdecor/rope.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
local rope = {}

-- Code by Mirko K. (modified by Temperest, Wulfsdad and kilbith) (License: GPL).
minetest.register_on_punchnode(function(pos, oldnode, digger)
if oldnode.name == "xdecor:rope" and not minetest.is_protected(pos, digger:get_player_name()) then
rope:remove(pos, oldnode, digger, "xdecor:rope")
end
end)

function rope.place(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local under = pointed_thing.under
local above = pointed_thing.above
local pos = above
local pos = pointed_thing.above
local oldnode = minetest.get_node(pos)
local stackname = itemstack:get_name()
if minetest.is_protected(pos, placer:get_player_name()) then return end
if minetest.is_protected(pos, placer:get_player_name()) then
return itemstack
end

while oldnode.name == "air" and not itemstack:is_empty() do
local newnode = {name = stackname, param1 = 0}
Expand All @@ -27,7 +21,7 @@ function rope.place(itemstack, placer, pointed_thing)
return itemstack
end

function rope:remove(pos, oldnode, digger, rope_name)
function rope.remove(pos, oldnode, digger, rope_name)
local num = 0
local below = {x=pos.x, y=pos.y, z=pos.z}
local digger_inv = digger:get_inventory()
Expand All @@ -52,5 +46,12 @@ xdecor.register("rope", {
inventory_image = "xdecor_rope_inv.png",
wield_image = "xdecor_rope_inv.png",
selection_box = xdecor.pixelbox(8, {{3, 0, 3, 2, 8, 2}}),
on_place = rope.place
on_place = rope.place,
on_punch = function(pos, node, puncher, pointed_thing)
local player_name = puncher:get_player_name()
if not minetest.is_protected(pos, player_name) or
minetest.get_player_privs(player_name).protection_bypass then
rope.remove(pos, node, puncher, "xdecor:rope")
end
end
})
3 changes: 2 additions & 1 deletion mods/xdecor/workbench.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ for i = 1, #nodes do
local def = minetest.registered_nodes[node]

if d[3] then
local groups, tiles = {}, {}
local groups = {}
local tiles
groups.not_in_creative_inventory = 1

for k, v in pairs(def.groups) do
Expand Down

0 comments on commit bac450a

Please sign in to comment.