From 06c3a6f4cd64b1d115392963cf511b8e2a6bf060 Mon Sep 17 00:00:00 2001 From: kilbith Date: Fri, 1 Apr 2016 23:52:00 +0200 Subject: [PATCH] Enchant table : Add a book entity over the table --- enchanting.lua | 33 +++++++++++++++++++++++++++++++++ textures/xdecor_book_open.png | Bin 0 -> 242 bytes 2 files changed, 33 insertions(+) create mode 100644 textures/xdecor_book_open.png diff --git a/enchanting.lua b/enchanting.lua index 1c5450d..b7d5b97 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -110,6 +110,29 @@ function enchanting.construct(pos) local inv = meta:get_inventory() inv:set_size("tool", 1) inv:set_size("mese", 1) + + minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open") + local timer = minetest.get_node_timer(pos) + timer:start(15.0) +end + +function enchanting.destruct(pos) + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do + if obj and obj:get_luaentity() and + obj:get_luaentity().name == "xdecor:book_open" then + obj:remove() break + end + end +end + +function enchanting.timer(pos) + local node = minetest.get_node(pos) + local num = #minetest.get_objects_inside_radius(pos, 0.9) + + if num == 0 then + minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open") + end + return true end xdecor.register("enchantment_table", { @@ -121,7 +144,9 @@ xdecor.register("enchantment_table", { sounds = default.node_sound_stone_defaults(), on_rotate = screwdriver.rotate_simple, can_dig = enchanting.dig, + on_timer = enchanting.timer, on_construct = enchanting.construct, + on_destruct = enchanting.destruct, on_receive_fields = enchanting.fields, on_metadata_inventory_put = enchanting.on_put, on_metadata_inventory_take = enchanting.on_take, @@ -129,6 +154,14 @@ xdecor.register("enchantment_table", { allow_metadata_inventory_move = function() return 0 end }) +minetest.register_entity("xdecor:book_open", { + visual = "sprite", + visual_size = {x=0.75, y=0.75}, + collisionbox = {0}, + physical = false, + textures = {"xdecor_book_open.png"} +}) + local function cap(S) return S:gsub("^%l", string.upper) end function enchanting:register_tools(mod, def) diff --git a/textures/xdecor_book_open.png b/textures/xdecor_book_open.png new file mode 100644 index 0000000000000000000000000000000000000000..508e808525e987fd72abcb284652343ec60a8c59 GIT binary patch literal 242 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!S%6Q7E08{M=Fr^-w=Q2lzkchA zGZ&7pT)*hh@x2{NO2x9W-onDZSyQW%qT?ha!pc`7V_d4kyL!eH^k|4ie z28U-i(tw;SPZ!4!iOaqH-h2%TJT9%DbQ8Y*n_e2#v96~q_}Nq6hPTJB2;8;#DWMhS z`D9M2|4JR^CpmI$3>{K>?|pe!9|%Zj3$^Pt;!Tk#x<84(;V0iqmn96Vvs0z-2&XQ( m!mg|*(sV3+M&+JAUzyekGk4xwa(ph(Rt8U3KbLh*2~7Y_%Us9+ literal 0 HcmV?d00001