Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Kolyah35
2026-03-16 23:18:53 +03:00
13 changed files with 679 additions and 333 deletions

View File

@@ -73,6 +73,8 @@
#include "../util/Mth.h"
#include "../network/packet/InteractPacket.h"
#include "../network/packet/RespawnPacket.h"
#include "../network/packet/AdventureSettingsPacket.h"
#include "../network/packet/SetSpawnPositionPacket.h"
#include "IConfigListener.h"
#include "../world/entity/MobCategory.h"
#include "../world/Difficulty.h"
@@ -333,6 +335,7 @@ void Minecraft::leaveGame(bool renameLevel /*=false*/)
_running = false;
#ifndef STANDALONE_SERVER
gui.clearMessages();
if (renameLevel) {
setScreen(new RenameMPLevelScreen(LevelStorageSource::TempLevelId));
}
@@ -725,10 +728,6 @@ void Minecraft::tickInput() {
setScreen(new ConsoleScreen());
}
if (!screen && key == Keyboard::KEY_O || key == 250) {
releaseMouse();
}
if (key == Keyboard::KEY_F3) {
options.toggle(OPTIONS_RENDER_DEBUG);
}
@@ -742,92 +741,96 @@ void Minecraft::tickInput() {
*/
}
if (!screen && key == Keyboard::KEY_O || key == 250) {
releaseMouse();
}
if (key == Keyboard::KEY_L) {
if (key == Keyboard::KEY_F) {
int dst = options.getIntValue(OPTIONS_VIEW_DISTANCE);
options.set(OPTIONS_VIEW_DISTANCE, (dst + 1) % 4);
}
if (key == Keyboard::KEY_U) {
onGraphicsReset();
player->heal(100);
}
if (key == Keyboard::KEY_B || key == 108) // Toggle the game mode
setIsCreativeMode(!isCreativeMode());
if (key == Keyboard::KEY_P) // Step forward in time
level->setTime( level->getTime() + 1000);
if (key == Keyboard::KEY_G) {
setScreen(new ArmorScreen());
/*
std::vector<AABB>& boxs = level->getCubes(NULL, AABB(128.1f, 73, 128.1f, 128.9f, 74.9f, 128.9f));
LOGI("boxes: %d\n", (int)boxs.size());
*/
}
if (key == Keyboard::KEY_Y) {
textures->reloadAll();
player->hurtTo(2);
}
if (key == Keyboard::KEY_Z || key == 108) {
for (int i = 0; i < 1; ++i) {
Mob* mob = NULL;
int forceId = 0;//MobTypes::Sheep;
int types[] = {
MobTypes::Sheep,
MobTypes::Pig,
MobTypes::Chicken,
MobTypes::Cow,
};
int mobType = (forceId > 0)? forceId : types[Mth::random(sizeof(types) / sizeof(int))];
mob = MobFactory::CreateMob(mobType, level);
//((Animal*)mob)->setAge(-1000);
float dx = 4 - 8 * Mth::random() + 4 * Mth::sin(Mth::DEGRAD * player->yRot);
float dz = 4 - 8 * Mth::random() + 4 * Mth::cos(Mth::DEGRAD * player->yRot);
if (mob && !MobSpawner::addMob(level, mob, player->x + dx, player->y, player->z + dz, Mth::random()*360, 0, true))
delete mob;
#ifdef CHEATS
if (key == Keyboard::KEY_U) {
onGraphicsReset();
player->heal(100);
}
}
if (key == Keyboard::KEY_X) {
const EntityList& entities = level->getAllEntities();
for (int i = entities.size()-1; i >= 0; --i) {
Entity* e = entities[i];
if (!e->isPlayer())
level->removeEntity(e);
if (key == Keyboard::KEY_B || key == 108) // Toggle the game mode
setIsCreativeMode(!isCreativeMode());
if (key == Keyboard::KEY_P) // Step forward in time
level->setTime( level->getTime() + 1000);
if (key == Keyboard::KEY_G) {
setScreen(new ArmorScreen());
/*
std::vector<AABB>& boxs = level->getCubes(NULL, AABB(128.1f, 73, 128.1f, 128.9f, 74.9f, 128.9f));
LOGI("boxes: %d\n", (int)boxs.size());
*/
}
}
if (key == Keyboard::KEY_C /*|| key == 4*/) {
player->inventory->clearInventoryWithDefault();
// @todo: Add saving here for benchmarking
}
if (key == Keyboard::KEY_H) {
setScreen( new PrerenderTilesScreen() );
}
if (key == Keyboard::KEY_O) {
for (int i = Inventory::MAX_SELECTION_SIZE; i < player->inventory->getContainerSize(); ++i)
if (player->inventory->getItem(i))
player->inventory->dropSlot(i, false);
}
if (key == Keyboard::KEY_M) {
Difficulty difficulty = (Difficulty)options.getIntValue(OPTIONS_DIFFICULTY);
options.set(OPTIONS_DIFFICULTY, (difficulty == Difficulty::PEACEFUL)?
Difficulty::NORMAL : Difficulty::PEACEFUL);
//setIsCreativeMode( !isCreativeMode() );
}
if (options.getBooleanValue(OPTIONS_RENDER_DEBUG)) {
if (key >= '0' && key <= '9') {
_perfRenderer->debugFpsMeterKeyPress(key - '0');
if (key == Keyboard::KEY_Y) {
textures->reloadAll();
player->hurtTo(2);
}
}
if (key == Keyboard::KEY_Z || key == 108) {
for (int i = 0; i < 1; ++i) {
Mob* mob = NULL;
int forceId = 0;//MobTypes::Sheep;
int types[] = {
MobTypes::Sheep,
MobTypes::Pig,
MobTypes::Chicken,
MobTypes::Cow,
};
int mobType = (forceId > 0)? forceId : types[Mth::random(sizeof(types) / sizeof(int))];
mob = MobFactory::CreateMob(mobType, level);
//((Animal*)mob)->setAge(-1000);
float dx = 4 - 8 * Mth::random() + 4 * Mth::sin(Mth::DEGRAD * player->yRot);
float dz = 4 - 8 * Mth::random() + 4 * Mth::cos(Mth::DEGRAD * player->yRot);
if (mob && !MobSpawner::addMob(level, mob, player->x + dx, player->y, player->z + dz, Mth::random()*360, 0, true))
delete mob;
}
}
if (key == Keyboard::KEY_X) {
const EntityList& entities = level->getAllEntities();
for (int i = entities.size()-1; i >= 0; --i) {
Entity* e = entities[i];
if (!e->isPlayer())
level->removeEntity(e);
}
}
if (key == Keyboard::KEY_C /*|| key == 4*/) {
player->inventory->clearInventoryWithDefault();
// @todo: Add saving here for benchmarking
}
if (key == Keyboard::KEY_H) {
setScreen( new PrerenderTilesScreen() );
}
if (key == Keyboard::KEY_O) {
for (int i = Inventory::MAX_SELECTION_SIZE; i < player->inventory->getContainerSize(); ++i)
if (player->inventory->getItem(i))
player->inventory->dropSlot(i, false);
}
if (key == Keyboard::KEY_M) {
Difficulty difficulty = (Difficulty)options.getIntValue(OPTIONS_DIFFICULTY);
options.set(OPTIONS_DIFFICULTY, (difficulty == Difficulty::PEACEFUL)?
Difficulty::NORMAL : Difficulty::PEACEFUL);
//setIsCreativeMode( !isCreativeMode() );
}
if (options.getBooleanValue(OPTIONS_RENDER_DEBUG)) {
if (key >= '0' && key <= '9') {
_perfRenderer->debugFpsMeterKeyPress(key - '0');
}
}
#endif
#endif
#ifndef PLATFORM_DESKTOP

View File

@@ -97,6 +97,8 @@ public:
Options(Minecraft* minecraft, const std::string& workingDirectory = "")
: minecraft(minecraft) {
// elements werent initialized so i was getting a garbage pointer and a crash
m_options.fill(nullptr);
initTable();
load();
}

View File

@@ -135,10 +135,14 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
#endif
#if defined(RPI)
renderDebugInfo();
#elif defined(PLATFORM_DESKTOP)
#endif
if (Keyboard::isKeyDown(Keyboard::KEY_TAB)) {
renderPlayerList(font, screenWidth, screenHeight);
}
if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG))
renderDebugInfo();
#endif
}
glDisable(GL_BLEND);
@@ -330,6 +334,11 @@ void Gui::addMessage(const std::string& _string) {
}
}
void Gui::clearMessages() {
guiMessages.clear();
chatScrollOffset = 0;
}
void Gui::setNowPlaying(const std::string& string) {
overlayMessageString = "Now playing: " + string;
overlayMessageTime = 20 * 3;
@@ -799,6 +808,83 @@ void Gui::renderDebugInfo() {
t.endOverrideAndDraw();
}
void Gui::renderPlayerList(Font* font, int screenWidth, int screenHeight) {
// only show when in game, no other screen
// if (!minecraft->level) return;
// only show the overlay while connected to a multiplayer server
Level* level = minecraft->level;
if (!level) return;
if (!level->isClientSide) return;
std::vector<std::string> playerNames;
playerNames.reserve(level->players.size());
for (Player* player : level->players) {
if (!player) continue;
playerNames.push_back(player->name);
}
// is this check needed? if there are no players, the box won't render at all since height will be 0,
// but maybe we want to skip rendering entirely in that case
// if (playerNames.empty())
// return;
std::sort(playerNames.begin(), playerNames.end());
float maxNameWidth = 0.0f;
// find the longest name so we can size the box accordingly
for (const std::string& name : playerNames) {
float nameWidth = font->width(name);
if (nameWidth > maxNameWidth)
maxNameWidth = nameWidth;
}
// player count title
std::string titleText = "Players (" + std::to_string(playerNames.size()) + ")";
float titleWidth = font->width(titleText);
if (titleWidth > maxNameWidth)
maxNameWidth = titleWidth;
const float padding = 4.0f;
const float lineHeight = (float)Font::DefaultLineHeight;
const float boxWidth = maxNameWidth + padding * 2;
const float boxHeight = (playerNames.size() + 1) * lineHeight + padding * 2;
const float boxLeft = (screenWidth - boxWidth) / 2.0f;
const float boxTop = 10.0f;
const float boxRight = boxLeft + boxWidth;
const float boxBottom = boxTop + boxHeight;
fill(boxLeft, boxTop, boxRight, boxBottom, 0x90000000);
float titleX = (screenWidth - titleWidth) / 2.0f;
float titleY = boxTop + padding;
// scale the text down slightly
// i think the gl scaling is the best for this
// oh my god this looks really bad OH GOD
//const float textScale = 0.8f;
//const float invTextScale = 1.0f / textScale;
//glPushMatrix2();
//glScalef2(textScale, textScale, 1);
// draw title
//font->draw(titleText, titleX * invTextScale, titleY * invTextScale, 0xFFFFFFFF);
font->draw(titleText, titleX, titleY, 0xFFFFFFFF);
// draw player names
// we should add ping icons here eventually, but for now just show names
float currentY = boxTop + padding + lineHeight;
for (const std::string& name : playerNames) {
font->draw(name, (boxLeft + padding), currentY, 0xFFDDDDDD);
currentY += lineHeight;
}
//glPopMatrix2();
}
void Gui::renderSleepAnimation( const int screenWidth, const int screenHeight ) {
int timer = minecraft->player->getSleepTimer();
float amount = (float) timer / (float) Player::SLEEP_DURATION;

View File

@@ -61,10 +61,12 @@ public:
void renderBubbles();
void renderHearts();
void renderDebugInfo();
void renderPlayerList(Font* font, int screenWidth, int screenHeight);
void renderProgressIndicator( const bool isTouchInterface, const int screenWidth, const int screenHeight, float a );
void addMessage(const std::string& string);
void clearMessages();
void postError(int errCode);
void onGraphicsReset();

View File

@@ -170,22 +170,31 @@ void TouchscreenInput_TestFps::onConfigChanged(const Config& c) {
//rebuild();
}
void TouchscreenInput_TestFps::setKey( int key, bool state )
void TouchscreenInput_TestFps::setKey(int key, bool state)
{
#ifdef WIN32
//LOGI("key: %d, %d\n", key, state);
//LOGI("key: %d, %d\n", key, state);
int id = -1;
if (key == _options->keyUp.key) id = KEY_UP;
if (key == _options->keyDown.key) id = KEY_DOWN;
if (key == _options->keyLeft.key) id = KEY_LEFT;
if (key == _options->keyRight.key) id = KEY_RIGHT;
if (key == _options->keyJump.key) id = KEY_JUMP;
if (key == _options->keySneak.key) id = KEY_SNEAK;
if (key == _options->keyCraft.key) id = KEY_CRAFT;
if (id >= 0) {
_keys[id] = state;
}
// theres no keyUp etc???
//if (key == _options->keyUp.key) id = KEY_UP;
//if (key == _options->keyDown.key) id = KEY_DOWN;
//if (key == _options->keyLeft.key) id = KEY_LEFT;
//if (key == _options->keyRight.key) id = KEY_RIGHT;
//if (key == _options->keyJump.key) id = KEY_JUMP;
//if (key == _options->keySneak.key) id = KEY_SNEAK;
//if (key == _options->keyCraft.key) id = KEY_CRAFT;
//if (id >= 0) {
// _keys[id] = state;
//}
if (key == _options->getIntValue(OPTIONS_KEY_FORWARD)) id = KEY_UP;
if (key == _options->getIntValue(OPTIONS_KEY_BACK)) id = KEY_DOWN;
if (key == _options->getIntValue(OPTIONS_KEY_LEFT)) id = KEY_LEFT;
if (key == _options->getIntValue(OPTIONS_KEY_RIGHT)) id = KEY_RIGHT;
if (key == _options->getIntValue(OPTIONS_KEY_JUMP)) id = KEY_JUMP;
if (key == _options->getIntValue(OPTIONS_KEY_SNEAK)) id = KEY_SNEAK;
//if (key == _options->getIntValue(OPTIONS_KEY_CRAFT)) id = KEY_CRAFT;
#endif
}

View File

@@ -167,16 +167,16 @@ void HumanoidMobRenderer::additionalRendering(Mob* mob, float a) {
const float depth = 1.0f;
// Front
t.tex(u0, vTop); t.vertex(-halfW, 0.0f, 0.0f);
t.tex(u1, vTop); t.vertex(halfW, 0.0f, 0.0f);
t.tex(u1, vBottom); t.vertex(halfW, height, 0.0f);
t.tex(u0, vBottom); t.vertex(-halfW, height, 0.0f);
t.tex(u2, vTop); t.vertex(-halfW, 0.0f, 0.0f);
t.tex(u3, vTop); t.vertex(halfW, 0.0f, 0.0f);
t.tex(u3, vBottom); t.vertex(halfW, height, 0.0f);
t.tex(u2, vBottom); t.vertex(-halfW, height, 0.0f);
// Back
t.tex(u2, vTop); t.vertex(halfW, 0.0f, depth);
t.tex(u3, vTop); t.vertex(-halfW, 0.0f, depth);
t.tex(u3, vBottom); t.vertex(-halfW, height, depth);
t.tex(u2, vBottom); t.vertex(halfW, height, depth);
// Back
t.tex(u0, vTop); t.vertex(halfW, 0.0f, depth);
t.tex(u1, vTop); t.vertex(-halfW, 0.0f, depth);
t.tex(u1, vBottom); t.vertex(-halfW, height, depth);
t.tex(u0, vBottom); t.vertex(halfW, height, depth);
// Left
t.tex(uL0, vTop); t.vertex(-halfW, 0.0f, depth);

View File

@@ -1,68 +1,68 @@
#ifndef NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__
#define NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__
//package net.minecraft.client.sound;
#if defined(ANDROID) && !defined(PRE_ANDROID23)
#include "../../platform/audio/SoundSystemSL.h"
#elif defined(__APPLE__) || defined(PLATFORM_DESKTOP)
#include "../../platform/audio/SoundSystemAL.h"
#else
#include "../../platform/audio/SoundSystem.h"
#endif
#include "SoundRepository.h"
#include "../../util/Random.h"
class Minecraft;
class Mob;
class Options;
class SoundEngine
{
static const int SOUND_DISTANCE = 16;
#if defined(ANDROID) && !defined(PRE_ANDROID23) && !defined(RPI)
SoundSystemSL soundSystem;
#elif defined(__APPLE__) || defined(PLATFORM_DESKTOP)
SoundSystemAL soundSystem;
#else
SoundSystem soundSystem;
#endif
Options* options;
int idCounter;
//static bool loaded;
Random random;
//int noMusicDelay = random.nextInt(20 * 60 * 10);
float _x;
float _y;
float _z;
float _yRot;
float _invMaxDistance;
public:
SoundEngine(float maxDistance);
~SoundEngine();
void init(Minecraft* mc, Options* options);
void destroy();
void enable(bool status);
void updateOptions();
void update(Mob* player, float a);
void play(const std::string& name, float x, float y, float z, float volume, float pitch);
void playUI(const std::string& name, float volume, float pitch);
float _getVolumeMult(float x, float y, float z);
private:
void loadLibrary() {}
SoundDesc _pp(const std::string& fn);
SoundRepository sounds;
Minecraft* mc;
};
#endif /*NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__*/
#ifndef NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__
#define NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__
//package net.minecraft.client.sound;
#if defined(ANDROID) && !defined(PRE_ANDROID23)
#include "../../platform/audio/SoundSystemSL.h"
#elif (defined(__APPLE__) || defined(PLATFORM_DESKTOP)) && !defined(NO_SOUND)
#include "../../platform/audio/SoundSystemAL.h"
#else
#include "../../platform/audio/SoundSystem.h"
#endif
#include "SoundRepository.h"
#include "../../util/Random.h"
class Minecraft;
class Mob;
class Options;
class SoundEngine
{
static const int SOUND_DISTANCE = 16;
#if defined(ANDROID) && !defined(PRE_ANDROID23) && !defined(RPI)
SoundSystemSL soundSystem;
#elif (defined(__APPLE__) || defined(PLATFORM_DESKTOP)) && !defined(NO_SOUND)
SoundSystemAL soundSystem;
#else
SoundSystem soundSystem;
#endif
Options* options;
int idCounter;
//static bool loaded;
Random random;
//int noMusicDelay = random.nextInt(20 * 60 * 10);
float _x;
float _y;
float _z;
float _yRot;
float _invMaxDistance;
public:
SoundEngine(float maxDistance);
~SoundEngine();
void init(Minecraft* mc, Options* options);
void destroy();
void enable(bool status);
void updateOptions();
void update(Mob* player, float a);
void play(const std::string& name, float x, float y, float z, float volume, float pitch);
void playUI(const std::string& name, float volume, float pitch);
float _getVolumeMult(float x, float y, float z);
private:
void loadLibrary() {}
SoundDesc _pp(const std::string& fn);
SoundRepository sounds;
Minecraft* mc;
};
#endif /*NET_MINECRAFT_CLIENT_SOUND__SoundEngine_H__*/