From: RealBadAngel Date: Mon, 8 Apr 2013 21:52:20 +0000 (+0200) Subject: Updated item_drop (now as modpack component) X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=e139fff8fb4bcbe003da60094a6f12aa553cd508;p=zefram%2Fminetest%2Ftechnic.git Updated item_drop (now as modpack component) --- diff --git a/item_drop/README.txt b/item_drop/README.txt new file mode 100644 index 0000000..fe43054 --- /dev/null +++ b/item_drop/README.txt @@ -0,0 +1,42 @@ +===ITEM_DROP MOD for MINETEST-C55=== +by PilzAdam + +Introduction: +This mod adds Minecraft like drop/pick up of items to Minetest. + +How to install: +Unzip the archive an place it in minetest-base-directory/mods/minetest/ +if you have a windows client or a linux run-in-place client. If you have +a linux system-wide instalation place it in ~/.minetest/mods/minetest/. +If you want to install this mod only in one world create the folder +worldmods/ in your worlddirectory. +For further information or help see: +http://wiki.minetest.com/wiki/Installing_Mods + +How to use the mod: +Just install it an everything works. + +For developers: +You dont have to use get_drops() anymore because of changes in the +builtin files of minetest. + +License: +Sourcecode: WTFPL (see below) +Sound: WTFPL (see below) + +See also: +http://minetest.net/ + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/item_drop/init.lua b/item_drop/init.lua new file mode 100644 index 0000000..8cd3b14 --- /dev/null +++ b/item_drop/init.lua @@ -0,0 +1,140 @@ +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}) + end + + end + else + minetest.after(0.5, function(entity) + entity.collect = true + end, object:get_luaentity()) + 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) + end + end + end + end +end +--[[ +minetest.register_on_dieplayer(function(name, pos) + local inv = name:get_inventory() + local pos = name:getpos() + for i = 1, inv:get_size("main"), 1 do + srcstack = inv:get_stack("main", i) + if srcstack:to_string() ~= "" then + pos.y = pos.y + 3 + local obj = minetest.env:add_item(pos, srcstack:to_string()) + local x = math.random(-5, 5) + if x >= -2 and x <=0 then + local x = x - 3 + end + if x > 0 and x <= 2 then + local x = x + 3 + end + local y = math.random(3, 5) + local z = math.random(-5, 5) + if z >= -2 and z <= 0 then + local z = z - 3 + end + if z > 0 and z <= 2 then + local z = z + 3 + end + inv:set_stack("main", i, "") + obj:setvelocity({x=x, y=y, z=z}) + end + if i == 32 then + break + end + end +end) +]]-- +print("DROPS LOADED!") \ No newline at end of file diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua new file mode 100644 index 0000000..6e479a1 --- /dev/null +++ b/item_drop/item_entity.lua @@ -0,0 +1,126 @@ +-- Minetest: builtin/item_entity.lua + +function minetest.spawn_item(pos, item) + -- Take item in any format + local stack = ItemStack(item) + local obj = minetest.env:add_entity(pos, "__builtin:item") + obj:get_luaentity():set_item(stack:to_string()) + return obj +end + +minetest.register_entity(":__builtin:item", { + initial_properties = { + hp_max = 1, + physical = true, + collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, + visual = "sprite", + visual_size = {x=0.5, y=0.5}, + textures = {""}, + spritediv = {x=1, y=1}, + initial_sprite_basepos = {x=0, y=0}, + is_visible = false, + }, + + itemstring = '', + physical_state = true, + timer = 0, + + set_item = function(self, itemstring) + self.itemstring = itemstring + local stack = ItemStack(itemstring) + local itemtable = stack:to_table() + local itemname = nil + if itemtable then + itemname = stack:to_table().name + end + local item_texture = nil + local item_type = "" + if minetest.registered_items[itemname] then + item_texture = minetest.registered_items[itemname].inventory_image + item_type = minetest.registered_items[itemname].type + end + prop = { + is_visible = true, + visual = "sprite", + textures = {"unknown_item.png"} + } + if item_texture and item_texture ~= "" then + prop.visual = "sprite" + prop.textures = {item_texture} + prop.visual_size = {x=0.50, y=0.50} + else + prop.visual = "wielditem" + prop.textures = {itemname} + prop.visual_size = {x=0.20, y=0.20} + prop.automatic_rotate = math.pi * 0.25 + end + self.object:set_properties(prop) + end, + + get_staticdata = function(self) + --return self.itemstring + return minetest.serialize({ + itemstring = self.itemstring, + always_collect = self.always_collect, + }) + end, + + on_activate = function(self, staticdata) + 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 + end + else + self.itemstring = staticdata + end + self.object:set_armor_groups({immortal=1}) + self.object:setvelocity({x=0, y=2, z=0}) + self.object:setacceleration({x=0, y=-10, z=0}) + self:set_item(self.itemstring) + end, + + on_step = function(self, dtime) + self.timer = self.timer + dtime + if (self.timer > 300) then + self.object:remove() + end + local p = self.object:getpos() + 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 self.physical_state then + self.object:setvelocity({x=0,y=0,z=0}) + self.object:setacceleration({x=0, y=0, z=0}) + self.physical_state = false + self.object:set_properties({ + physical = false + }) + end + else + if not self.physical_state then + self.object:setvelocity({x=0,y=0,z=0}) + self.object:setacceleration({x=0, y=-10, z=0}) + self.physical_state = true + self.object:set_properties({ + physical = true + }) + end + end + end, + + 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 + end + self.object:remove() + end, +}) +print("ITEM ENTITY LOADED") diff --git a/technic/config.lua b/technic/config.lua index c921981..f237968 100644 --- a/technic/config.lua +++ b/technic/config.lua @@ -1,5 +1,3 @@ -enable_item_drop=false -enable_item_pickup=true enable_technic_inventory=true enable_mining_drill=true enable_mining_laser=true diff --git a/technic/init.lua b/technic/init.lua index 99284a3..58e0488 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -50,9 +50,6 @@ dofile(modpath.."/deployer.lua") dofile(modpath.."/constructor.lua") dofile(modpath.."/frames.lua") -if enable_item_drop then dofile(modpath.."/item_drop.lua") end -if enable_item_pickup then dofile(modpath.."/item_pickup.lua") end - function has_locked_chest_privilege(meta, player) if player:get_player_name() ~= meta:get_string("owner") then return false diff --git a/technic/item_drop.lua b/technic/item_drop.lua deleted file mode 100644 index 3165e6a..0000000 --- a/technic/item_drop.lua +++ /dev/null @@ -1,100 +0,0 @@ --- This part written by PilzAdam (item_drop mod) - -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 and 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() - end - end - end - - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do - if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then - if object:get_luaentity().collect then - if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) 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}) - - 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}) - - -- 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 - -if minetest.setting_get("log_mods") then - minetest.log("action", "item_drop loaded") -end diff --git a/technic/item_pickup.lua b/technic/item_pickup.lua deleted file mode 100644 index 04ed0f8..0000000 --- a/technic/item_pickup.lua +++ /dev/null @@ -1,63 +0,0 @@ -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 - 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 - - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do - if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then - if object:get_luaentity().collect then - if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) 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}) - - end - else - minetest.after(0.5, function(entity) - entity.collect = true - end, object:get_luaentity()) - end - end - end - end -end) diff --git a/technic/water_mill.lua b/technic/water_mill.lua index fca52bb..52966ed 100644 --- a/technic/water_mill.lua +++ b/technic/water_mill.lua @@ -4,7 +4,7 @@ minetest.register_craft({ output = 'technic:water_mill', recipe = { {'default:stone', 'default:stone', 'default:stone'}, - {'default:wood', 'technic:diamond', 'default:wood'}, + {'default:wood', 'default:diamond', 'default:wood'}, {'default:stone', 'moreores:copper_ingot', 'default:stone'}, } })