REMOVE: User class

This commit is contained in:
Kolyah35
2026-03-17 22:49:59 +03:00
parent 2c132d5bc7
commit 5ff8b54c4f
9 changed files with 35 additions and 100 deletions

View File

@@ -116,8 +116,7 @@ int Minecraft::customDebugId = Minecraft::CDI_NONE;
bool Minecraft::useAmbientOcclusion = false;
Minecraft::Minecraft()
: user(NULL),
Minecraft::Minecraft() :
level(NULL),
player(NULL),
cameraTargetPlayer(NULL),
@@ -222,7 +221,6 @@ Minecraft::~Minecraft()
}
//delete player;
delete user;
delete inputHolder;
delete storageSource;
@@ -1145,10 +1143,8 @@ void Minecraft::init()
checkGlError("Init complete");
#endif
user = new User(options.getStringValue(OPTIONS_USERNAME), "");
setIsCreativeMode(false); // false means it's Survival Mode
reloadOptions();
}
void Minecraft::setSize(int w, int h) {
@@ -1334,9 +1330,9 @@ void Minecraft::hostMultiplayer(int port) {
#if !defined(NO_NETWORK)
netCallback = new ServerSideNetworkHandler(this, raknetInstance);
#ifdef STANDALONE_SERVER
raknetInstance->host(user->name, port, 16);
raknetInstance->host(options.getStringValue(OPTIONS_USERNAME), port, 16);
#else
raknetInstance->host(user->name, port);
raknetInstance->host(options.getStringValue(OPTIONS_USERNAME), port);
#endif
#endif
}
@@ -1393,8 +1389,10 @@ void Minecraft::_levelGenerated()
this->cameraTargetPlayer = player;
std::string serverName = options.getStringValue(OPTIONS_USERNAME) + " - " + level->getLevelData()->levelName;
if (raknetInstance->isServer())
raknetInstance->announceServer(user->name);
raknetInstance->announceServer(serverName);
if (netCallback) {
netCallback->levelGenerated(level);

View File

@@ -13,7 +13,6 @@
//#include "../network/RakNetInstance.h"
#include "../world/phys/HitResult.h"
class User;
class Level;
class LocalPlayer;
class IInputHolder;
@@ -165,7 +164,6 @@ public:
int lastTickTime;
float ticksSinceLastUpdate;
User* user;
Level* level;
LocalPlayer* player;

View File

@@ -1,62 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT__User_H__
#define NET_MINECRAFT_CLIENT__User_H__
//package net.minecraft.client;
#include "../world/level/tile/Tile.h"
class User
{
public:
//static List<Tile> allowedTiles = /*new*/ ArrayList<Tile>();
//static {
// allowedTiles.push_back(Tile::rock);
// allowedTiles.push_back(Tile::stoneBrick);
// allowedTiles.push_back(Tile::redBrick);
// allowedTiles.push_back(Tile::dirt);
// allowedTiles.push_back(Tile::wood);
// allowedTiles.push_back(Tile::treeTrunk);
// allowedTiles.push_back(Tile::leaves);
// allowedTiles.push_back(Tile::torch);
// allowedTiles.push_back(Tile::stoneSlabHalf);
// allowedTiles.push_back(Tile::glass);
// allowedTiles.push_back(Tile::mossStone);
// allowedTiles.push_back(Tile::sapling);
// allowedTiles.push_back(Tile::flower);
// allowedTiles.push_back(Tile::rose);
// allowedTiles.push_back(Tile::mushroom1);
// allowedTiles.push_back(Tile::mushroom2);
// allowedTiles.push_back(Tile::sand);
// allowedTiles.push_back(Tile::gravel);
// allowedTiles.push_back(Tile::sponge);
// allowedTiles.push_back(Tile::cloth);
// allowedTiles.push_back(Tile::coalOre);
// allowedTiles.push_back(Tile::ironOre);
// allowedTiles.push_back(Tile::goldOre);
// allowedTiles.push_back(Tile::ironBlock);
// allowedTiles.push_back(Tile::goldBlock);
// allowedTiles.push_back(Tile::bookshelf);
// allowedTiles.push_back(Tile::tnt);
// allowedTiles.push_back(Tile::obsidian);
// // System.out.println(allowedTiles.size());
//}
static bool isTileAllowed(const Tile& tile) {
return true;
}
std::string name;
std::string sessionId;
//std::string mpPassword;
User(const std::string& name, const std::string& sessionId) {
this->name = name;
this->sessionId = sessionId;
}
};
#endif /*NET_MINECRAFT_CLIENT__User_H__*/

View File

@@ -5,6 +5,7 @@
#include "../../world/level/Level.h"
#include "../../world/item/ItemInstance.h"
#include "../player/LocalPlayer.h"
#include "client/Options.h"
#ifndef STANDALONE_SERVER
#include "../sound/SoundEngine.h"
#include "../particle/ParticleEngine.h"
@@ -27,7 +28,7 @@ GameMode::GameMode( Minecraft* minecraft)
/*virtual*/
Player* GameMode::createPlayer(Level* level) {
return new LocalPlayer(minecraft, level, minecraft->user, level->dimension->id, isCreativeType());
return new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType());
}
/*virtual*/

View File

@@ -1,7 +1,6 @@
#include "UsernameScreen.h"
#include "StartMenuScreen.h"
#include "../../Minecraft.h"
#include "../../User.h"
#include "../Font.h"
#include "../components/Button.h"
#include "../../../platform/input/Keyboard.h"
@@ -75,7 +74,6 @@ void UsernameScreen::buttonClicked(Button* button)
if (button == &_btnDone && !tUsername.text.empty()) {
minecraft->options.set(OPTIONS_USERNAME, tUsername.text);
minecraft->options.save();
minecraft->user->name = tUsername.text;
minecraft->setScreen(NULL); // goes to StartMenuScreen
}
}

