mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
Merge branch 'voxel-upd' into vixel-upd-2
This commit is contained in:
commit
d9e1d353d5
36 changed files with 498 additions and 286 deletions
|
|
@ -57,7 +57,7 @@ void BlocksController::updateSides(int x, int y, int z) {
|
|||
}
|
||||
|
||||
void BlocksController::breakBlock(Player* player, const Block* def, int x, int y, int z) {
|
||||
chunks->set(x,y,z, 0, 0);
|
||||
chunks->set(x,y,z, voxel{0,0});
|
||||
lighting->onBlockSet(x,y,z, 0);
|
||||
if (def->rt.funcsset.onbroken) {
|
||||
scripting::on_block_broken(player, def, x, y, z);
|
||||
|
|
@ -75,7 +75,11 @@ void BlocksController::updateBlock(int x, int y, int z) {
|
|||
return;
|
||||
}
|
||||
if (def->rt.funcsset.update) {
|
||||
int states = vox->states;
|
||||
int id = vox->id;
|
||||
scripting::update_block(def, x, y, z);
|
||||
if (states != vox->states || id!= vox->id)
|
||||
updateSides(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -236,27 +236,27 @@ void PlayerController::updateInteraction(){
|
|||
int x = iend.x;
|
||||
int y = iend.y;
|
||||
int z = iend.z;
|
||||
uint8_t states = 0;
|
||||
voxel voxel;
|
||||
|
||||
Block* def = contentIds->getBlockDef(player->chosenBlock);
|
||||
if (def->rotatable){
|
||||
const std::string& name = def->rotations.name;
|
||||
if (name == "pipe") {
|
||||
if (norm.x < 0.0f) states = BLOCK_DIR_WEST;
|
||||
else if (norm.x > 0.0f) states = BLOCK_DIR_EAST;
|
||||
else if (norm.y > 0.0f) states = BLOCK_DIR_UP;
|
||||
else if (norm.y < 0.0f) states = BLOCK_DIR_DOWN;
|
||||
else if (norm.z > 0.0f) states = BLOCK_DIR_NORTH;
|
||||
else if (norm.z < 0.0f) states = BLOCK_DIR_SOUTH;
|
||||
if (norm.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
|
||||
else if (norm.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
|
||||
else if (norm.y > 0.0f) voxel.setDir(BLOCK_DIR_UP);
|
||||
else if (norm.y < 0.0f) voxel.setDir(BLOCK_DIR_DOWN);
|
||||
else if (norm.z > 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
|
||||
else if (norm.z < 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
|
||||
} else if (name == "pane") {
|
||||
glm::vec3 vec = camera->dir;
|
||||
if (abs(vec.x) > abs(vec.z)){
|
||||
if (vec.x > 0.0f) states = BLOCK_DIR_EAST;
|
||||
if (vec.x < 0.0f) states = BLOCK_DIR_WEST;
|
||||
if (vec.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
|
||||
if (vec.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
|
||||
}
|
||||
if (abs(vec.x) < abs(vec.z)){
|
||||
if (vec.z > 0.0f) states = BLOCK_DIR_SOUTH;
|
||||
if (vec.z < 0.0f) states = BLOCK_DIR_NORTH;
|
||||
if (vec.z > 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
|
||||
if (vec.z < 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -285,7 +285,8 @@ void PlayerController::updateInteraction(){
|
|||
chosenBlock = 0;
|
||||
}
|
||||
if (chosenBlock != vox->id) {
|
||||
chunks->set(x, y, z, chosenBlock, states);
|
||||
voxel.id = chosenBlock;
|
||||
chunks->set(x, y, z, voxel);
|
||||
lighting->onBlockSet(x,y,z, chosenBlock);
|
||||
if (def->rt.funcsset.onplaced) {
|
||||
scripting::on_block_placed(player, def, x, y, z);
|
||||
|
|
@ -299,6 +300,7 @@ void PlayerController::updateInteraction(){
|
|||
player->chosenBlock = chunks->get(x,y,z)->id;
|
||||
}
|
||||
} else {
|
||||
player->selectedVoxel = voxel{0, 0};
|
||||
selectedBlockId = -1;
|
||||
selectedBlockStates = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,13 +39,14 @@ int l_block_index(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_set_block(lua_State* L) {
|
||||
voxel voxel;
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int id = lua_tointeger(L, 4);
|
||||
int states = lua_tointeger(L, 5);
|
||||
scripting::level->chunks->set(x, y, z, id, states);
|
||||
scripting::level->lighting->onBlockSet(x,y,z, id);
|
||||
voxel.id = lua_tointeger(L, 4);
|
||||
voxel.states = lua_tointeger(L, 5);
|
||||
scripting::level->chunks->set(x, y, z, voxel);
|
||||
scripting::level->lighting->onBlockSet(x,y,z, voxel.id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -66,57 +67,6 @@ inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
int l_get_block_x(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_y(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_z(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_player_pos(lua_State* L) {
|
||||
glm::vec3 pos = scripting::level->player->hitbox->position;
|
||||
lua_pushnumber(L, pos.x);
|
||||
|
|
@ -149,6 +99,7 @@ int l_set_player_pos(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// old functions, not recommended to use
|
||||
int l_get_block_states(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
|
|
@ -159,41 +110,6 @@ int l_get_block_states(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int l_get_block_user_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4) + VOXEL_USER_BITS_OFFSET;
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
lua_pushinteger(L, 0);
|
||||
return 1;
|
||||
}
|
||||
uint mask = ((1 << bits) - 1) << offset;
|
||||
uint data = (vox->states & mask) >> offset;
|
||||
lua_pushinteger(L, data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block_user_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4) + VOXEL_USER_BITS_OFFSET;
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
uint mask = (1 << bits) - 1;
|
||||
int value = lua_tointeger(L, 6) & mask;
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
vox->states = (vox->states & (~mask)) | (value << offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_is_replaceable_at(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
|
|
@ -204,6 +120,172 @@ int l_is_replaceable_at(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int l_get_block_dir(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int states = vox->getDir();
|
||||
lua_pushinteger(L, states);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_dir(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
s = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setDir(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_sig(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
bool sig = vox->getSig();
|
||||
lua_pushboolean(L, sig);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_sig(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
bool s = lua_toboolean(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setSig(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_custom_state(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
i = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
bool state = vox->getCustomState(i);
|
||||
lua_pushboolean(L, state);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_state(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
i = lua_tointeger(L, 4);
|
||||
bool s = lua_toboolean(L, 5);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setCustomState(i, s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_custom_value(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int state = vox->getCustomValue();
|
||||
lua_pushinteger(L, state);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_value(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
v = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setCustomValue(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// for specific modes
|
||||
int l_get_block_custom_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4);
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr)
|
||||
lua_pushinteger(L, 0);
|
||||
else
|
||||
lua_pushinteger(L, vox->getCustomBits(offset, bits));
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4);
|
||||
int bits = lua_tointeger(L, 5);
|
||||
int value = lua_tointeger(L, 6);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox != nullptr)
|
||||
vox->setCustomBits(offset, bits, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
lua_pushinteger(L, z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int l_get_block_x(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
int l_get_block_y(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
int l_get_block_z(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);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
|
||||
lua_setglobal(L, NAME))
|
||||
|
||||
|
|
@ -222,7 +304,20 @@ void apilua::create_funcs(lua_State* L) {
|
|||
lua_addfunc(L, l_set_player_pos, "set_player_pos");
|
||||
lua_addfunc(L, l_get_player_rot, "get_player_rot");
|
||||
lua_addfunc(L, l_set_player_rot, "set_player_rot");
|
||||
lua_addfunc(L, l_get_block_states, "get_block_states");
|
||||
lua_addfunc(L, l_get_block_user_bits, "get_block_user_bits");
|
||||
lua_addfunc(L, l_set_block_user_bits, "set_block_user_bits");
|
||||
|
||||
lua_addfunc(L, l_get_block_states, "get_block_states"); // old function
|
||||
|
||||
lua_addfunc(L, l_get_block_dir, "get_block_dir");
|
||||
lua_addfunc(L, l_set_block_dir, "set_block_dir");
|
||||
lua_addfunc(L, l_get_block_custom_state, "get_block_custom_state");
|
||||
lua_addfunc(L, l_set_block_custom_state, "set_block_custom_state");
|
||||
lua_addfunc(L, l_get_block_custom_value, "get_block_custom_value");
|
||||
lua_addfunc(L, l_set_block_custom_value, "set_block_custom_value");
|
||||
lua_addfunc(L, l_get_block_sig, "get_block_sig");
|
||||
lua_addfunc(L, l_set_block_sig, "set_block_sig");
|
||||
lua_addfunc(L, l_get_block_x, "get_block_X");
|
||||
lua_addfunc(L, l_get_block_y, "get_block_Y");
|
||||
lua_addfunc(L, l_get_block_z, "get_block_Z");
|
||||
lua_addfunc(L, l_get_block_custom_bits, "get_block_custom_bits");
|
||||
lua_addfunc(L, l_set_block_custom_bits, "set_block_custom_bits");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue