]> git.lizzy.rs Git - Crafter.git/blob - mods/player_api/init.lua
Fix mob multiple item drop
[Crafter.git] / mods / player_api / init.lua
1 -- player/init.lua
2
3 dofile(minetest.get_modpath("player_api") .. "/api.lua")
4
5 -- Default player appearance
6 player_api.register_model("character.b3d", {
7         animation_speed = 24,
8         textures = {"player.png", },
9         animations = {
10                 -- Standard animations.
11                 stand     = {x = 5,   y = 5},
12                 die       = {x = 5,   y = 5},
13                 lay       = {x = 162, y = 162},
14                 walk      = {x = 168, y = 187},
15                 mine      = {x = 189, y = 198},
16                 run       = {x = 189, y = 198},
17                 walk_mine = {x = 200, y = 219},
18                 run_mine  = {x = 200, y = 219},
19                 sit       = {x = 81,  y = 160},
20                 sneak     = {x = 60,  y = 60},
21                 sneak_mine_stand = {x=20,y=30},
22                 sneak_walk= {x = 60,   y = 80},
23                 sneak_mine_walk= {x = 40,   y = 59},
24         },
25         collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
26         stepheight = 0.6,
27         eye_height = 1.47,
28 })
29
30 -- Update appearance when the player joins
31 minetest.register_on_joinplayer(function(player)
32         player_api.player_attached[player:get_player_name()] = false
33         player_api.set_model(player, "character.b3d")
34         player:set_local_animation(
35                 {x = 0,   y = 79},
36                 {x = 168, y = 187},
37                 {x = 189, y = 198},
38                 {x = 200, y = 219},
39                 24
40         )
41 end)
42
43 minetest.register_entity("player_api:item", {
44         initial_properties = {
45                 hp_max = 1,
46                 physical = true,
47                 collide_with_objects = false,
48                 collisionbox = {0, 0, 0, 0, 0, 0},
49                 visual = "wielditem",
50                 visual_size = {x = 0.21, y = 0.21},
51                 textures = {""},
52                 spritediv = {x = 1, y = 1},
53                 initial_sprite_basepos = {x = 0, y = 0},
54                 is_visible = true,
55                 pointable = false,
56         },
57
58         itemstring = "",
59
60         set_item = function(self, item)
61                 local stack = ItemStack(item or self.itemstring)
62                 
63                 self.itemstring = stack:to_string()
64                 
65
66                 -- Backwards compatibility: old clients use the texture
67                 -- to get the type of the item
68                 local itemname = stack:is_known() and stack:get_name() or "unknown"
69
70                 local max_count = stack:get_stack_max()
71                 local count = math.min(stack:get_count(), max_count)
72
73                 local size = 0.21
74                 local coll_height = size * 0.75
75                 local def = minetest.registered_nodes[itemname]
76                 local glow = def and def.light_source
77
78                 local is_visible = true
79                 if self.itemstring == "" then
80                         -- item not yet known
81                         is_visible = false
82                 end
83
84                 self.object:set_properties({
85                         is_visible = is_visible,
86                         visual = "wielditem",
87                         textures = {itemname},
88                         visual_size = {x = size, y = size},
89                         collisionbox = {-size, -0.21, -size,
90                                 size, coll_height, size},
91                         selectionbox = {-size, -size, -size, size, size, size},
92                         --automatic_rotate = math.pi * 0.5 * 0.2 / size,
93                         wield_item = self.itemstring,
94                         glow = glow,
95                 })
96         end,
97
98         on_step = function(self, dtime)
99                 if not self.wielder then
100                         self.object:remove()
101                 end
102         end,
103 })