View File

@@ -242,11 +242,12 @@ static void* fetchSkinForPlayer(void* param) {
fwrite(skinData.data(), 1, skinData.size(), fp);
fclose(fp);
LOGI("[Skin] cached skin to %s\n", cacheFile.c_str());
} else {
player->setTextureName("skins/" + player->name + ".png");
} else {
LOGW("[Skin] failed to write skin cache %s\n", cacheFile.c_str());
}
player->setTextureName("skins/" + player->name + ".png");
return NULL;
}
@@ -287,11 +288,12 @@ static void* fetchCapeForPlayer(void* param) {
fwrite(capeData.data(), 1, capeData.size(), fp);
fclose(fp);
LOGI("[Cape] cached cape to %s\n", cacheFile.c_str());
player->setCapeTextureName("capes/" + player->name + ".png");
} else {
LOGW("[Cape] failed to write cape cache %s\n", cacheFile.c_str());
}
player->setCapeTextureName("capes/" + player->name + ".png");
return NULL;
}
@@ -310,7 +312,7 @@ static bool isJumpable(int tileId) {
} // anonymous namespace
LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user, int dimension, bool isCreative)
LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, const std::string& username, int dimension, bool isCreative)
: Player(level, isCreative),
minecraft(minecraft),
input(NULL),
@@ -326,9 +328,10 @@ LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user, int dim
_init();
#ifndef STANDALONE_SERVER
if (user != NULL && !user->name.empty()) {
this->name = user->name;
if (!name.empty()) {
this->name = name;
// Fetch user skin and cape from Mojang servers in the background (avoids blocking the main thread)
// TODO: Fix this memory leak
new CThread(fetchSkinForPlayer, this);
new CThread(fetchCapeForPlayer, this);
}

View File

@@ -4,8 +4,6 @@
//package net.minecraft.client.player;
#include "input/IMoveInput.h"
#include "../User.h"
#include "../../platform/input/Keyboard.h"
#include "../../util/SmoothFloat.h"
#include "../../world/entity/player/Player.h"
@@ -17,7 +15,7 @@ class LocalPlayer: public Player
{
typedef Player super;
public:
LocalPlayer(Minecraft* minecraft, Level* level, User* user, int dimension, bool isCreative);
LocalPlayer(Minecraft* minecraft, Level* level, const std::string& username, int dimension, bool isCreative);
~LocalPlayer();
void _init();

View File

@@ -1,5 +1,6 @@
#include "ClientSideNetworkHandler.h"
#include "client/Options.h"
#include "packet/PacketInclude.h"
#include "RakNetInstance.h"
#include "../world/level/chunk/ChunkSource.h"
@@ -85,7 +86,7 @@ void ClientSideNetworkHandler::onConnect(const RakNet::RakNetGUID& hostGuid)
serverGuid = hostGuid;
clearChunksLoaded();
LoginPacket packet(minecraft->user->name.c_str(), SharedConstants::NetworkProtocolVersion);
LoginPacket packet(minecraft->options.getStringValue(OPTIONS_USERNAME).c_str(), SharedConstants::NetworkProtocolVersion);
raknetInstance->send(packet);
}
@@ -157,7 +158,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, StartGam
level->isClientSide = true;
bool isCreative = (packet->gameType == GameType::Creative);
LocalPlayer* player = new LocalPlayer(minecraft, level, minecraft->user, level->dimension->id, isCreative);
LocalPlayer* player = new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreative);
player->owner = rakPeer->GetMyGUID();
player->entityId = packet->entityId;
player->moveTo(packet->x, packet->y, packet->z, player->yRot, player->xRot);

