converting block states to a bitfield
This commit is contained in:
@@ -60,7 +60,7 @@ int l_set_block(lua_State* L) {
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
lua_Integer id = lua_tointeger(L, 4);
|
||||
lua_Integer states = lua_tointeger(L, 5);
|
||||
lua_Integer state = lua_tointeger(L, 5);
|
||||
bool noupdate = lua_toboolean(L, 6);
|
||||
if (id < 0 || size_t(id) >= scripting::indices->countBlockDefs()) {
|
||||
return 0;
|
||||
@@ -68,7 +68,7 @@ int l_set_block(lua_State* L) {
|
||||
if (!scripting::level->chunks->get(x, y, z)) {
|
||||
return 0;
|
||||
}
|
||||
scripting::level->chunks->set(x, y, z, id, states);
|
||||
scripting::level->chunks->set(x, y, z, id, int2blockstate(state));
|
||||
scripting::level->lighting->onBlockSet(x,y,z, id);
|
||||
if (!noupdate)
|
||||
scripting::blocks->updateSides(x, y, z);
|
||||
@@ -97,7 +97,7 @@ int l_get_block_x(lua_State* L) {
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ int l_get_block_y(lua_State* L) {
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ int l_get_block_z(lua_State* L) {
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ int l_get_block_rotation(lua_State* L) {
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int rotation = vox == nullptr ? 0 : vox->rotation();
|
||||
int rotation = vox == nullptr ? 0 : vox->state.rotation;
|
||||
lua_pushinteger(L, rotation);
|
||||
return 1;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ int l_set_block_rotation(lua_State* L) {
|
||||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
vox->setRotation(value);
|
||||
vox->state.rotation = value;
|
||||
scripting::level->chunks->getChunkByVoxel(x, y, z)->setModified(true);
|
||||
return 0;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ int l_get_block_states(lua_State* L) {
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int states = vox == nullptr ? 0 : vox->states;
|
||||
int states = vox == nullptr ? 0 : blockstate2int(vox->state);
|
||||
lua_pushinteger(L, states);
|
||||
return 1;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ int l_set_block_states(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->states = states;
|
||||
vox->state = int2blockstate(states);
|
||||
chunk->setModified(true);
|
||||
return 0;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ int l_get_block_user_bits(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
uint mask = ((1 << bits) - 1) << offset;
|
||||
uint data = (vox->states & mask) >> offset;
|
||||
uint data = (blockstate2int(vox->state) & mask) >> offset;
|
||||
lua_pushinteger(L, data);
|
||||
return 1;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ int l_set_block_user_bits(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
lua_Integer offset = lua_tointeger(L, 4) + VOXEL_USER_BITS_OFFSET;
|
||||
lua_Integer offset = lua_tointeger(L, 4);
|
||||
lua_Integer bits = lua_tointeger(L, 5);
|
||||
|
||||
size_t mask = ((1 << bits) - 1) << offset;
|
||||
@@ -218,7 +218,7 @@ int l_set_block_user_bits(lua_State* L) {
|
||||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
vox->states = (vox->states & (~mask)) | value;
|
||||
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user