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 airmaster
parent
5f489efc69
commit
bb225672f9
|
@ -37,32 +37,35 @@ core.register_entity(":__builtin:item", {
|
||||||
slippery_state = false,
|
slippery_state = false,
|
||||||
age = 0,
|
age = 0,
|
||||||
|
|
||||||
set_item = function(self, itemstring)
|
set_item = function(self, item)
|
||||||
local stack = ItemStack(itemstring or self.itemstring)
|
local stack = ItemStack(item or self.itemstring)
|
||||||
self.itemstring = stack:to_string()
|
self.itemstring = stack:to_string()
|
||||||
|
if self.itemstring == "" then
|
||||||
|
-- item not yet known
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Backwards compatibility: old clients use the texture
|
-- Backwards compatibility: old clients use the texture
|
||||||
-- to get the type of the item
|
-- to get the type of the item
|
||||||
local itemname = stack:get_name()
|
local itemname = stack:is_known() and stack:get_name() or "unknown"
|
||||||
|
|
||||||
local max_count = stack:get_stack_max()
|
local max_count = stack:get_stack_max()
|
||||||
local count = math.min(stack:get_count(), max_count)
|
local count = math.min(stack:get_count(), max_count)
|
||||||
local size = 0.2 + 0.1 * (count / max_count)
|
local size = 0.2 + 0.1 * (count / max_count) ^ (1 / 3)
|
||||||
|
local coll_height = size * 0.75
|
||||||
if not stack:is_known() then
|
|
||||||
itemname = "unknown"
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
is_visible = true,
|
is_visible = true,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
textures = {itemname},
|
textures = {itemname},
|
||||||
visual_size = {x = size, y = size},
|
visual_size = {x = size, y = size},
|
||||||
collisionbox = {-size, -size, -size, size, size, size},
|
collisionbox = {-size, -coll_height, -size,
|
||||||
automatic_rotate = math.pi * 0.5,
|
size, coll_height, size},
|
||||||
|
selectionbox = {-size, -size, -size, size, size, size},
|
||||||
|
automatic_rotate = math.pi * 0.5 * 0.2 / size,
|
||||||
wield_item = self.itemstring,
|
wield_item = self.itemstring,
|
||||||
})
|
})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
|
@ -154,7 +157,7 @@ core.register_entity(":__builtin:item", {
|
||||||
is_slippery = slippery ~= 0
|
is_slippery = slippery ~= 0
|
||||||
if is_slippery then
|
if is_slippery then
|
||||||
is_physical = true
|
is_physical = true
|
||||||
|
|
||||||
-- Horizontal deceleration
|
-- Horizontal deceleration
|
||||||
local slip_factor = 4.0 / (slippery + 4)
|
local slip_factor = 4.0 / (slippery + 4)
|
||||||
self.object:set_acceleration({
|
self.object:set_acceleration({
|
||||||
|
|
Loading…
Reference in New Issue