View File

@@ -25,38 +25,38 @@ public:
static const int C_RIGHT_HINGE_MASK = 16;
DoorTile(int id, const Material* material);
int getTexture(LevelSource* level, int x, int y, int z, int face);
int getTexture(LevelSource* level, int x, int y, int z, int face) override;
bool blocksLight();
bool isSolidRender();
bool isCubeShaped();
int getRenderShape();
int getRenderLayer();
bool isSolidRender() override;
bool isCubeShaped() override;
int getRenderShape() override;
int getRenderLayer() override;
AABB getTileAABB(Level* level, int x, int y, int z);
AABB* getAABB(Level* level, int x, int y, int z);
AABB getTileAABB(Level* level, int x, int y, int z) override;
AABB* getAABB(Level* level, int x, int y, int z) override;
void updateShape(LevelSource* level, int x, int y, int z);
void updateShape(LevelSource* level, int x, int y, int z) override;
void setShape(int compositeData);
void attack(Level* level, int x, int y, int z, Player* player);
bool use(Level* level, int x, int y, int z, Player* player);
void attack(Level* level, int x, int y, int z, Player* player) override;
bool use(Level* level, int x, int y, int z, Player* player) override;
void setOpen(Level* level, int x, int y, int z, bool shouldOpen);
static bool isOpen(LevelSource* level, int x, int y, int z);
void neighborChanged(Level* level, int x, int y, int z, int type);
void neighborChanged(Level* level, int x, int y, int z, int type) override;
int getResource(int data, Random* random);
int getResource(int data, Random* random) override;
// override to avoid duplicate drops when upper half is mined directly
void playerDestroy(Level* level, Player* player, int x, int y, int z, int data) override;
HitResult clip(Level* level, int xt, int yt, int zt, const Vec3& a, const Vec3& b);
HitResult clip(Level* level, int xt, int yt, int zt, const Vec3& a, const Vec3& b) override;
int getDir(LevelSource* level, int x, int y, int z);
bool mayPlace(Level* level, int x, int y, int z, unsigned char face);
bool mayPlace(Level* level, int x, int y, int z, unsigned char face) override;
static int getCompositeData(LevelSource* level, int x, int y, int z);
};