New block properties and lua functions
This commit is contained in:
parent
9e1a7213c7
commit
9ebbe1029d
@ -1,7 +1,7 @@
|
||||
function on_random_update(x, y, z)
|
||||
local dirtid = block_index('base:dirt');
|
||||
if is_solid_at(x, y+1, z) then
|
||||
set_block(x, y, z, dirtid)
|
||||
set_block(x, y, z, dirtid, 0)
|
||||
else
|
||||
local grassblockid = block_index('base:grass_block')
|
||||
for lx=-1,1 do
|
||||
@ -9,7 +9,7 @@ function on_random_update(x, y, z)
|
||||
for lz=-1,1 do
|
||||
if get_block(x + lx, y + ly, z + lz) == dirtid then
|
||||
if not is_solid_at(x + lx, y + ly + 1, z + lz) then
|
||||
set_block(x + lx, y + ly, z + lz, grassblockid)
|
||||
set_block(x + lx, y + ly, z + lz, grassblockid, 0)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@ -143,6 +143,7 @@ Block* ContentLoader::loadBlock(std::string name, fs::path file) {
|
||||
root->flag("breakable", def->breakable);
|
||||
root->flag("selectable", def->selectable);
|
||||
root->flag("grounded", def->grounded);
|
||||
root->flag("hidden", def->hidden);
|
||||
root->flag("sky-light-passing", def->skyLightPassing);
|
||||
root->num("draw-group", def->drawGroup);
|
||||
|
||||
|
||||
@ -245,12 +245,15 @@ void HudRenderer::drawContentAccess(const GfxContext& ctx, Player* player) {
|
||||
GfxContext subctx = ctx.sub();
|
||||
subctx.depthTest(true);
|
||||
subctx.cullFace(true);
|
||||
uint index = 0;
|
||||
for (uint i = 0; i < count-1; i++) {
|
||||
Block* cblock = contentIds->getBlockDef(i+1);
|
||||
if (cblock == nullptr)
|
||||
break;
|
||||
int x = xs + (icon_size+interval) * (i % inv_cols);
|
||||
int y = ys + (icon_size+interval) * (i / inv_cols);
|
||||
if (cblock->hidden)
|
||||
continue;
|
||||
int x = xs + (icon_size+interval) * (index % inv_cols);
|
||||
int y = ys + (icon_size+interval) * (index / inv_cols);
|
||||
if (mx > x && mx < x + (int)icon_size && my > y && my < y + (int)icon_size) {
|
||||
tint.r *= 1.2f;
|
||||
tint.g *= 1.2f;
|
||||
@ -262,6 +265,7 @@ void HudRenderer::drawContentAccess(const GfxContext& ctx, Player* player) {
|
||||
tint = vec4(1.0f);
|
||||
}
|
||||
blocksPreview->draw(cblock, x, y, icon_size, tint);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
uiShader->use();
|
||||
@ -338,7 +342,6 @@ void HudRenderer::draw(const GfxContext& ctx){
|
||||
Block* cblock = contentIds->getBlockDef(player->chosenBlock);
|
||||
assert(cblock != nullptr);
|
||||
blocksPreview->draw(cblock, width - 56, uicamera->getFov() - 56, 48, vec4(1.0f));
|
||||
//drawBlockPreview(cblock, width - 56, uicamera->fov - 56, 48, 48, vec4(1.0f));
|
||||
}
|
||||
uishader->use();
|
||||
batch->begin();
|
||||
|
||||
@ -43,7 +43,8 @@ int l_set_block(lua_State* L) {
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int id = lua_tointeger(L, 4);
|
||||
scripting::level->chunks->set(x, y, z, id, 0);
|
||||
int states = lua_tointeger(L, 5);
|
||||
scripting::level->chunks->set(x, y, z, id, states);
|
||||
scripting::level->lighting->onBlockSet(x,y,z, id);
|
||||
return 0;
|
||||
}
|
||||
@ -74,6 +75,24 @@ int l_set_player_pos(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_states(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int states = vox == nullptr ? 0 : vox->states;
|
||||
lua_pushinteger(L, states);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_is_replaceable_at(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
|
||||
lua_pushboolean(L, scripting::level->chunks->isReplaceable(x, y, z));
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
|
||||
lua_setglobal(L, NAME))
|
||||
@ -83,8 +102,10 @@ void apilua::create_funcs(lua_State* L) {
|
||||
lua_addfunc(L, l_block_name, "block_name");
|
||||
lua_addfunc(L, l_blocks_count, "blocks_count");
|
||||
lua_addfunc(L, l_is_solid_at, "is_solid_at");
|
||||
lua_addfunc(L, l_is_replaceable_at, "is_replaceable_at");
|
||||
lua_addfunc(L, l_set_block, "set_block");
|
||||
lua_addfunc(L, l_get_block, "get_block");
|
||||
lua_addfunc(L, l_get_player_pos, "get_player_pos");
|
||||
lua_addfunc(L, l_set_player_pos, "set_player_pos");
|
||||
lua_addfunc(L, l_get_block_states, "get_block_states");
|
||||
}
|
||||
|
||||
@ -80,6 +80,7 @@ public:
|
||||
bool breakable = true;
|
||||
bool rotatable = false;
|
||||
bool grounded = false;
|
||||
bool hidden = false;
|
||||
AABB hitbox;
|
||||
BlockRotProfile rotations;
|
||||
|
||||
|
||||
@ -97,6 +97,13 @@ bool Chunks::isSolid(int x, int y, int z) {
|
||||
return contentIds->getBlockDef(v->id)->rt.solid;
|
||||
}
|
||||
|
||||
bool Chunks::isReplaceable(int x, int y, int z) {
|
||||
voxel* v = get(x, y, z);
|
||||
if (v == nullptr)
|
||||
return false;
|
||||
return contentIds->getBlockDef(v->id)->replaceable;
|
||||
}
|
||||
|
||||
ubyte Chunks::getLight(int x, int y, int z, int channel){
|
||||
x -= ox * CHUNK_W;
|
||||
z -= oz * CHUNK_D;
|
||||
|
||||
@ -55,6 +55,7 @@ public:
|
||||
|
||||
const AABB* isObstacle(float x, float y, float z);
|
||||
bool isSolid(int x, int y, int z);
|
||||
bool isReplaceable(int x, int y, int z);
|
||||
|
||||
// does not move chunks inside
|
||||
void _setOffset(int x, int z);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user