add ENTITY_NONE, ENTITY_AUTO reserved entity id & update player.set_entity(...)
This commit is contained in:
parent
f2101f6504
commit
23c66654a2
@ -27,6 +27,7 @@ inline constexpr blockid_t BLOCK_OBSTACLE = 1;
|
|||||||
inline constexpr blockid_t BLOCK_STRUCT_AIR = 2;
|
inline constexpr blockid_t BLOCK_STRUCT_AIR = 2;
|
||||||
inline constexpr itemid_t ITEM_EMPTY = 0;
|
inline constexpr itemid_t ITEM_EMPTY = 0;
|
||||||
inline constexpr entityid_t ENTITY_NONE = 0;
|
inline constexpr entityid_t ENTITY_NONE = 0;
|
||||||
|
inline constexpr entityid_t ENTITY_AUTO = std::numeric_limits<entityid_t>::max();
|
||||||
|
|
||||||
inline constexpr int CHUNK_W = 16;
|
inline constexpr int CHUNK_W = 16;
|
||||||
inline constexpr int CHUNK_H = 256;
|
inline constexpr int CHUNK_H = 256;
|
||||||
|
|||||||
@ -229,7 +229,9 @@ static int l_set_entity(lua::State* L) {
|
|||||||
if (player == nullptr) {
|
if (player == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (auto entity = get_entity(L, 2)) {
|
if (lua::isnumber(L, 2)) {
|
||||||
|
player->setEntity(lua::tointeger(L, 2));
|
||||||
|
} else if (auto entity = get_entity(L, 2)) {
|
||||||
player->setEntity(entity->getUID());
|
player->setEntity(entity->getUID());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ Player::Player(
|
|||||||
Player::~Player() = default;
|
Player::~Player() = default;
|
||||||
|
|
||||||
void Player::updateEntity() {
|
void Player::updateEntity() {
|
||||||
if (eid == 0) {
|
if (eid == ENTITY_AUTO) {
|
||||||
auto& def = level.content.entities.require("base:player");
|
auto& def = level.content.entities.require("base:player");
|
||||||
eid = level.entities->spawn(def, getPosition());
|
eid = level.entities->spawn(def, getPosition());
|
||||||
if (auto entity = level.entities->get(eid)) {
|
if (auto entity = level.entities->get(eid)) {
|
||||||
@ -73,7 +73,7 @@ void Player::updateEntity() {
|
|||||||
if (auto entity = level.entities->get(eid)) {
|
if (auto entity = level.entities->get(eid)) {
|
||||||
entity->setPlayer(id);
|
entity->setPlayer(id);
|
||||||
}
|
}
|
||||||
} else if (chunks->getChunkByVoxel(position)) {
|
} else if (chunks->getChunkByVoxel(position) && eid != ENTITY_NONE) {
|
||||||
logger.error() << "player entity despawned or deleted; "
|
logger.error() << "player entity despawned or deleted; "
|
||||||
"will be respawned";
|
"will be respawned";
|
||||||
eid = 0;
|
eid = 0;
|
||||||
|
|||||||
@ -54,7 +54,7 @@ class Player : public Serializable {
|
|||||||
bool infiniteItems = true;
|
bool infiniteItems = true;
|
||||||
bool instantDestruction = true;
|
bool instantDestruction = true;
|
||||||
bool loadingChunks = true;
|
bool loadingChunks = true;
|
||||||
entityid_t eid;
|
entityid_t eid = ENTITY_AUTO;
|
||||||
entityid_t selectedEid = 0;
|
entityid_t selectedEid = 0;
|
||||||
|
|
||||||
glm::vec3 rotation {};
|
glm::vec3 rotation {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user