|
| 1 | +minetest.register_entity("pclasses:item", { |
| 2 | + initial_properties = { |
| 3 | + hp_max = 1, |
| 4 | + physical = false, |
| 5 | + collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, |
| 6 | + visual = "sprite", |
| 7 | + visual_size = {x=0.5, y=0.5}, |
| 8 | + textures = {""}, |
| 9 | + spritediv = {x=1, y=1}, |
| 10 | + initial_sprite_basepos = {x=0, y=0}, |
| 11 | + is_visible = false, |
| 12 | + }, |
| 13 | + itemname = '', |
| 14 | + class = '', |
| 15 | + set_class = function(self, class) |
| 16 | + self.class = class |
| 17 | + end, |
| 18 | + set_item = function(self, itemstring) |
| 19 | + self.itemname = itemstring |
| 20 | + local itemname = itemstring |
| 21 | + local item_texture = nil |
| 22 | + local item_type = "" |
| 23 | + if minetest.registered_items[itemname] then |
| 24 | + item_texture = minetest.registered_items[itemname].inventory_image |
| 25 | + item_type = minetest.registered_items[itemname].type |
| 26 | + end |
| 27 | + local prop = { |
| 28 | + is_visible = true, |
| 29 | + visual = "sprite", |
| 30 | + textures = {"unknown_item.png"} |
| 31 | + } |
| 32 | + if item_texture and item_texture ~= "" then |
| 33 | + prop.visual = "sprite" |
| 34 | + prop.textures = {item_texture} |
| 35 | + prop.visual_size = {x=0.50, y=0.50} |
| 36 | + else |
| 37 | + prop.visual = "wielditem" |
| 38 | + prop.textures = {itemname} |
| 39 | + prop.visual_size = {x=0.25, y=0.25} |
| 40 | + prop.automatic_rotate = math.pi * 0.10 |
| 41 | + end |
| 42 | + self.object:set_properties(prop) |
| 43 | + end, |
| 44 | + on_rightclick = function(self, clicker) |
| 45 | + print(clicker:get_player_name()) |
| 46 | + print(self.class) |
| 47 | + pclasses.api.set_player_class(clicker:get_player_name(), self.class) |
| 48 | + end, |
| 49 | + on_activate = function(self, staticdata) |
| 50 | + self.itemname = staticdata:split("|")[1] |
| 51 | + self.class = staticdata:split("|")[2] |
| 52 | +-- self.object:set_armor_groups({immortal=1}) |
| 53 | + self:set_item(self.itemname) |
| 54 | + end, |
| 55 | + get_staticdata = function(self) |
| 56 | + return self.itemname .. "|" .. self.class |
| 57 | + end, |
| 58 | +}) |
| 59 | + |
| 60 | +local classes_items = { |
| 61 | + ["hunter"] = "throwing:bow_minotaur_horn_improved", |
| 62 | + ["warrior"] = "default:dungeon_master_s_blood_sword", |
| 63 | + ["admin"] = "maptools:pick_admin", |
| 64 | + ["adventurer"] = "unified_inventory:bag_large" |
| 65 | +} |
| 66 | + |
1 | 67 | function pclasses.register_class_switch_orb(cname, color)
|
2 | 68 | color = color or { r = 255, g = 255, b = 255 }
|
3 | 69 | local txtcolor = string.format("#%02x%02x%02x", color.r, color.g, color.b)
|
4 | 70 | local overlay = "pclasses_class_switch_orb_overlay.png"
|
5 |
| - minetest.register_node(":pclasses:class_switch_orb_" .. cname, { |
| 71 | + minetest.register_node(":pclasses:class_switch_" .. cname, { |
6 | 72 | description = "Class switch orb (" .. cname .. ")",
|
7 | 73 | tiles = {overlay .. "^[colorize:" .. txtcolor .. "^" .. overlay},
|
| 74 | + drawtype = "nodebox", |
| 75 | + node_box = { type = "fixed", fixed = { |
| 76 | + {-7/16, -8/16, -7/16, 7/16, -7/16, 7/16}, -- bottom plate |
| 77 | + {-6/16, -7/16, -6/16, 6/16, -6/16, 6/16}, -- bottom plate (upper) |
| 78 | + {-0.25, -6/16, -0.25, 0.25, 11/16, 0.25}, -- pillar |
| 79 | + {-7/16, 11/16, -7/16, 7/16, 12/16, 7/16}, -- top plate |
| 80 | + }}, |
8 | 81 | drop = "",
|
9 | 82 | can_dig = function() return false end,
|
10 | 83 | diggable = false,
|
11 | 84 | sunlight_propagates = true,
|
12 | 85 | light_source = 10,
|
13 | 86 | sounds = default.node_sound_glass_defaults(),
|
14 |
| - groups = {not_in_creative_inventory=1}, |
15 |
| - on_rightclick = function(pos, node, player, itemstack, pointed_thing) |
16 |
| - -- TODO implement timeout logic |
17 |
| - pclasses.api.set_player_class(player:get_player_name(), cname) |
18 |
| - end |
| 87 | + groups = {not_in_creative_inventory=1, cracky = 1}, |
| 88 | + after_place_node = function(pos) |
| 89 | + pos.y = pos.y + 1 |
| 90 | + local obj = minetest.add_entity(pos, "pclasses:item") |
| 91 | + if obj then |
| 92 | + obj:get_luaentity():set_item(classes_items[cname]) |
| 93 | + obj:get_luaentity():set_class(cname) |
| 94 | + end |
| 95 | + end, |
19 | 96 | })
|
20 | 97 | end
|
0 commit comments