add player.is_infinite_items, .set_infinite_items

This commit is contained in:
MihailRis 2024-11-20 13:19:49 +03:00
parent f4f479d389
commit 14b596140d
6 changed files with 54 additions and 4 deletions

View File

@ -56,12 +56,19 @@ player.set_noclip(bool)
Getter and setter for player noclip mode (collisions disabled)
```lua
player.is_infinite_items() -> bool
player.set_infinite_items(bool)
```
Getter and setter for infinite items (not removed from inventory after use)
``` lua
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number
```
Point setter and getter added by player
Spawn point setter and getter
```lua
player.get_selected_block(playerid: int) -> x,y,z

View File

@ -56,6 +56,13 @@ player.set_noclip(bool)
Геттер и сеттер noclip режима (выключенная коллизия игрока)
```lua
player.is_infinite_items() -> bool
player.set_infinite_items(bool)
```
Геттер и сеттер бесконечных предметов (не удаляются из инвентаря при использовании)
```lua
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number

View File

@ -461,6 +461,10 @@ void PlayerController::processRightClick(const Block& def, const Block& target)
}
}
if (chosenBlock != vox->id && chosenBlock) {
if (!player->isInfiniteItems()) {
auto& slot = player->getInventory()->getSlot(player->getChosenSlot());
slot.setCount(slot.getCount()-1);
}
blocksController->placeBlock(
player.get(), def, state, coord.x, coord.y, coord.z
);
@ -522,8 +526,8 @@ void PlayerController::updateInteraction(float delta) {
auto iend = selection.position;
if (lclick && !input.shift && item.rt.funcsset.on_block_break_by) {
if (scripting::on_item_break_block(
player.get(), item, iend.x, iend.y, iend.z
)) {
player.get(), item, iend.x, iend.y, iend.z
)) {
return;
}
}

View File

@ -128,6 +128,20 @@ static int l_set_noclip(lua::State* L) {
return 0;
}
static int l_is_infinite_items(lua::State* L) {
if (auto player = get_player(L, 1)) {
return lua::pushboolean(L, player->isInfiniteItems());
}
return 0;
}
static int l_set_infinite_items(lua::State* L) {
if (auto player = get_player(L, 1)) {
player->setInfiniteItems(lua::toboolean(L, 2));
}
return 0;
}
static int l_get_selected_block(lua::State* L) {
if (auto player = get_player(L, 1)) {
if (player->selection.vox.id == BLOCK_VOID) {
@ -220,6 +234,8 @@ const luaL_Reg playerlib[] = {
{"set_flight", lua::wrap<l_set_flight>},
{"is_noclip", lua::wrap<l_is_noclip>},
{"set_noclip", lua::wrap<l_set_noclip>},
{"is_infinite_items", lua::wrap<l_is_infinite_items>},
{"set_infinite_items", lua::wrap<l_set_infinite_items>},
{"get_selected_block", lua::wrap<l_get_selected_block>},
{"get_selected_entity", lua::wrap<l_get_selected_entity>},
{"set_spawnpoint", lua::wrap<l_set_spawnpoint>},
@ -228,4 +244,5 @@ const luaL_Reg playerlib[] = {
{"set_entity", lua::wrap<l_set_entity>},
{"get_camera", lua::wrap<l_get_camera>},
{"set_camera", lua::wrap<l_set_camera>},
{NULL, NULL}};
{NULL, NULL}
};

View File

@ -240,6 +240,14 @@ void Player::setNoclip(bool flag) {
this->noclip = flag;
}
bool Player::isInfiniteItems() const {
return infiniteItems;
}
void Player::setInfiniteItems(bool flag) {
infiniteItems = flag;
}
entityid_t Player::getEntity() const {
return eid;
}
@ -273,6 +281,7 @@ dv::value Player::serialize() const {
root["flight"] = flight;
root["noclip"] = noclip;
root["infinite-items"] = infiniteItems;
root["chosen-slot"] = chosenSlot;
root["entity"] = eid;
root["inventory"] = inventory->serialize();
@ -300,6 +309,8 @@ void Player::deserialize(const dv::value& src) {
flight = src["flight"].asBoolean();
noclip = src["noclip"].asBoolean();
src.at("infinite-items").get(infiniteItems);
setChosenSlot(src["chosen-slot"].asInteger());
eid = src["entity"].asNumber();

View File

@ -49,6 +49,7 @@ class Player : public Object, public Serializable {
std::shared_ptr<Inventory> inventory;
bool flight = false;
bool noclip = false;
bool infiniteItems = true;
entityid_t eid;
entityid_t selectedEid;
public:
@ -86,6 +87,9 @@ public:
bool isNoclip() const;
void setNoclip(bool flag);
bool isInfiniteItems() const;
void setInfiniteItems(bool flag);
entityid_t getEntity() const;
void setEntity(entityid_t eid);