Bring back normal item dropping/combining
parent
2ab451f8d7
commit
41e04b2838
|
@ -6,6 +6,10 @@ Heavily borrows from Mineclone, along with other mods!
|
|||
|
||||
## todo for version 0.04
|
||||
|
||||
make sky dark when snowing or raining
|
||||
|
||||
fix gui size to match all (chest overclips)
|
||||
|
||||
mobs
|
||||
|
||||
animated chests
|
||||
|
|
|
@ -94,7 +94,43 @@ core.register_entity(":__builtin:item", {
|
|||
self.object:set_acceleration({x = 0, y = -gravity, z = 0})
|
||||
self:set_item()
|
||||
end,
|
||||
try_merge_with = function(self, own_stack, object, entity)
|
||||
if self.age == entity.age then
|
||||
-- Can not merge with itself
|
||||
return false
|
||||
end
|
||||
|
||||
local stack = ItemStack(entity.itemstring)
|
||||
local name = stack:get_name()
|
||||
if own_stack:get_name() ~= name or
|
||||
own_stack:get_meta() ~= stack:get_meta() or
|
||||
own_stack:get_wear() ~= stack:get_wear() or
|
||||
own_stack:get_free_space() == 0 then
|
||||
-- Can not merge different or full stack
|
||||
return false
|
||||
end
|
||||
|
||||
local count = own_stack:get_count()
|
||||
local total_count = stack:get_count() + count
|
||||
local max_count = stack:get_stack_max()
|
||||
|
||||
if total_count > max_count then
|
||||
return false
|
||||
end
|
||||
-- Merge the remote stack into this one
|
||||
|
||||
local pos = object:get_pos()
|
||||
pos.y = pos.y + ((total_count - count) / max_count) * 0.15
|
||||
self.object:move_to(pos)
|
||||
|
||||
self.age = 0 -- Handle as new entity
|
||||
own_stack:set_count(total_count)
|
||||
self:set_item(own_stack)
|
||||
|
||||
entity.itemstring = ""
|
||||
object:remove()
|
||||
return true
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
self.age = self.age + dtime
|
||||
if time_to_live > 0 and self.age > time_to_live then
|
||||
|
@ -163,6 +199,28 @@ core.register_entity(":__builtin:item", {
|
|||
self.object:set_velocity({x = 0, y = 0, z = 0})
|
||||
end
|
||||
|
||||
--Only collect items if not moving
|
||||
if is_moving then
|
||||
return
|
||||
end
|
||||
-- Collect the items around to merge with
|
||||
local own_stack = ItemStack(self.itemstring)
|
||||
if own_stack:get_free_space() == 0 then
|
||||
return
|
||||
end
|
||||
local objects = core.get_objects_inside_radius(pos, 1.0)
|
||||
for k, obj in pairs(objects) do
|
||||
local entity = obj:get_luaentity()
|
||||
if entity and entity.name == "__builtin:item" then
|
||||
if self:try_merge_with(own_stack, obj, entity) then
|
||||
own_stack = ItemStack(self.itemstring)
|
||||
if own_stack:get_free_space() == 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end,
|
||||
|
|
|
@ -87,19 +87,18 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||
end
|
||||
end
|
||||
|
||||
--throw a single item at player's speed
|
||||
--sneak throw, throws whole stack
|
||||
--throwing an item
|
||||
function minetest.item_drop(itemstack, dropper, pos)
|
||||
local dropper_is_player = dropper and dropper:is_player()
|
||||
local p = table.copy(pos)
|
||||
local cnt = itemstack:get_count()
|
||||
local vel = vector.new(0,0,0)
|
||||
|
||||
if dropper_is_player then
|
||||
p.y = p.y + 1.5
|
||||
p.y = p.y + 1.2
|
||||
vel = dropper:get_player_velocity()
|
||||
end
|
||||
|
||||
local item = itemstack:take_item(1)
|
||||
local item = itemstack:take_item(cnt)
|
||||
local obj = core.add_item(p, item)
|
||||
if obj then
|
||||
if dropper_is_player then
|
||||
|
@ -113,9 +112,12 @@ function minetest.item_drop(itemstack, dropper, pos)
|
|||
end
|
||||
return itemstack
|
||||
end
|
||||
-- If we reach this, adding the object to the
|
||||
-- environment failed
|
||||
end
|
||||
|
||||
|
||||
|
||||
--sound for craft success
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
minetest.sound_play("clack", {
|
||||
|
|
Loading…
Reference in New Issue