Skip to content

Instantly share code, notes, and snippets.

@GreenXenith GreenXenith/init.lua Secret
Created Oct 31, 2017

Embed
What would you like to do?
init.lua
minetest.register_node("mymod:mynode", {
description = "mynode",
drawtype = "mesh",
mesh = "mynode.obj",
tiles = {"mynode.png"},
use_texture_alpha = true,
inventory_image = "inv_mynode.png",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.4, -0.5, 0.5, 0.4, 0.5, 0.2},
},
collision_box = {
type = "fixed",
fixed = {-0.4, -0.5, 0.5, 0.4, 0.5, 0.2},
},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {snappy = 3},
sounds = default.node_sound_leaves_defaults(),
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if player then
minetest.chat_send_player(player:get_player_name(),
"Cannot move stuff.")
return 0
end
end,
on_place = function(itemstack, placer, pointed_thing)
if minetest.is_yes(placer:get_attribute("has_placed_mynode")) then
print "! mynode not placed - another exists"
return itemstack
else
print "! mynode placed."
return minetest.item_place(itemstack, placer, pointed_thing)
end
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local owner = placer:get_player_name()
meta:set_string("owner", owner)
meta:set_string("infotext", owner.."'s mynode")
local inv = meta:get_inventory()
inv:set_size("main", 8*2)
local stuffers = stuffer.select_stuffers()
for i=1, #stuffers do
inv:set_stack("main", i, stuffers[i])
end
placer:set_attribute("has_placed_mynode", "true")
print "! has_placed = true"
end,
on_rightclick = function(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
local owner = meta:get_string("owner")
local meta = minetest.get_meta(pos)
if owner == player then
minetest.show_formspec(
clicker:get_player_name(),
"default:chest_locked",
stocking.get_stocking_formspec(pos))
else
return itemstack
end
return itemstack
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local name = player and player:get_player_name()
local owner = meta:get_string("owner")
local inv = meta:get_inventory()
return name == owner and inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
minetest.log("action", player:get_player_name() ..
" moves stuff in mynode at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to mynode at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" takes stuff from mynode at " .. minetest.pos_to_string(pos))
end,
on_dig = function(pos, node, digger)
if can_dig then
digger:set_attribute("has_placed_mynode", "false")
minetest.remove_node(pos)
print "! has_placed = false (dug)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.