Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ struct ControllerHandler {
static void clampVec(float&, float&);
static int32_t lastPerspectiveMs;
static bool_t jumpHeld, sneakHeld, sprintHeld;
static bool_t sneakToggle;
static bool_t attackHeld, useHeld, confirmHeld;
static bool_t justCaptured;
static bool_t wasConnected;

static void beginCapture(bool_t);
static void endCapture();
Expand Down
11 changes: 6 additions & 5 deletions modifiedeight-newadditions/headers/input/ControllerLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ enum ControllerAction {
CA_TOGGLE_PERSPECTIVE = 8,
CA_SNEAK = 9,
CA_GAME_MENU = 10,
CA_MOVE_AXIS_X = 11,
CA_MOVE_AXIS_Y = 12,
CA_LOOK_AXIS_X = 13,
CA_LOOK_AXIS_Y = 14,
CA_COUNT = 15
CA_CHAT = 11,
CA_MOVE_AXIS_X = 12,
CA_MOVE_AXIS_Y = 13,
CA_LOOK_AXIS_X = 14,
CA_LOOK_AXIS_Y = 15,
CA_COUNT = 16
};

struct ControllerLayout {
Expand Down
27 changes: 17 additions & 10 deletions modifiedeight-newadditions/impl/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,27 @@ void Minecraft::joinMultiplayer(const struct PingedCompatibleServer& a2, bool_t
}
void Minecraft::leaveGame(bool_t a2, bool_t a3) {
if(!this->field_CF4 && this->levelGenerated) {
if (this->player && this->level && this->level->getLevelData()) {
CompoundTag playerTag;
this->player->saveWithoutId(&playerTag);
this->level->getLevelData()->setPlayerTag(&playerTag);
bool_t skipSave = this->level && this->level->isClientMaybe && !a2;
if (!skipSave) {
if (this->player && this->level && this->level->getLevelData()) {
CompoundTag playerTag;
this->player->saveWithoutId(&playerTag);
this->level->getLevelData()->setPlayerTag(&playerTag);
}
}
if (this->level && this->level->getLevelStorage() && this->player) {
this->level->getLevelStorage()->save(this->player);
if (!skipSave) {
if (this->level && this->level->getLevelStorage() && this->player) {
this->level->getLevelStorage()->save(this->player);
}
}
if(this->level) {
if(this->level->getChunkSource()) {
this->level->getChunkSource()->saveAll(0);
if(!skipSave) {
if(this->level->getChunkSource()) {
this->level->getChunkSource()->saveAll(0);
}
this->level->saveGame();
this->level->savePlayers();
}
this->level->saveGame();
this->level->savePlayers();
this->level->saveLevelData();
}
this->rakNetInstance->disconnect();
Expand Down
28 changes: 12 additions & 16 deletions modifiedeight-newadditions/impl/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,18 @@ void Gui::onConfigChanged(const Config &a2) {

sp = a2.mc->useTouchscreen();
if (sp) {
if (a2.mc->options.useJoypad) {
v22 = 6;
} else {
v22 = 6;
if (a2.field_0 > 480) {
do {
this->getSlotPos(0, v23, v25);
sp = this->getSlotPos(v22, v24, v25);
if ((float)((float)((float)a2.field_0 -
(float)((float)(v24 - v23) * a2.guiScale)) *
a2.field_1C) < 80.0) {
break;
}
++v22;
} while (v22 != 8);
}
v22 = 6;
if (a2.field_0 > 480) {
do {
this->getSlotPos(0, v23, v25);
sp = this->getSlotPos(v22, v24, v25);
if ((float)((float)((float)a2.field_0 -
(float)((float)(v24 - v23) * a2.guiScale)) *
a2.field_1C) < 80.0) {
break;
}
++v22;
} while (v22 != 8);
}
this->slotsAmount = v22;
} else {
Expand Down
42 changes: 33 additions & 9 deletions modifiedeight-newadditions/impl/input/ControllerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <input/Keyboard.hpp>
#include <input/Mouse.hpp>
#include <inventory/Inventory.hpp>
#include <sound/SoundEngine.hpp>
#include <math.h>
#include <utils.h>

Expand All @@ -34,9 +35,12 @@ float ControllerHandler::moveY = 0.0f;
bool_t ControllerHandler::jumpHeld = 0;
bool_t ControllerHandler::sneakHeld = 0;
bool_t ControllerHandler::sprintHeld = 0;
bool_t ControllerHandler::sneakToggle = 0;
bool_t ControllerHandler::attackHeld = 0;
bool_t ControllerHandler::useHeld = 0;
bool_t ControllerHandler::confirmHeld = 0;
bool_t ControllerHandler::justCaptured = 0;
bool_t ControllerHandler::wasConnected = 0;
float ControllerHandler::frameDt = 1.0f;
double ControllerHandler::lastFrameS = 0;
void ControllerHandler::clampVec(float& x, float& y) {
Expand Down Expand Up @@ -75,6 +79,7 @@ bool_t ControllerHandler::takeCaptured(Binding& out) {
out = ControllerHandler::capturedBinding;
ControllerHandler::hasCaptured = 0;
ControllerHandler::captureMode = 0;
ControllerHandler::justCaptured = 1;
return 1;
}

Expand Down Expand Up @@ -113,15 +118,23 @@ void ControllerHandler::tick(Minecraft* mc) {
if(dtMs > 100.0f) dtMs = 100.0f;
ControllerHandler::lastFrameS = nowS;
ControllerHandler::frameDt += ((dtMs / 16.6667f) - ControllerHandler::frameDt) * 0.2f;
if(mc && Gamepad::connected && !ControllerHandler::wasConnected && mc->useTouchscreen() && !mc->options.useJoypad) {
mc->options.useJoypad = 1;
mc->options.save();
mc->optionUpdated(&Options::Option::USE_TOUCH_JOYPAD, 1);
}
ControllerHandler::wasConnected = Gamepad::connected;
if(!ControllerHandler::isEnabled(mc)) {
ControllerHandler::releaseAll();
ControllerHandler::sneakToggle = 0;
ControllerHandler::confirmHeld = 0;
Gamepad::beginFrame();
return;
}

if(ControllerHandler::captureMode) {
ControllerHandler::releaseAll();
ControllerHandler::sneakToggle = 0;
ControllerHandler::confirmHeld = 0;
if(!ControllerHandler::hasCaptured) {
Binding found;
Expand Down Expand Up @@ -164,7 +177,13 @@ void ControllerHandler::tickGame(Minecraft* mc) {
ControllerHandler::moveY = my;

ControllerHandler::jumpHeld = Gamepad::isBindingDown(ControllerLayout::get(CA_JUMP));
ControllerHandler::sneakHeld = Gamepad::isBindingDown(ControllerLayout::get(CA_SNEAK));
if(Gamepad::wasBindingPressed(ControllerLayout::get(CA_SNEAK))) {
ControllerHandler::sneakToggle ^= 1;
if(mc->soundEngine) {
mc->soundEngine->playUI("random.click", 1.0f, 1.0f);
}
}
ControllerHandler::sneakHeld = ControllerHandler::sneakToggle;

static int32_t lastFwdTapMs = 0;
static bool_t fwdWasDown = 0;
Expand Down Expand Up @@ -241,6 +260,10 @@ void ControllerHandler::tickGame(Minecraft* mc) {
mc->gui.handleKeyPressed(100);
}

if(Gamepad::wasBindingPressed(ControllerLayout::get(CA_CHAT))) {
mc->screenChooser.setScreen(CHAT_SCREEN);
}

if(Gamepad::wasBindingPressed(ControllerLayout::get(CA_TOGGLE_PERSPECTIVE))) {
int32_t nowMs = getTimeMs();
if(nowMs - ControllerHandler::lastPerspectiveMs >= 350) {
Expand Down Expand Up @@ -289,7 +312,10 @@ void ControllerHandler::tickMenu(Minecraft* mc) {
int16_t cy = (int16_t)ControllerHandler::cursorY;

bool_t confirm = Gamepad::isBindingDown(ControllerLayout::get(CA_JUMP));
if(confirm && !ControllerHandler::confirmHeld) {
if(!confirm) {
ControllerHandler::justCaptured = 0;
}
if(confirm && !ControllerHandler::confirmHeld && !ControllerHandler::justCaptured) {
ControllerHandler::confirmHeld = 1;
ControllerHandler::lastPadCursorMs = getTimeMs();
Mouse::feed(1, 1, cx, cy);
Expand Down Expand Up @@ -348,13 +374,11 @@ void ControllerHandler::applyMove(IMoveInput* input, Player* player) {
}
}

if(ControllerHandler::sneakHeld) {
if(flying) {
input->flyDownPressed = 1;
input->sneakingMaybe = 0;
} else {
input->sneakingMaybe = 1;
}
if(flying) {
input->flyDownPressed = ControllerHandler::sneakToggle;
input->sneakingMaybe = 0;
} else {
input->sneakingMaybe = ControllerHandler::sneakToggle;
}

if(player->isLocalPlayer()) {
Expand Down
3 changes: 3 additions & 0 deletions modifiedeight-newadditions/impl/input/ControllerLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const char_t* _caNames[CA_COUNT] = {
"Toggle Perspective",
"Sneak/Fly Down",
"Game Menu",
"Chat",
"Move Left/Right",
"Move Forward/Back",
"Look Left/Right",
Expand All @@ -36,6 +37,7 @@ static const char_t* _caKeys[CA_COUNT] = {
"perspective",
"sneak",
"gamemenu",
"chat",
"movex",
"movey",
"lookx",
Expand Down Expand Up @@ -64,6 +66,7 @@ void ControllerLayout::resetToDefaults() {
ControllerLayout::bindings[CA_LOOK_AXIS_X] = Binding(BIND_AXIS_FULL, GP_AXIS_RX);
ControllerLayout::bindings[CA_LOOK_AXIS_Y] = Binding(BIND_AXIS_FULL, GP_AXIS_RY);
ControllerLayout::bindings[CA_GAME_MENU] = Binding(BIND_BUTTON, GP_BTN_START);
ControllerLayout::bindings[CA_CHAT] = Binding(BIND_BUTTON, GP_BTN_DPAD_RIGHT);
}

void ControllerLayout::load() {
Expand Down
3 changes: 3 additions & 0 deletions modifiedeight/headers/input/ControllerHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ struct ControllerHandler {
static void clampVec(float&, float&);
static int32_t lastPerspectiveMs;
static bool_t jumpHeld, sneakHeld, sprintHeld;
static bool_t sneakToggle;
static bool_t attackHeld, useHeld, confirmHeld;
static bool_t justCaptured;
static bool_t wasConnected;

static void beginCapture(bool_t);
static void endCapture();
Expand Down
11 changes: 6 additions & 5 deletions modifiedeight/headers/input/ControllerLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ enum ControllerAction {
CA_TOGGLE_PERSPECTIVE = 8,
CA_SNEAK = 9,
CA_GAME_MENU = 10,
CA_MOVE_AXIS_X = 11,
CA_MOVE_AXIS_Y = 12,
CA_LOOK_AXIS_X = 13,
CA_LOOK_AXIS_Y = 14,
CA_COUNT = 15
CA_CHAT = 11,
CA_MOVE_AXIS_X = 12,
CA_MOVE_AXIS_Y = 13,
CA_LOOK_AXIS_X = 14,
CA_LOOK_AXIS_Y = 15,
CA_COUNT = 16
};

struct ControllerLayout {
Expand Down
28 changes: 12 additions & 16 deletions modifiedeight/impl/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,18 @@ void Gui::onConfigChanged(const Config &a2) {

sp = a2.mc->useTouchscreen();
if (sp) {
if (a2.mc->options.useJoypad) {
v22 = 6;
} else {
v22 = 6;
if (a2.field_0 > 480) {
do {
this->getSlotPos(0, v23, v25);
sp = this->getSlotPos(v22, v24, v25);
if ((float)((float)((float)a2.field_0 -
(float)((float)(v24 - v23) * a2.guiScale)) *
a2.field_1C) < 80.0) {
break;
}
++v22;
} while (v22 != 8);
}
v22 = 6;
if (a2.field_0 > 480) {
do {
this->getSlotPos(0, v23, v25);
sp = this->getSlotPos(v22, v24, v25);
if ((float)((float)((float)a2.field_0 -
(float)((float)(v24 - v23) * a2.guiScale)) *
a2.field_1C) < 80.0) {
break;
}
++v22;
} while (v22 != 8);
}
this->slotsAmount = v22;
} else {
Expand Down
10 changes: 6 additions & 4 deletions modifiedeight/impl/gui/screens/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ static bool resolveItem(const std::string& rawName, int& outId, std::string& out
}

static bool executeCommand(Minecraft* mc, const std::string& line) {
if (!mc || !mc->level || mc->isOnlineClient() || (mc->level && mc->level->isClientMaybe)) return false;
if (line.empty() || line[0] != '/') return false;

std::stringstream ss(line.substr(1));
Expand Down Expand Up @@ -498,12 +499,13 @@ static bool executeCommand(Minecraft* mc, const std::string& line) {

void ChatScreen::sendChatMessage() {
if(this->field_54.size()) {
if(!executeCommand(this->minecraft, this->field_54)) {
if (this->minecraft->isOnlineClient() || (this->minecraft->level && this->minecraft->level->isClientMaybe)) {
MessagePacket v7(this->field_54, this->minecraft->player->username);
this->minecraft->rakNetInstance->send(v7);
if(!this->minecraft->isOnlineClient()) {
this->minecraft->gui.addMessage(this->minecraft->player->username, this->field_54, 200);
}
} else if(!executeCommand(this->minecraft, this->field_54)) {
MessagePacket v7(this->field_54, this->minecraft->player->username);
this->minecraft->rakNetInstance->send(v7);
this->minecraft->gui.addMessage(this->minecraft->player->username, this->field_54, 200);
}
this->field_78.emplace_back(this->field_54);
this->field_84 = this->field_78.size();
Expand Down
Loading
Loading