Skip to main content
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.
mouseComponent
Component*
Component for mouse input handling
parent
Canvas*
Parent canvas for rendering
minecraftApplet
MinecraftApplet*
Applet context (can be NULL)
width
int
Display width
height
int
Display height
fullscreen
bool
Whether to run in fullscreen mode

Core Methods

init

void init()
Initializes the Minecraft game instance, setting up textures, fonts, renderers, and other core systems.

run

void run()
Starts the main game loop. This method runs continuously until the game is stopped.

run_middle

void 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

void 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).
bFirst
bool
True for the first active viewport in splitscreen
bUpdateTextures
bool
True if renderer textures should be updated

destroy

void 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.
level
MultiPlayerLevel*
The level to set as active
message
int
default:"-1"
Message ID to display during level transition
forceInsertPlayer
shared_ptr<Player>
default:"nullptr"
Player to force insert into the level
doForceStatsSave
bool
default:"true"
Whether to force save player statistics
bPrimaryPlayerSignedOut
bool
default:"false"
Whether the primary player signed out

getLevel

MultiPlayerLevel *getLevel(int dimension)
Gets the level for a specific dimension.
dimension
int
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.
iPad
int
Input device index (0-3 for Xbox/PlayStation controllers)

createExtraLocalPlayer

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.
idx
int
Player index (0-3)
name
const wstring&
Player name
pad
int
Controller pad index
iDimension
int
Starting dimension

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

int getLocalPlayerIdx()
Gets the currently active local player index.

Screen Management

setScreen

void setScreen(Screen *screen)
Sets the current screen/menu.
screen
Screen*
The screen to display (NULL for in-game)

getScreen

Screen *getScreen()
Returns the currently displayed screen.

pauseGame

void 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
const wstring&
Server address or hostname
port
int
Server port number

getConnection

ClientConnection *getConnection(int iPad)
Gets the client connection for a specific player.
iPad
int
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

void emergencySave()
Performs an emergency save of the current game state.

Public Member Variables

width
int
Current display width
height
int
Current display height
width_phys
int
Physical framebuffer width
height_phys
int
Physical framebuffer height
level
MultiPlayerLevel*
Current active level
player
shared_ptr<MultiplayerLocalPlayer>
Current local player
localplayers
shared_ptr<MultiplayerLocalPlayer>[4]
Array of all local players for splitscreen
gameMode
MultiPlayerGameMode*
Current game mode handler
textures
Textures*
Texture manager
options
Options*
Game options and settings
soundEngine
SoundEngine*
Sound and music manager
gui
Gui*
In-game GUI renderer
levelRenderer
LevelRenderer*
Level/world renderer
gameRenderer
GameRenderer*
Main game renderer
pause
volatile bool
Whether the game is paused
running
volatile bool
Whether the game is running
skins
TexturePackRepository*
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.

Platform Considerations

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.

Build docs developers (and LLMs) love