update base:drop component
This commit is contained in:
parent
51eadd397c
commit
b3ac1bd8f4
@ -1,10 +1,10 @@
|
||||
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={
|
||||
id=itemid,
|
||||
count=count,
|
||||
ready=ready
|
||||
pickup_delay=pickup_delay
|
||||
}})
|
||||
end
|
||||
|
||||
|
||||
@ -4,11 +4,11 @@ local rig = entity.skeleton
|
||||
|
||||
inair = true
|
||||
target = -1
|
||||
ready = false
|
||||
timer = 0.3
|
||||
|
||||
local dropitem = ARGS
|
||||
if dropitem then
|
||||
ready = dropitem.ready
|
||||
timer = dropitem.pickup_delay or timer
|
||||
end
|
||||
if SAVED_DATA.item then
|
||||
dropitem.id = item.index(SAVED_DATA.item)
|
||||
@ -43,7 +43,6 @@ function on_grounded(force)
|
||||
mat4.scale(matrix, scale, matrix)
|
||||
rig:set_matrix(0, matrix)
|
||||
inair = false
|
||||
ready = true
|
||||
end
|
||||
|
||||
function on_fall()
|
||||
@ -53,12 +52,12 @@ end
|
||||
function on_sensor_enter(index, oid)
|
||||
local playerid = hud.get_player()
|
||||
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()
|
||||
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")
|
||||
end
|
||||
if index == 1 and ready and oid == playerentity then
|
||||
if index == 1 and oid == playerentity then
|
||||
target = oid
|
||||
end
|
||||
end
|
||||
@ -83,8 +82,12 @@ function on_render()
|
||||
end
|
||||
end
|
||||
|
||||
function on_update()
|
||||
function on_update(tps)
|
||||
timer = timer - 1.0/tps
|
||||
if target ~= -1 then
|
||||
if timer > 0.0 then
|
||||
return
|
||||
end
|
||||
local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos())
|
||||
vec3.normalize(dir, dir)
|
||||
vec3.mul(dir, 10.0, dir)
|
||||
|
||||
@ -19,7 +19,7 @@ function on_hud_open()
|
||||
local pvel = {player.get_vel(pid)}
|
||||
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
||||
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))
|
||||
drop.rigidbody:set_vel(velocity)
|
||||
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::pop(L);
|
||||
}
|
||||
load_script(fs::path("post_content.lua"), true);
|
||||
load_script(fs::path("stdcmd.lua"), true);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user