Skip to content

Commit

Permalink
Merge changes made in technic_game
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBadAngel committed Jul 6, 2013
1 parent b78b90d commit 3a37005
Show file tree
Hide file tree
Showing 54 changed files with 589 additions and 580 deletions.
1 change: 1 addition & 0 deletions item_drop/depends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
technic
151 changes: 58 additions & 93 deletions item_drop/init.lua
Original file line number Diff line number Diff line change
@@ -1,109 +1,74 @@
dofile(minetest.get_modpath("item_drop").."/item_entity.lua")
time_pick = 3
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos()
pos.y = pos.y+0.5
local inv = player:get_inventory()
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
if object:get_luaentity().timer > time_pick then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
if object:get_luaentity().itemstring ~= "" then
minetest.sound_play("item_drop_pickup", {
to_player = player:get_player_name(),
})
end
object:get_luaentity().itemstring = ""
object:remove()
end
end
end
end

for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 3)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
--print(dump(object:getpos().y-player:getpos().y))
if object:getpos().y-player:getpos().y > 0 then
if object:get_luaentity().collect then
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
if object:get_luaentity().timer > time_pick then
local pos1 = pos
pos1.y = pos1.y+0.2
local pos2 = object:getpos()
local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
vec.x = vec.x*3
vec.y = vec.y*3
vec.z = vec.z*3
object:setvelocity(vec)

minetest.after(1, function(args)
local lua = object:get_luaentity()
if object == nil or lua == nil or lua.itemstring == nil then
return
end
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
if object:get_luaentity().itemstring ~= "" then
minetest.sound_play("item_drop_pickup", {
to_player = player:get_player_name(),
})
end
object:get_luaentity().itemstring = ""
object:remove()
else
object:setvelocity({x=0,y=0,z=0})
end
end, {player, object})

if technic.config:getBool("enable_item_pickup") then
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
if player and player:get_hp() > 0 then
local pos = player:getpos()
pos.y = pos.y+0.5
local inv = player:get_inventory()
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
if not object:is_player() and object:get_luaentity() then
local obj=object:get_luaentity()
if obj.name == "__builtin:item" then
if inv:room_for_item("main", ItemStack(obj.itemstring)) then
if obj.timer > time_pick then
inv:add_item("main", ItemStack(obj.itemstring))
if obj.itemstring ~= "" then
minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10})
end
if object:get_luaentity() then
object:get_luaentity().itemstring = ""
object:remove()
end
end

end
else
minetest.after(0.5, function(entity)
entity.collect = true
end, object:get_luaentity())
end
end
end
end
end
end
end)
end)
end

function minetest.handle_node_drops(pos, drops, digger)
for _,item in ipairs(drops) do
local count, name
if type(item) == "string" then
count = 1
name = item
else
count = item:get_count()
name = item:get_name()
end
for i=1,count do
local obj = minetest.env:add_item(pos, name)
if obj ~= nil then
obj:get_luaentity().collect = true
local x = math.random(1, 5)
if math.random(1,2) == 1 then
x = -x
end
local z = math.random(1, 5)
if math.random(1,2) == 1 then
z = -z
end
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
obj:get_luaentity().timer = time_pick
-- FIXME this doesnt work for deactiveted objects
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
obj:remove()
end, obj)
if technic.config:getBool("enable_item_drop") then
function minetest.handle_node_drops(pos, drops, digger)
for _,item in ipairs(drops) do
local count, name
if type(item) == "string" then
count = 1
name = item
else
count = item:get_count()
name = item:get_name()
end
for i=1,count do
local obj = minetest.env:add_item(pos, name)
if obj ~= nil then
obj:get_luaentity().collect = true
local x = math.random(1, 5)
if math.random(1,2) == 1 then
x = -x
end
local z = math.random(1, 5)
if math.random(1,2) == 1 then
z = -z
end
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
obj:get_luaentity().timer = time_pick
-- FIXME this doesnt work for deactiveted objects
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
obj:remove()
end, obj)
end
end
end
end
end
end

