Fix history editing bug

- Use the `get_<var>` pattern for chat's `history`.
- Make the Biome_map comment clearer
This commit is contained in:
Bigjango13 2024-03-09 13:01:52 -05:00
parent 3ff24c2a92
commit a6e0cd8f13
3 changed files with 10 additions and 5 deletions

View File

@ -10,7 +10,10 @@
#include <mods/misc/misc.h>
#include <mods/touch/touch.h>
std::vector<std::string> history;
static std::vector<std::string> &get_history() {
static std::vector<std::string> history = {};
return history;
}
// Structure
struct ChatScreen {
@ -26,7 +29,7 @@ CUSTOM_VTABLE(chat_screen, Screen) {
original_init(super);
ChatScreen *self = (ChatScreen *) super;
// Text Input
self->chat = TextInputBox::create("", "", &history);
self->chat = TextInputBox::create("", "", &get_history());
self->super.m_textInputs->push_back(self->chat);
self->chat->init(super->font);
self->chat->setFocused(true);
@ -81,7 +84,8 @@ CUSTOM_VTABLE(chat_screen, Screen) {
if (key == 0x0d && self->chat->isFocused()) {
if (self->chat->getText().length() > 0) {
std::string text = self->chat->getText();
if (self->chat->history_pos != int(history.size() - 1)) {
std::vector<std::string> &history = get_history();
if (history.size() == 0 || text != history.back()) {
history.push_back(text);
}
_chat_queue_message(text.c_str());
@ -119,7 +123,6 @@ static Screen *create_chat_screen() {
// Init
void _init_chat_ui() {
history = {};
misc_run_on_game_key_press([](Minecraft *minecraft, int key) {
if (key == 0x54) {
if (Minecraft_isLevelGenerated(minecraft) && minecraft->screen == NULL) {

View File

@ -5,3 +5,5 @@ property Minecraft *mc = 0x18;
method void renderItem(Mob *mob, ItemInstance *item) = 0x4b824;
method void render(float param_1) = 0x4bfcc;
static-property ItemInHandRenderer *instance = 0x137bc0;

View File

@ -16,5 +16,5 @@ virtual-method float getCreatureProbability() = 0x20;
property int color = 0x2c;
property int leaf_color = 0x34;
// 64x64, Temp x humidity
// This is a Biome*[64x64], temp x humidity
static-property-array Biome *map = 0x17c970;