add falling_block entity
This commit is contained in:
parent
277155e3d1
commit
f7d0ec438f
@ -1,6 +1,8 @@
|
||||
{
|
||||
"items": [
|
||||
"bazalt_breaker"
|
||||
"entities": [
|
||||
"drop",
|
||||
"player",
|
||||
"falling_block"
|
||||
],
|
||||
"blocks": [
|
||||
"dirt",
|
||||
@ -28,8 +30,7 @@
|
||||
"torch",
|
||||
"wooden_door"
|
||||
],
|
||||
"entities": [
|
||||
"drop",
|
||||
"player"
|
||||
"items": [
|
||||
"bazalt_breaker"
|
||||
]
|
||||
}
|
||||
@ -6,7 +6,5 @@
|
||||
"sensors": [
|
||||
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2],
|
||||
["radius", 1.6]
|
||||
],
|
||||
"save-rig-textures": true,
|
||||
"save-rig-pose": true
|
||||
]
|
||||
}
|
||||
|
||||
7
res/content/base/entities/falling_block.json
Normal file
7
res/content/base/entities/falling_block.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"components": [
|
||||
"falling_block"
|
||||
],
|
||||
"rig-name": "base:block",
|
||||
"hitbox": [0.4, 0.4, 0.4]
|
||||
}
|
||||
48
res/content/base/models/block.obj
Normal file
48
res/content/base/models/block.obj
Normal file
@ -0,0 +1,48 @@
|
||||
o Cube
|
||||
v 0.5 -0.5 -0.5
|
||||
v 0.5 -0.5 0.5
|
||||
v -0.5 -0.5 0.5
|
||||
v -0.5 -0.5 -0.5
|
||||
v 0.5 0.5 -0.5
|
||||
v 0.5 0.5 0.5
|
||||
v -0.5 0.5 0.5
|
||||
v -0.5 0.5 -0.5
|
||||
vt 0.0 0.0
|
||||
vt 1.0 0.0
|
||||
vt 1.0 1.0
|
||||
vt 0.0 1.0
|
||||
vt 0.0 0.0
|
||||
vt 1.0 0.0
|
||||
vt 1.0 1.0
|
||||
vt 0.0 1.0
|
||||
vt 1.0 0.0
|
||||
vt 1.0 1.0
|
||||
vt 0.0 0.0
|
||||
vt 1.0 0.0
|
||||
vt 0.0 1.0
|
||||
vt 0.0 0.0
|
||||
vt 0.0 1.0
|
||||
vt 1.0 0.0
|
||||
vt 1.0 1.0
|
||||
vt 1.0 1.0
|
||||
vt 0.0 1.0
|
||||
vt 0.0 0.0
|
||||
vn 0.0 -1.0 0.0
|
||||
vn 0.0 1.0 0.0
|
||||
vn 1.0 -0.0 0.0
|
||||
vn -1.0 -0.0 -0.0
|
||||
vn 0.0 0.0 -1.0
|
||||
vn -0.0 -0.0 1.0
|
||||
usemtl $2
|
||||
s off
|
||||
f 1/1/1 2/2/1 3/3/1 4/4/1
|
||||
usemtl $3
|
||||
f 5/5/2 8/6/2 7/7/2 6/8/2
|
||||
usemtl $0
|
||||
f 1/9/3 5/10/3 6/8/3 2/11/3
|
||||
usemtl $1
|
||||
f 3/12/4 7/7/4 8/13/4 4/14/4
|
||||
usemtl $4
|
||||
f 5/15/5 1/1/5 4/16/5 8/17/5
|
||||
usemtl $5
|
||||
f 2/2/6 6/18/6 7/19/6 3/20/6
|
||||
@ -5,6 +5,7 @@
|
||||
"events/pickup"
|
||||
],
|
||||
"models": [
|
||||
"block",
|
||||
"drop-block",
|
||||
"drop-item"
|
||||
]
|
||||
|
||||
5
res/content/base/rigs/block.json
Normal file
5
res/content/base/rigs/block.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"root": {
|
||||
"model": "block"
|
||||
}
|
||||
}
|
||||
31
res/content/base/scripts/components/falling_block.lua
Normal file
31
res/content/base/scripts/components/falling_block.lua
Normal file
@ -0,0 +1,31 @@
|
||||
local tsf = entity.transform
|
||||
local body = entity.rigidbody
|
||||
local rig = entity.modeltree
|
||||
|
||||
ARGS = ARGS or {}
|
||||
local blockid = ARGS.block
|
||||
if SAVED_DATA.block then
|
||||
blockid = SAVED_DATA.block
|
||||
else
|
||||
SAVED_DATA.block = blockid
|
||||
end
|
||||
|
||||
do -- setup visuals
|
||||
local textures = block.get_textures(block.index(blockid))
|
||||
for i,t in ipairs(textures) do
|
||||
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
|
||||
end
|
||||
end
|
||||
|
||||
function on_grounded()
|
||||
local pos = tsf:get_pos()
|
||||
local ix = math.floor(pos[1])
|
||||
local iy = math.floor(pos[2])
|
||||
local iz = math.floor(pos[3])
|
||||
if block.is_replaceable_at(ix, iy, iz) then
|
||||
block.set(ix, iy, iz, block.index(blockid))
|
||||
else
|
||||
entities.spawn("base:drop", pos, {item={id=item.index(blockid..".item"), count=1}})
|
||||
end
|
||||
entity:despawn()
|
||||
end
|
||||
14
res/content/base/scripts/sand.lua
Normal file
14
res/content/base/scripts/sand.lua
Normal file
@ -0,0 +1,14 @@
|
||||
local function update(x, y, z)
|
||||
if block.is_replaceable_at(x, y-1, z) then
|
||||
entities.spawn("base:falling_block", {x+0.5, y+0.5, z+0.5}, {block='base:sand'})
|
||||
block.set(x, y, z, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function on_update(x, y, z)
|
||||
update(x, y, z)
|
||||
end
|
||||
|
||||
function on_placed(x, y, z)
|
||||
update(x, y, z)
|
||||
end
|
||||
@ -344,6 +344,8 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
|
||||
if (auto bodyType = BodyType_from(bodyTypeName)) {
|
||||
def.bodyType = *bodyType;
|
||||
}
|
||||
|
||||
root->str("rig-name", def.rigName);
|
||||
}
|
||||
|
||||
void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const std::string& name) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user