--[[
minetest.register_on_dieplayer(function(name, pos)
local inv = name:get_inventory()
Expand Down Expand Up @@ -137,4 +102,4 @@ minetest.register_on_dieplayer(function(name, pos)
end
end)
]]--
print("DROPS LOADED!")
print("DROPS LOADED!")
92 changes: 79 additions & 13 deletions item_drop/item_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ minetest.register_entity(":__builtin:item", {
itemstring = '',
physical_state = true,
timer = 0,

set_item = function(self, itemstring)
self.itemstring = itemstring
local stack = ItemStack(itemstring)
Expand Down Expand Up @@ -62,15 +62,21 @@ minetest.register_entity(":__builtin:item", {
return minetest.serialize({
itemstring = self.itemstring,
always_collect = self.always_collect,
timer = self.timer,
})
end,

on_activate = function(self, staticdata)
on_activate = function(self, staticdata, dtime_s)
if string.sub(staticdata, 1, string.len("return")) == "return" then
local data = minetest.deserialize(staticdata)
if data and type(data) == "table" then
self.itemstring = data.itemstring
self.always_collect = data.always_collect
self.timer = data.timer
if not self.timer then
self.timer = 0
end
self.timer = self.timer+dtime_s
end
else
self.itemstring = staticdata
Expand All @@ -80,18 +86,79 @@ minetest.register_entity(":__builtin:item", {
self.object:setacceleration({x=0, y=-10, z=0})
self:set_item(self.itemstring)
end,

on_step = function(self, dtime)
local time = minetest.setting_get("remove_items")
if not time then
time = 300
end
if not self.timer then
self.timer = 0
end
self.timer = self.timer + dtime
if (self.timer > 300) then
if time ~= 0 and (self.timer > time) then
self.object:remove()
end

local p = self.object:getpos()

local name = minetest.env:get_node(p).name
if name == "default:lava_flowing" or name == "default:lava_source" then
minetest.sound_play("builtin_item_lava", {pos=self.object:getpos(),gain = 1.0, max_hear_distance = 10})
self.object:remove()
return
end

if minetest.registered_nodes[name] and minetest.registered_nodes[name].liquidtype == "flowing" then
get_flowing_dir = function(self)
local pos = self.object:getpos()
local param2 = minetest.env:get_node(pos).param2
for i,d in ipairs({-1, 1, -1, 1}) do
if i<3 then
pos.x = pos.x+d
else
pos.z = pos.z+d
end

local name = minetest.env:get_node(pos).name
local par2 = minetest.env:get_node(pos).param2
if name == "default:water_flowing" and par2 < param2 then
return pos
end

if i<3 then
pos.x = pos.x-d
else
pos.z = pos.z-d
end
end
end

local vec = get_flowing_dir(self)
if vec then
local v = self.object:getvelocity()
if vec and vec.x-p.x > 0 then
self.object:setvelocity({x=0.5,y=v.y,z=0})
elseif vec and vec.x-p.x < 0 then
self.object:setvelocity({x=-0.5,y=v.y,z=0})
elseif vec and vec.z-p.z > 0 then
self.object:setvelocity({x=0,y=v.y,z=0.5})
elseif vec and vec.z-p.z < 0 then
self.object:setvelocity({x=0,y=v.y,z=-0.5})
end
self.object:setacceleration({x=0, y=-10, z=0})
self.physical_state = true
self.object:set_properties({
physical = true
})
return
end
end

p.y = p.y - 0.3
local nn = minetest.env:get_node(p).name
-- If node is not registered or node is walkably solid and resting on nodebox
local v = self.object:getvelocity()
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then
-- If node is not registered or node is walkably solid
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable then
if self.physical_state then
self.object:setvelocity({x=0,y=0,z=0})
self.object:setacceleration({x=0, y=0, z=0})
Expand All @@ -114,13 +181,12 @@ minetest.register_entity(":__builtin:item", {

on_punch = function(self, hitter)
if self.itemstring ~= '' then
local left = hitter:get_inventory():add_item("main", self.itemstring)
if not left:is_empty() then
self.itemstring = left:to_string()
return
end
hitter:get_inventory():add_item("main", self.itemstring)
end
self.object:remove()
end,
})
print("ITEM ENTITY LOADED")

if minetest.setting_get("log_mods") then
minetest.log("action", "builtin_item loaded")
end
Loading

0 comments on commit 3a37005

Please sign in to comment.