mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
add signal & fix
This commit is contained in:
parent
970ae6dab5
commit
b2735d8068
2 changed files with 51 additions and 12 deletions
|
|
@ -146,8 +146,8 @@ 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),
|
||||
s = lua_tointeger(L, 5);
|
||||
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;
|
||||
|
|
@ -157,20 +157,39 @@ int l_get_block_custom_value(lua_State* L) {
|
|||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
bool state = vox->getCustomValue();
|
||||
lua_pushboolean(L, state);
|
||||
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, 5);
|
||||
v = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setCustomValue(v);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
|
||||
lua_setglobal(L, NAME))
|
||||
|
|
@ -195,4 +214,6 @@ void apilua::create_funcs(lua_State* L) {
|
|||
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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,28 +10,39 @@ const int BLOCK_DIR_EAST = 0x3;
|
|||
const int BLOCK_DIR_UP = 0x4;
|
||||
const int BLOCK_DIR_DOWN = 0x5;
|
||||
|
||||
// limited to 16 block orientations
|
||||
const int BLOCK_ROT_MASK = 0xF;
|
||||
// limited to 8 block orientations
|
||||
const int BLOCK_DIR_MASK = 0x7;
|
||||
|
||||
const int BLOCK_SIG_MASK = 0x8;
|
||||
|
||||
// limited to 16 block variants
|
||||
const int BLOCK_VARIANT_MASK = 0xF0;
|
||||
|
||||
//
|
||||
// |* * * * * * * * * * * * * * * *|* * *|*|* * * *|* * * *|*'*'*'*|
|
||||
// id dir/ \variant value state
|
||||
// |sig|
|
||||
//
|
||||
|
||||
struct voxel {
|
||||
blockid_t id;
|
||||
u_short16 states;
|
||||
|
||||
inline u_char8 getDir() const {
|
||||
return states & BLOCK_ROT_MASK;
|
||||
return states & BLOCK_DIR_MASK;
|
||||
}
|
||||
|
||||
inline void setDir(u_char8 dir) {
|
||||
states &= ~BLOCK_ROT_MASK;
|
||||
states &= ~BLOCK_DIR_MASK;
|
||||
states |= dir;
|
||||
}
|
||||
|
||||
//todo: fix this
|
||||
inline u_char8 getVariant() const {
|
||||
return states & BLOCK_VARIANT_MASK;
|
||||
}
|
||||
|
||||
//todo: fix this
|
||||
inline void setVariant(u_char8 variant) {
|
||||
states &= ~BLOCK_VARIANT_MASK;
|
||||
states |= variant;
|
||||
|
|
@ -51,9 +62,7 @@ struct voxel {
|
|||
}
|
||||
}
|
||||
|
||||
/* if the block has a custom state you
|
||||
can use value in range 0 to 15 else
|
||||
you can use value in range 0 to 255 */
|
||||
// can use value in range 0 to 15
|
||||
inline u_char8 getCustomValue() const {
|
||||
return states >> 20;
|
||||
}
|
||||
|
|
@ -65,6 +74,15 @@ struct voxel {
|
|||
states &= ~(0xF << 20);
|
||||
states |= (value << 20);
|
||||
}
|
||||
|
||||
inline bool getSig() const {
|
||||
return states & BLOCK_SIG_MASK;
|
||||
}
|
||||
|
||||
inline void setSig(bool sig) {
|
||||
states &= ~BLOCK_SIG_MASK;
|
||||
states |= sig;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* VOXELS_VOXEL_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue