Skip to content

Commit bb22567

Browse files
HybridDognerzhul
authored andcommittedSep 11, 2017
Fix dropped item look (#6370)
* Abort set_item when it does nothing * Do not adjust dropped item size linearly Instead use cube root because the item count is proportional to the volume, not to the length. * Make the item rotate slower when it's bigger Bigger items chafe more on the ground, so they can't rotate as fast as small ones * Fix items flying in air
1 parent 5f489ef commit bb22567

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed
 

‎builtin/game/item_entity.lua

+15-12
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,35 @@ core.register_entity(":__builtin:item", {
3737
slippery_state = false,
3838
age = 0,
3939

40-
set_item = function(self, itemstring)
41-
local stack = ItemStack(itemstring or self.itemstring)
40+
set_item = function(self, item)
41+
local stack = ItemStack(item or self.itemstring)
4242
self.itemstring = stack:to_string()
43+
if self.itemstring == "" then
44+
-- item not yet known
45+
return
46+
end
4347

4448
-- Backwards compatibility: old clients use the texture
4549
-- to get the type of the item
46-
local itemname = stack:get_name()
50+
local itemname = stack:is_known() and stack:get_name() or "unknown"
4751

4852
local max_count = stack:get_stack_max()
4953
local count = math.min(stack:get_count(), max_count)
50-
local size = 0.2 + 0.1 * (count / max_count)
51-
52-
if not stack:is_known() then
53-
itemname = "unknown"
54-
end
54+
local size = 0.2 + 0.1 * (count / max_count) ^ (1 / 3)
55+
local coll_height = size * 0.75
5556

5657
self.object:set_properties({
5758
is_visible = true,
5859
visual = "wielditem",
5960
textures = {itemname},
6061
visual_size = {x = size, y = size},
61-
collisionbox = {-size, -size, -size, size, size, size},
62-
automatic_rotate = math.pi * 0.5,
62+
collisionbox = {-size, -coll_height, -size,
63+
size, coll_height, size},
64+
selectionbox = {-size, -size, -size, size, size, size},
65+
automatic_rotate = math.pi * 0.5 * 0.2 / size,
6366
wield_item = self.itemstring,
6467
})
65-
68+
6669
end,
6770

6871
get_staticdata = function(self)
@@ -154,7 +157,7 @@ core.register_entity(":__builtin:item", {
154157
is_slippery = slippery ~= 0
155158
if is_slippery then
156159
is_physical = true
157-
160+
158161
-- Horizontal deceleration
159162
local slip_factor = 4.0 / (slippery + 4)
160163
self.object:set_acceleration({

0 commit comments

Comments
 (0)
Please sign in to comment.