The Minecraft class is the core client-side class that manages the game instance, including rendering, player management, level handling, and game loop execution.
Constructor
Minecraft(Component *mouseComponent, Canvas *parent, MinecraftApplet *minecraftApplet,
int width, int height, bool fullscreen)
Creates a new Minecraft game instance.
Component for mouse input handling
Parent canvas for rendering
Applet context (can be NULL)
Whether to run in fullscreen mode
Core Methods
init
Initializes the Minecraft game instance, setting up textures, fonts, renderers, and other core systems.
run
Starts the main game loop. This method runs continuously until the game is stopped.
run_middle
Executes the middle portion of the game loop. Split from run() to allow integration with platform-specific game loops (Xbox, PlayStation).
run_end
Executes the end portion of the game loop and cleanup.
tick
void tick(bool bFirst, bool bUpdateTextures)
Updates game state for one tick (called 20 times per second).
True for the first active viewport in splitscreen
True if renderer textures should be updated
destroy
Cleans up and destroys the Minecraft instance, releasing all resources.
Level Management
setLevel
void setLevel(MultiPlayerLevel *level, int message = -1,
shared_ptr<Player> forceInsertPlayer = nullptr,
bool doForceStatsSave = true, bool bPrimaryPlayerSignedOut = false)
Sets the active level/world.
The level to set as active
Message ID to display during level transition
forceInsertPlayer
shared_ptr<Player>
default:"nullptr"
Player to force insert into the level
Whether to force save player statistics
Whether the primary player signed out
getLevel
MultiPlayerLevel *getLevel(int dimension)
Gets the level for a specific dimension.
Dimension ID (0 = Overworld, -1 = Nether, 1 = The End)
selectLevel
void selectLevel(ConsoleSaveFile *saveFile, const wstring& levelId,
const wstring& levelName, LevelSettings *levelSettings)
Selects and loads a level from a save file.
releaseLevel
void releaseLevel(int message)
Releases the current level and displays a message.
Player Management
createPrimaryLocalPlayer
void createPrimaryLocalPlayer(int iPad)
Creates the primary local player for a given controller/input device.
Input device index (0-3 for Xbox/PlayStation controllers)
shared_ptr<MultiplayerLocalPlayer> createExtraLocalPlayer(
int idx, const wstring& name, int pad, int iDimension,
ClientConnection *clientConnection = NULL,
MultiPlayerLevel *levelpassedin = NULL)
Creates an additional local player for splitscreen multiplayer.
addLocalPlayer
bool addLocalPlayer(int idx)
Adds a local player to the game and rearranges the screen for splitscreen.
removeLocalPlayerIdx
void removeLocalPlayerIdx(int idx)
Removes a local player from the game.
setLocalPlayerIdx
bool setLocalPlayerIdx(int idx)
Sets the active local player index.
getLocalPlayerIdx
Gets the currently active local player index.
Screen Management
setScreen
void setScreen(Screen *screen)
Sets the current screen/menu.
The screen to display (NULL for in-game)
getScreen
Returns the currently displayed screen.
pauseGame
Pauses the game and displays the pause menu.
Connection Management
connectTo
void connectTo(const wstring& server, int port)
Connects to a multiplayer server.
Server address or hostname
getConnection
ClientConnection *getConnection(int iPad)
Gets the client connection for a specific player.
Player input device index
clearConnectionFailed
void clearConnectionFailed()
Clears connection failure flags.
Utility Methods
GetInstance
static Minecraft *GetInstance()
Returns the singleton Minecraft instance.
getAspectRatio
float getAspectRatio() const
Returns the true physical aspect ratio for perspective projection.
getLevelSource
LevelStorageSource *getLevelSource()
Returns the level storage source for loading/saving worlds.
getWorkingDirectory
static File getWorkingDirectory()
static File getWorkingDirectory(const wstring& applicationName)
Gets the game’s working directory.
onWindowResize
void onWindowResize(int width, int height)
Handles window resize events.
emergencySave
Performs an emergency save of the current game state.
Public Member Variables
Physical framebuffer width
Physical framebuffer height
player
shared_ptr<MultiplayerLocalPlayer>
Current local player
localplayers
shared_ptr<MultiplayerLocalPlayer>[4]
Array of all local players for splitscreen
Current game mode handler
Game options and settings
Whether the game is paused
Whether the game is running
Texture pack/skin repository
Static Constants
static const wstring VERSION_STRING;
The game version string.
static const int frameTimes_length = 512;
static __int64 frameTimes[frameTimes_length];
Frame timing data for performance monitoring.
static const int tickTimes_length = 512;
static __int64 tickTimes[tickTimes_length];
Tick timing data for performance monitoring.
Example Usage
Creating a Minecraft Instance
// Create Minecraft instance
Minecraft *minecraft = new Minecraft(mouseComponent, canvas, NULL, 1280, 720, false);
// Initialize the game
minecraft->init();
// Start the game loop
minecraft->run();
Loading a World
// Get the Minecraft instance
Minecraft *minecraft = Minecraft::GetInstance();
// Load a level
LevelSettings settings;
minecraft->selectLevel(saveFile, L"world1", L"My World", &settings);
Managing Splitscreen Players
// Add a second player for splitscreen
minecraft->addLocalPlayer(1);
// Create the player
auto player2 = minecraft->createExtraLocalPlayer(1, L"Player2", 1, 0);
// Switch active player
minecraft->setLocalPlayerIdx(1);
// Remove player when done
minecraft->removeLocalPlayerIdx(1);
Connecting to a Server
// Connect to multiplayer server
minecraft->connectTo(L"192.168.1.100", 25565);
// Check connection status
ClientConnection *conn = minecraft->getConnection(0);
if (conn && conn->isConnected()) {
// Successfully connected
}
Thread Safety
The setLevel method uses a critical section (m_setLevelCS). Always ensure proper synchronization when modifying level state from multiple threads.
The Minecraft class includes platform-specific code for:
- Xbox (DURANGO)
- PlayStation (ORBIS)
- PC (WINDOWS64)
- PS Vita (PSVITA)
Widescreen support maintains vertical FOV while adjusting horizontal FOV based on the physical aspect ratio.