update base:drop component
This commit is contained in:
parent
51eadd397c
commit
b3ac1bd8f4
@ -1,10 +1,10 @@
|
|||||||
local base_entities = {}
|
local base_entities = {}
|
||||||
|
|
||||||
function base_entities.drop(ppos, itemid, count, ready)
|
function base_entities.drop(ppos, itemid, count, pickup_delay)
|
||||||
return entities.spawn("base:drop", ppos, {base__drop={
|
return entities.spawn("base:drop", ppos, {base__drop={
|
||||||
id=itemid,
|
id=itemid,
|
||||||
count=count,
|
count=count,
|
||||||
ready=ready
|
pickup_delay=pickup_delay
|
||||||
}})
|
}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,11 @@ local rig = entity.skeleton
|
|||||||
|
|
||||||
inair = true
|
inair = true
|
||||||
target = -1
|
target = -1
|
||||||
ready = false
|
timer = 0.3
|
||||||
|
|
||||||
local dropitem = ARGS
|
local dropitem = ARGS
|
||||||
if dropitem then
|
if dropitem then
|
||||||
ready = dropitem.ready
|
timer = dropitem.pickup_delay or timer
|
||||||
end
|
end
|
||||||
if SAVED_DATA.item then
|
if SAVED_DATA.item then
|
||||||
dropitem.id = item.index(SAVED_DATA.item)
|
dropitem.id = item.index(SAVED_DATA.item)
|
||||||
@ -43,7 +43,6 @@ function on_grounded(force)
|
|||||||
mat4.scale(matrix, scale, matrix)
|
mat4.scale(matrix, scale, matrix)
|
||||||
rig:set_matrix(0, matrix)
|
rig:set_matrix(0, matrix)
|
||||||
inair = false
|
inair = false
|
||||||
ready = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_fall()
|
function on_fall()
|
||||||
@ -53,12 +52,12 @@ end
|
|||||||
function on_sensor_enter(index, oid)
|
function on_sensor_enter(index, oid)
|
||||||
local playerid = hud.get_player()
|
local playerid = hud.get_player()
|
||||||
local playerentity = player.get_entity(playerid)
|
local playerentity = player.get_entity(playerid)
|
||||||
if ready and oid == playerentity and index == 0 then
|
if timer < 0.0 and oid == playerentity and index == 0 then
|
||||||
entity:despawn()
|
entity:despawn()
|
||||||
inventory.add(player.get_inventory(playerid), dropitem.id, dropitem.count)
|
inventory.add(player.get_inventory(playerid), dropitem.id, dropitem.count)
|
||||||
audio.play_sound_2d("events/pickup", 0.5, 0.8+math.random()*0.4, "regular")
|
audio.play_sound_2d("events/pickup", 0.5, 0.8+math.random()*0.4, "regular")
|
||||||
end
|
end
|
||||||
if index == 1 and ready and oid == playerentity then
|
if index == 1 and oid == playerentity then
|
||||||
target = oid
|
target = oid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -83,8 +82,12 @@ function on_render()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_update()
|
function on_update(tps)
|
||||||
|
timer = timer - 1.0/tps
|
||||||
if target ~= -1 then
|
if target ~= -1 then
|
||||||
|
if timer > 0.0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos())
|
local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos())
|
||||||
vec3.normalize(dir, dir)
|
vec3.normalize(dir, dir)
|
||||||
vec3.mul(dir, 10.0, dir)
|
vec3.mul(dir, 10.0, dir)
|
||||||
|
|||||||
@ -19,7 +19,7 @@ function on_hud_open()
|
|||||||
local pvel = {player.get_vel(pid)}
|
local pvel = {player.get_vel(pid)}
|
||||||
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
||||||
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
||||||
local drop = base_util.drop(ppos, itemid, 1)
|
local drop = base_util.drop(ppos, itemid, 1, 1.5)
|
||||||
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
||||||
drop.rigidbody:set_vel(velocity)
|
drop.rigidbody:set_vel(velocity)
|
||||||
end)
|
end)
|
||||||
|
|||||||
12
res/scripts/post_content.lua
Normal file
12
res/scripts/post_content.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function make_read_only(t)
|
||||||
|
setmetatable(t, {
|
||||||
|
__newindex = function()
|
||||||
|
error("table is read-only")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
make_read_only(block.properties)
|
||||||
|
for k,v in pairs(block.properties) do
|
||||||
|
make_read_only(v)
|
||||||
|
end
|
||||||
@ -195,6 +195,7 @@ void scripting::on_content_load(Content* content) {
|
|||||||
lua::setfield(L, "properties");
|
lua::setfield(L, "properties");
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
|
load_script(fs::path("post_content.lua"), true);
|
||||||
load_script(fs::path("stdcmd.lua"), true);
|
load_script(fs::path("stdcmd.lua"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user