server compilable

This commit is contained in:
Kolyah35
2026-03-26 03:48:08 +03:00
parent cbd81b47ce
commit a45c01d013
96 changed files with 3344 additions and 7975 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,229 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT__Minecraft_H__
#define NET_MINECRAFT_CLIENT__Minecraft_H__
#include "Options.h"
#ifndef STANDALONE_SERVER
#include "MouseHandler.h"
#include "gui/Gui.h"
#include "gui/screens/ScreenChooser.h"
#endif
#include "Timer.h"
//#include "../network/RakNetInstance.h"
#include "../world/phys/HitResult.h"
class Level;
class LocalPlayer;
class IInputHolder;
class Mob;
class Player;
class LevelRenderer;
class GameRenderer;
class ParticleEngine;
class Entity;
class ICreator;
class GameMode;
class Textures;
class CThread;
class SoundEngine;
class Screen;
class Font;
class LevelStorageSource;
class BuildActionIntention;
class PerfRenderer;
class LevelSettings;
class IRakNetInstance;
class NetEventCallback;
class CommandServer;
struct PingedCompatibleServer;
//class ExternalFileLevelStorageSource;
#include "../App.h"
#include "PixelCalc.h"
class AppPlatform;
class AppPlatform_android;
class Minecraft: public App
{
protected:
Minecraft();
public:
virtual ~Minecraft();
void init();
void setSize(int width, int height);
void reloadOptions();
bool supportNonTouchScreen();
bool useTouchscreen();
void grabMouse();
void releaseMouse();
void handleBuildAction(BuildActionIntention*);
void toggleDimension(){}
bool isCreativeMode();
void setIsCreativeMode(bool isCreative);
void setScreen(Screen*);
virtual void selectLevel(const std::string& levelId, const std::string& levelName, const LevelSettings& settings);
virtual void setLevel(Level* level, const std::string& message = "", LocalPlayer* forceInsertPlayer = NULL);
void generateLevel( const std::string& message, Level* level );
LevelStorageSource* getLevelSource();
bool isLookingForMultiplayer;
void locateMultiplayer();
void cancelLocateMultiplayer();
bool joinMultiplayer(const PingedCompatibleServer& server);
bool joinMultiplayerFromString(const std::string& server);
void hostMultiplayer(int port=19132);
Player* respawnPlayer(int playerId);
void respawnPlayer();
void resetPlayer(Player* player);
void doActuallyRespawnPlayer();
void update();
void tick(int nTick, int maxTick);
void tickInput();
bool isOnlineClient();
bool isOnline();
void pauseGame(bool isBackPaused);
void gameLostFocus();
void prepareLevel(const std::string& message);
void leaveGame(bool renameLevel = false);
int getProgressStatusId();
const char* getProgressMessage();
ICreator* getCreator();
// void onGraphicsLost() {}
void onGraphicsReset();
bool isLevelGenerated();
void handleMouseDown(int button, bool down);
void audioEngineOn();
void audioEngineOff();
bool isPowerVR() { return _powerVr; }
bool isKindleFire(int kindleVersion);
bool transformResolution(int* w, int* h);
void optionUpdated(OptionId option, bool value);
void optionUpdated(OptionId option, float value);
void optionUpdated(OptionId option, int value);
#ifdef __APPLE__
bool _isSuperFast;
bool isSuperFast() { return _isSuperFast; }
#endif
protected:
void _levelGenerated();
private:
static void* prepareLevel_tspawn(void *p_param);
void _reloadInput();
public:
int width;
int height;
// Vars that the platform is allowed to use in the future
int commandPort;
int reserved_d1, reserved_d2;
float reserved_f1, reserved_f2;
Options options;
static bool useAmbientOcclusion;
//static bool threadInterrupt;
volatile bool pause;
LevelRenderer* levelRenderer;
GameRenderer* gameRenderer;
ParticleEngine* particleEngine;
SoundEngine* soundEngine;
GameMode* gameMode;
#ifndef STANDALONE_SERVER
Textures* textures;
ScreenChooser screenChooser;
Font* font;
#endif
IRakNetInstance* raknetInstance;
NetEventCallback* netCallback;
int lastTime;
int lastTickTime;
float ticksSinceLastUpdate;
Level* level;
LocalPlayer* player;
IInputHolder* inputHolder;
Mob* cameraTargetPlayer;
#ifndef STANDALONE_SERVER
Gui gui;
#endif
CThread* generateLevelThread;
Screen* screen;
static int customDebugId;
static const int CDI_NONE = 0;
static const int CDI_GRAPHICS = 1;
#ifndef STANDALONE_SERVER
MouseHandler mouseHandler;
#endif
bool mouseGrabbed;
PixelCalc pixelCalc;
PixelCalc pixelCalcUi;
HitResult hitResult;
volatile int progressStagePercentage;
// This field is initialized in main()
// It sets the base path to where worlds can be written (sdcard on android)
std::string externalStoragePath;
std::string externalCacheStoragePath;
protected:
Timer timer;
// @note @attn @warn: this is dangerous as fuck!
volatile bool isGeneratingLevel;
bool _hasSignaledGeneratingLevelFinished;
LevelStorageSource* storageSource;
bool _running;
bool _powerVr;
private:
volatile int progressStageStatusId;
static const char* progressMessages[];
int missTime;
int ticks;
bool screenMutex;
bool hasScheduledScreen;
Screen* scheduledScreen;
int _licenseId;
bool _supportsNonTouchscreen;
bool _isCreativeMode;
//int _respawnPlayerTicks;
Player* _pendingRemovePlayer; // @attn @todo @fix: remove this shait and fix the respawn behaviour
PerfRenderer* _perfRenderer;
CommandServer* _commandServer;
};
#endif /*NET_MINECRAFT_CLIENT__Minecraft_H__*/

View File

@@ -1,11 +1,6 @@
#include "Options.h"
#include "OptionStrings.h"
#include "Minecraft.h"
#include "../platform/log.h"
#include "../world/Difficulty.h"
#include <cmath>
#include <memory>
#include <MinecraftClient.h>
bool Options::debugGl = false;
@@ -290,13 +285,13 @@ void Options::setOptionsFilePath(const std::string& path) {
}
void Options::notifyOptionUpdate(OptionId key, bool value) {
minecraft->optionUpdated(key, value);
minecraft.optionUpdated(key, value);
}
void Options::notifyOptionUpdate(OptionId key, float value) {
minecraft->optionUpdated(key, value);
minecraft.optionUpdated(key, value);
}
void Options::notifyOptionUpdate(OptionId key, int value) {
minecraft->optionUpdated(key, value);
minecraft.optionUpdated(key, value);
}

View File

@@ -15,9 +15,8 @@
//#include "locale/Language.h"
#include <string>
#include <cstdio>
#include "../platform/input/Keyboard.h"
#include "../util/StringUtils.h"
#include <platform/input/Keyboard.h>
#include <util/StringUtils.h>
#include "OptionsFile.h"
#include "Option.h"
#include <array>
@@ -88,7 +87,7 @@ enum OptionId {
OPTIONS_COUNT
};
class Minecraft;
class MinecraftClient;
typedef std::vector<std::string> StringVector;
class Options
@@ -96,7 +95,7 @@ class Options
public:
static bool debugGl;
Options(Minecraft* minecraft, const std::string& workingDirectory = "")
Options(MinecraftClient& minecraft, const std::string& workingDirectory = "")
: minecraft(minecraft) {
// elements werent initialized so i was getting a garbage pointer and a crash
m_options.fill(nullptr);
@@ -161,7 +160,7 @@ private:
std::array<Option*, OPTIONS_COUNT> m_options;
OptionsFile optionsFile;
Minecraft* minecraft;
MinecraftClient& minecraft;
};
#endif /*NET_MINECRAFT_CLIENT__Options_H__*/

View File

@@ -1,56 +0,0 @@
#include "CreativeMode.h"
#include "../Minecraft.h"
#ifndef STANDALONE_SERVER
#include "../particle/ParticleEngine.h"
#endif
#include "../player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "../renderer/LevelRenderer.h"
#include "../sound/SoundEngine.h"
#endif
#include "../../world/level/Level.h"
//#include "../../network/Packet.h"
#include "../../network/packet/RemoveBlockPacket.h"
#include "../../world/entity/player/Abilities.h"
static const int DestructionTickDelay = 5;
CreativeMode::CreativeMode(Minecraft* minecraft)
: super(minecraft)
{
}
void CreativeMode::startDestroyBlock(int x, int y, int z, int face) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
creativeDestroyBlock(x, y, z, face);
destroyDelay = DestructionTickDelay;
}
void CreativeMode::creativeDestroyBlock(int x, int y, int z, int face) {
minecraft->level->extinguishFire(x, y, z, face);
destroyBlock(x, y, z, face);
}
void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) {
destroyDelay--;
if (destroyDelay <= 0) {
destroyDelay = DestructionTickDelay;
creativeDestroyBlock(x, y, z, face);
}
}
void CreativeMode::stopDestroyBlock() {
destroyDelay = 0;
}
void CreativeMode::initAbilities( Abilities& abilities ) {
abilities.mayfly = true;
abilities.instabuild = true;
abilities.invulnerable = true;
}
bool CreativeMode::isCreativeType() {
return true;
}

View File

@@ -1,26 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
//package net.minecraft.client.gamemode;
#include "GameMode.h"
class CreativeMode: public GameMode
{
typedef GameMode super;
public:
CreativeMode(Minecraft* minecraft);
void startDestroyBlock(int x, int y, int z, int face);
void continueDestroyBlock(int x, int y, int z, int face);
void stopDestroyBlock();
bool isCreativeType();
void initAbilities(Abilities& abilities);
private:
void creativeDestroyBlock(int x, int y, int z, int face);
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/

View File

@@ -1,102 +0,0 @@
#include "CreatorMode.h"
#include "../Minecraft.h"
#include "../particle/ParticleEngine.h"
#include "../player/LocalPlayer.h"
#include "../renderer/LevelRenderer.h"
#include "../sound/SoundEngine.h"
#include "../../world/level/Level.h"
//#include "../../network/Packet.h"
#include "../../network/packet/RemoveBlockPacket.h"
#include "../../world/entity/player/Abilities.h"
static const int DestructionTickDelay = 5;
class Creator: public ICreator {
//virtual void getEvents();
public:
Creator(/*int eventLifeTime*/)
: _tileEvents(32),
_tickId(0)
{
}
void setTick(int tick) {
_tickId = tick;
}
EventList<TileEvent>& getTileEvents() { return _tileEvents; }
void addevent_blockUse(int entityId, int x, int y, int z, int face) {
TileEvent t = {
entityId,
x,y,z,
face
};
_tileEvents.add(t, _tickId);
}
private:
EventList<TileEvent> _tileEvents;
int _tickId;
};
CreatorMode::CreatorMode(Minecraft* minecraft)
: super(minecraft)
{
_creator = new Creator();
}
CreatorMode::~CreatorMode() {
delete _creator;
}
void CreatorMode::startDestroyBlock(int x, int y, int z, int face) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
CreatorDestroyBlock(x, y, z, face);
destroyDelay = DestructionTickDelay;
}
void CreatorMode::CreatorDestroyBlock(int x, int y, int z, int face) {
minecraft->level->extinguishFire(x, y, z, face);
destroyBlock(x, y, z, face);
}
void CreatorMode::continueDestroyBlock(int x, int y, int z, int face) {
destroyDelay--;
if (destroyDelay <= 0) {
destroyDelay = DestructionTickDelay;
CreatorDestroyBlock(x, y, z, face);
}
}
bool CreatorMode::useItemOn( Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit ) {
if (item && item->id == ((Item*)Item::sword_iron)->id)
_creator->addevent_blockUse(player->entityId, x, y, z, face);
return super::useItemOn(player, level, item, x, y, z, face, hit);
}
void CreatorMode::stopDestroyBlock() {
destroyDelay = 0;
}
void CreatorMode::initAbilities( Abilities& abilities ) {
abilities.mayfly = true;
abilities.instabuild = true;
abilities.invulnerable = true;
}
bool CreatorMode::isCreativeType() {
return true;
}
ICreator* CreatorMode::getCreator() {
return _creator;
}
void CreatorMode::tick() {
_creator->setTick(minecraft->level->getTime());
super::tick();
}

View File

@@ -1,127 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
//package net.minecraft.client.gamemode;
#include "GameMode.h"
#include "../../world/PosTranslator.h"
class ICreator {
public:
virtual ~ICreator() {}
struct TileEvent {
int entityId;
int x, y, z;
int face;
void write(std::stringstream& ss, IPosTranslator& t) const {
int xx = x, yy = y, zz = z;
t.to(xx, yy, zz);
ss << xx << "," << yy << "," << zz << "," << face << "," << entityId;
}
};
template <class T>
class EventList {
public:
EventList(int size) {
_events.reserve(size);
_maxSize = (int)size;
clear();
}
void clear() {
_index = -1;
_size = 0;
}
void add(const T& item, int tick) {
if (_size < _maxSize) {
_events.push_back(Item());
++_size;
}
Item& e = _events[_nextIndex()];
e.item = item;
e.timestamp = tick;
}
int size() const {
return _size;
}
const T& operator[](int i) const {
return _events[_getIndex(i)].item;
}
T& operator[](int i) {
return _events[_getIndex(i)].item;
}
void write(std::stringstream& ss, IPosTranslator& t, int minTimetamp) const {
int i = _getFirstNewerIndex(minTimetamp);
if (i < 0)
return;
while (1) {
_events[i].item.write(ss, t);
if (i == _index) return;
ss << "|";
if (++i == _size) i = 0;
}
}
private:
int _getIndex(int i) const { return (1 + _index + i) % _size; }
int _nextIndex() {
if (++_index == _size) _index = 0;
return _index;
}
int _getFirstNewerIndex(int timestamp) const {
for (int i = _index + 1, j = 0; j < _size; ++i, ++j) {
if (i == _size) i = 0;
if (_events[i].timestamp >= timestamp) return i;
}
return -1;
}
struct Item {
int timestamp;
T item;
};
int _index;
int _size;
int _maxSize;
std::vector<Item> _events;
};
virtual EventList<TileEvent>& getTileEvents() = 0;
};
class Creator;
class CreatorMode: public GameMode
{
typedef GameMode super;
public:
CreatorMode(Minecraft* minecraft);
~CreatorMode();
void startDestroyBlock(int x, int y, int z, int face);
void continueDestroyBlock(int x, int y, int z, int face);
void stopDestroyBlock();
bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
void tick();
ICreator* getCreator();
bool isCreativeType();
void initAbilities(Abilities& abilities);
private:
void CreatorDestroyBlock(int x, int y, int z, int face);
Creator* _creator;
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__*/

View File

@@ -1,174 +0,0 @@
#include "GameMode.h"
#include "../Minecraft.h"
#include "../../network/packet/UseItemPacket.h"
#include "../../network/packet/PlayerActionPacket.h"
#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"
#endif
#include "../../network/RakNetInstance.h"
#include "../../network/packet/RemoveBlockPacket.h"
#ifndef STANDALONE_SERVER
#include "../renderer/LevelRenderer.h"
#endif
#include "../../world/level/material/Material.h"
GameMode::GameMode( Minecraft* minecraft)
: minecraft(minecraft),
destroyProgress(0),
oDestroyProgress(0),
destroyTicks(0),
destroyDelay(0)
{
}
/*virtual*/
Player* GameMode::createPlayer(Level* level) {
return new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType());
}
/*virtual*/
void GameMode::interact(Player* player, Entity* entity) {
player->interact(entity);
}
/*virtual*/
void GameMode::attack(Player* player, Entity* entity) {
if (minecraft->level->adventureSettings.noPvP && entity->isPlayer())
return;
if (minecraft->level->adventureSettings.noPvM && entity->isMob())
return;
player->attack(entity);
}
/* virtual */
void GameMode::startDestroyBlock( int x, int y, int z, int face ) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
destroyBlock(x, y, z, face);
}
/*virtual*/
bool GameMode::destroyBlock(int x, int y, int z, int face) {
Level* level = minecraft->level;
Tile* oldTile = Tile::tiles[level->getTile(x, y, z)];
if (!oldTile)
return false;
if (level->adventureSettings.immutableWorld) {
if (oldTile != (Tile*)Tile::leaves
&& oldTile->material != Material::plant) {
return false;
}
}
#ifndef STANDALONE_SERVER
minecraft->particleEngine->destroy(x, y, z);
#endif
int data = level->getData(x, y, z);
bool changed = level->setTile(x, y, z, 0);
if (changed) {
#ifndef STANDALONE_SERVER
minecraft->soundEngine->play(oldTile->soundType->getBreakSound(), x + 0.5f, y + 0.5f, z + 0.5f, (oldTile->soundType->getVolume() + 1) / 2, oldTile->soundType->getPitch() * 0.8f);
#endif
oldTile->destroy(level, x, y, z, data);
if (minecraft->options.getBooleanValue(OPTIONS_DESTROY_VIBRATION)) minecraft->platform()->vibrate(24);
if (minecraft->isOnline()) {
RemoveBlockPacket packet(minecraft->player, x, y, z);
minecraft->raknetInstance->send(packet);
}
}
return changed;
}
/*virtual*/
bool GameMode::useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit) {
float clickX = hit.x - x;
float clickY = hit.y - y;
float clickZ = hit.z - z;
if (level->isClientSide) {
item = player->inventory->getSelected();
UseItemPacket packet(x, y, z, face, item, player->entityId, clickX, clickY, clickZ);
minecraft->raknetInstance->send(packet);
}
int t = level->getTile(x, y, z);
if (t == Tile::invisible_bedrock->id) return false;
if (t > 0 && Tile::tiles[t]->use(level, x, y, z, player))
return true;
if (item == NULL) return false;
if(isCreativeType()) {
int aux = item->getAuxValue();
int count = item->count;
bool success = item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
item->setAuxValue(aux);
item->count = count;
return success;
} else {
return item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
}
}
bool GameMode::useItem( Player* player, Level* level, ItemInstance* item ) {
int oldCount = item->count;
ItemInstance* itemInstance = item->use(level, player);
if(level->isClientSide) {
UseItemPacket packet(item, player->entityId, player->aimDirection);
minecraft->raknetInstance->send(packet);
}
if (itemInstance != item || (itemInstance != NULL && itemInstance->count != oldCount)) {
//player.inventory.items[player.inventory.selected] = itemInstance;
//if (itemInstance.count == 0) {
// player.inventory.items[player.inventory.selected] = NULL;
//}
return true;
}
return false;
}
ItemInstance* GameMode::handleInventoryMouseClick( int containerId, int slotNum, int buttonNum, Player* player ) {
//return player.containerMenu.clicked(slotNum, buttonNum, player);
return NULL;
}
void GameMode::handleCloseInventory( int containerId, Player* player ) {
//player.containerMenu.removed(player);
//player.containerMenu = player.inventoryMenu;
}
float GameMode::getPickRange() {
return 5.0f;
}
void GameMode::initPlayer( Player* player ) {
initAbilities(player->abilities);
}
void GameMode::releaseUsingItem(Player* player){
if (minecraft->level->isClientSide && player->isUsingItem()) {
PlayerActionPacket packet(PlayerActionPacket::RELEASE_USE_ITEM, 0, 0, 0, 0, player->entityId);
minecraft->raknetInstance->send(packet);
}
player->releaseUsingItem();
}
void GameMode::tick() {
oDestroyProgress = destroyProgress;
}
void GameMode::render( float a ) {
#ifndef STANDALONE_SERVER
if (destroyProgress <= 0) {
minecraft->gui.progress = 0;
minecraft->levelRenderer->destroyProgress = 0;
} else {
float dp = oDestroyProgress + (destroyProgress - oDestroyProgress) * a;
minecraft->gui.progress = dp;
minecraft->levelRenderer->destroyProgress = dp;
}
#endif
}

View File

@@ -1,63 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__
//package net.minecraft.client.gamemode;
#include "../../world/level/tile/Tile.h"
class ItemInstance;
class Minecraft;
class Level;
class Player;
class Abilities;
class GameMode
{
protected:
Minecraft* minecraft;
public:
GameMode(Minecraft* minecraft);
virtual ~GameMode() {}
virtual void initLevel(Level* level) {}
virtual void startDestroyBlock(int x, int y, int z, int face);
virtual bool destroyBlock(int x, int y, int z, int face);
virtual void continueDestroyBlock(int x, int y, int z, int face) = 0;
virtual void stopDestroyBlock() {}
virtual void tick();
virtual void render(float a);
virtual float getPickRange();
/* void postLevelGen(LevelGen levelGen, Level level) {} */
virtual bool useItem(Player* player, Level* level, ItemInstance* item);
virtual bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
virtual Player* createPlayer(Level* level);
virtual void initPlayer(Player* player);
virtual void adjustPlayer(Player* player) {}
virtual bool canHurtPlayer() { return false; }
virtual void interact(Player* player, Entity* entity);
virtual void attack(Player* player, Entity* entity);
virtual ItemInstance* handleInventoryMouseClick(int containerId, int slotNum, int buttonNum, Player* player);
virtual void handleCloseInventory(int containerId, Player* player);
virtual bool isCreativeType() { return false; }
virtual bool isSurvivalType() { return false; }
virtual void initAbilities(Abilities& abilities) {}
virtual void releaseUsingItem(Player* player);
float oDestroyProgress;
float destroyProgress;
protected:
int destroyTicks;
int destroyDelay;
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__*/

View File

@@ -1,98 +0,0 @@
#include "SurvivalMode.h"
#include "../Minecraft.h"
#include "../player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "../particle/ParticleEngine.h"
#include "../sound/SoundEngine.h"
#endif
#include "../../world/level/Level.h"
#include "../../world/entity/player/Abilities.h"
SurvivalMode::SurvivalMode( Minecraft* minecraft )
: super(minecraft),
xDestroyBlock(-1),
yDestroyBlock(-1),
zDestroyBlock(-1)
{
}
void SurvivalMode::continueDestroyBlock( int x, int y, int z, int face ) {
if (destroyDelay > 0) {
destroyDelay--;
return;
}
if (x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock) {
int t = minecraft->level->getTile(x, y, z);
if (t == 0) return;
Tile* tile = Tile::tiles[t];
destroyProgress += tile->getDestroyProgress(minecraft->player);
if ((++destroyTicks & 3) == 1) {
#ifndef STANDALONE_SERVER
if (tile != NULL) {
minecraft->soundEngine->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f);
}
#endif
}
if (destroyProgress >= 1) {
destroyBlock(x, y, z, face);
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 5;
}
} else {
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
xDestroyBlock = x;
yDestroyBlock = y;
zDestroyBlock = z;
}
}
bool SurvivalMode::destroyBlock( int x, int y, int z, int face ) {
int t = minecraft->level->getTile(x, y, z);
int data = minecraft->level->getData(x, y, z);
bool changed = GameMode::destroyBlock(x, y, z, face);
bool couldDestroy = minecraft->player->canDestroy(Tile::tiles[t]);
ItemInstance* item = minecraft->player->inventory->getSelected();
if (item != NULL) {
item->mineBlock(t, x, y, z);
if (item->count == 0) {
//item->snap(minecraft->player);
minecraft->player->inventory->clearSlot(minecraft->player->inventory->selected);
}
}
if (changed && couldDestroy) {
ItemInstance instance(t, 1, data);
Tile::tiles[t]->playerDestroy(minecraft->level, minecraft->player, x, y, z, data);
}
return changed;
}
void SurvivalMode::stopDestroyBlock() {
destroyProgress = 0;
destroyDelay = 0;
}
void SurvivalMode::initAbilities( Abilities& abilities ) {
abilities.flying = false;
abilities.mayfly = false;
abilities.instabuild = false;
abilities.invulnerable = false;
}
void SurvivalMode::startDestroyBlock( int x, int y, int z, int face ) {
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
return;
int t = minecraft->level->getTile(x, y, z);
if (t > 0 && destroyProgress == 0) Tile::tiles[t]->attack(minecraft->level, x, y, z, minecraft->player);
if (t > 0 && Tile::tiles[t]->getDestroyProgress(minecraft->player) >= 1)
destroyBlock(x, y, z, face);
}

View File

@@ -1,31 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
#define NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
#include "GameMode.h"
class Abilities;
class Minecraft;
class SurvivalMode: public GameMode
{
typedef GameMode super;
public:
SurvivalMode(Minecraft* minecraft);
bool destroyBlock(int x, int y, int z, int face);
void startDestroyBlock(int x, int y, int z, int face);
void continueDestroyBlock(int x, int y, int z, int face);
void stopDestroyBlock();
bool canHurtPlayer() { return true; }
bool isSurvivalType() { return true; }
void initAbilities( Abilities& abilities );
private:
int xDestroyBlock;
int yDestroyBlock;
int zDestroyBlock;
};
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__*/

View File

@@ -1,11 +1,12 @@
#include "Gui.h"
#include "Font.h"
#include "MinecraftClient.h"
#include "client/Options.h"
#include "platform/input/Keyboard.h"
#include "screens/IngameBlockSelectionScreen.h"
#include "screens/ChatScreen.h"
#include "screens/ConsoleScreen.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../player/LocalPlayer.h"
#include "../renderer/Tesselator.h"
#include "../renderer/TileRenderer.h"
@@ -29,39 +30,23 @@
#include <algorithm>
#include <sstream>
#define MAX_MESSAGE_WIDTH 240
float Gui::InvGuiScale = 1.0f / 3.0f;
float Gui::GuiScale = 1.0f / Gui::InvGuiScale;
const float Gui::DropTicks = 40.0f;
//#include <android/log.h>
Gui::Gui(Minecraft* minecraft)
: minecraft(minecraft),
tickCount(0),
progress(0),
overlayMessageTime(0),
animateOverlayMessageColor(false),
chatScrollOffset(0),
tbr(1),
_inventoryNeedsUpdate(true),
_flashSlotId(-1),
_flashSlotStartTime(-1),
_slotFont(NULL),
_numSlots(4),
_currentDropTicks(-1),
_currentDropSlot(-1),
MAX_MESSAGE_WIDTH(240),
itemNameOverlayTime(2),
_openInventorySlot(minecraft->useTouchscreen())
{
// @todo virtual controlConfigurationChanged() when player switches from keyboard to touch for example
Gui::Gui(MinecraftClient& minecraft) : minecraft(minecraft), _openInventorySlot(minecraft.useTouchscreen()) {
glGenBuffers2(1, &_inventoryRc.vboId);
glGenBuffers2(1, &rcFeedbackInner.vboId);
glGenBuffers2(1, &rcFeedbackOuter.vboId);
//Gui::InvGuiScale = 1.0f / (int) (3 * Minecraft::width / 854);
}
Gui::~Gui()
{
Gui::~Gui() {
if (_slotFont)
delete _slotFont;
@@ -69,17 +54,16 @@ Gui::~Gui()
}
void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
if (!minecraft->level || !minecraft->player)
if (!minecraft.level || !minecraft.getPlayer())
return;
//minecraft->gameRenderer->setupGuiScreen();
Font* font = minecraft->font;
Font* font = minecraft.getFont();
const bool isTouchInterface = minecraft->useTouchscreen();
const bool isTouchInterface = minecraft.useTouchscreen();
const int screenWidth = (int)(minecraft->width * InvGuiScale);
const int screenHeight = (int)(minecraft->height * InvGuiScale);
const int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale);
const int screenHeight = (int)(minecraft.getScreenHeigth() * InvGuiScale);
blitOffset = -90;
renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a);
@@ -91,9 +75,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
// F: 3
int ySlot = screenHeight - 16 - 3;
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
if (minecraft->gameMode->canHurtPlayer()) {
minecraft->textures->loadAndBindTexture("gui/icons.png");
if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
if (minecraft.gameMode->canHurtPlayer()) {
minecraft.getTextures()->loadAndBindTexture("gui/icons.png");
Tesselator& t = Tesselator::instance;
t.beginOverride();
t.colorABGR(0xffffffff);
@@ -103,7 +87,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
}
}
if(minecraft->player->getSleepTimer() > 0) {
if(minecraft.getPlayer()->getSleepTimer() > 0) {
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
@@ -112,7 +96,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
}
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
renderToolBar(a, ySlot, screenWidth);
glEnable(GL_BLEND);

View File

@@ -10,7 +10,7 @@
#include "../../util/Random.h"
#include "../IConfigListener.h"
class Minecraft;
class MinecraftClient;
class ItemInstance;
class Textures;
class Tesselator;
@@ -27,7 +27,7 @@ typedef std::vector<GuiMessage> GuiMessageList;
class Gui: public GuiComponent, IConfigListener
{
public:
Gui(Minecraft* minecraft);
Gui(MinecraftClient& minecraft);
~Gui();
int getSlotIdAt(int x, int y);
@@ -90,43 +90,42 @@ private:
void tickItemDrop();
float cubeSmoothStep(float percentage, float min, float max);
public:
float progress;
float progress = 0.f;
std::string selectedName;
static float InvGuiScale;
static float GuiScale;
private:
int MAX_MESSAGE_WIDTH;
//ItemRenderer itemRenderer;
GuiMessageList guiMessages;
int chatScrollOffset;
int chatScrollOffset = 0;
Random random;
Minecraft* minecraft;
int tickCount;
float itemNameOverlayTime;
MinecraftClient& minecraft;
int tickCount = 0;
float itemNameOverlayTime = 2;
std::string overlayMessageString;
int overlayMessageTime;
bool animateOverlayMessageColor;
int overlayMessageTime = 0;
bool animateOverlayMessageColor = false;
float tbr;
float tbr = 1.f;
RenderChunk _inventoryRc;
bool _inventoryNeedsUpdate;
bool _inventoryNeedsUpdate = true;
int _flashSlotId;
float _flashSlotStartTime;
int _flashSlotId = -1;
float _flashSlotStartTime = -1;
Font* _slotFont;
int _numSlots;
Font* _slotFont = nullptr;
int _numSlots = 4;
RenderChunk rcFeedbackOuter;
RenderChunk rcFeedbackInner;
// For dropping
static const float DropTicks;
float _currentDropTicks;
int _currentDropSlot;
float _currentDropTicks = -1;
int _currentDropSlot = -1;
bool _openInventorySlot;
};

View File

@@ -1,7 +1,7 @@
#include "Screen.h"
#include "components/Button.h"
#include "components/TextBox.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../renderer/Tesselator.h"
#include "../sound/SoundEngine.h"
#include "../../platform/input/Keyboard.h"

View File

@@ -1,14 +1,14 @@
#include "RolledSelectionListH.h"
#include "../../Minecraft.h"
#include "../../renderer/Tesselator.h"
#include "../../renderer/gles.h"
#include "../../../platform/input/Mouse.h"
#include "../../../platform/input/Multitouch.h"
#include "../../../util/Mth.h"
#include "../../renderer/Textures.h"
#include "MinecraftClient.h"
RolledSelectionListH::RolledSelectionListH( Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
: minecraft(minecraft),
width(width),
height(height),
@@ -172,7 +172,7 @@ void RolledSelectionListH::render( int xm, int ym, float a )
//LOGI("x: %f\n", xo);
minecraft->textures->loadAndBindTexture("gui/background.png");
minecraft.textures().loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1);
float s = 32;
t.begin();
@@ -280,7 +280,7 @@ void RolledSelectionListH::render( int xm, int ym, float a )
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
{
Tesselator& t = Tesselator::instance;
minecraft->textures->loadAndBindTexture("gui/background.png");
minecraft.textures().loadAndBindTexture("gui/background.png");
glColor4f2(1.0f, 1, 1, 1);
float s = 32;
t.begin();

View File

@@ -2,7 +2,7 @@
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
#include "../GuiComponent.h"
class Minecraft;
class MinecraftClient;
class Tesselator;
@@ -12,7 +12,7 @@ class RolledSelectionListH : public GuiComponent
static const int DRAG_OUTSIDE = -2;
static const int DRAG_NORMAL = 0;
public:
RolledSelectionListH(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
RolledSelectionListH(MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
virtual int getItemAtPosition(int x, int y);
@@ -45,7 +45,7 @@ protected:
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
int getItemAtXPositionRaw(int x);
protected:
Minecraft* minecraft;
MinecraftClient& minecraft;
float x0;
float x1;

View File

@@ -22,7 +22,7 @@
//static NinePatchLayer* guiPaneFrame = NULL;
static __inline void setIfNotSet(bool& ref, bool condition) {
static inline void setIfNotSet(bool& ref, bool condition) {
ref = (ref || condition);
}

View File

@@ -9,7 +9,7 @@
#include "../Gui.h"
#include "../../renderer/Textures.h"
#include "../../gamemode/GameMode.h"
#include <gamemode/GameMode.h>
#include "ArmorScreen.h"
#include "../components/Button.h"

View File

@@ -1,55 +0,0 @@
#include "RenameMPLevelScreen.h"
#include "StartMenuScreen.h"
#include "DialogDefinitions.h"
#include "../Gui.h"
#include "../../Minecraft.h"
#include "../../../AppPlatform.h"
#include "../../../platform/log.h"
#include "../../../world/level/storage/LevelStorageSource.h"
static char ILLEGAL_FILE_CHARACTERS[] = {
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
};
RenameMPLevelScreen::RenameMPLevelScreen( const std::string& levelId )
: _levelId(levelId)
{
}
void RenameMPLevelScreen::init() {
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_RENAME_MP_WORLD);
}
void RenameMPLevelScreen::render(int xm, int ym, float a)
{
renderBackground();
#ifdef WIN32
minecraft->getLevelSource()->renameLevel(_levelId, "Save?Level");
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
#else
int status = minecraft->platform()->getUserInputStatus();
if (status > -1) {
if (status == 1) {
std::vector<std::string> v = minecraft->platform()->getUserInput();
if (!v.empty()) {
// Read the level name.
// 1) Trim name 2) Remove all bad chars -) We don't have to getUniqueLevelName, since renameLevel will do that
std::string levelId = v[0];
for (int i = 0; i < sizeof(ILLEGAL_FILE_CHARACTERS) / sizeof(char); ++i)
levelId = Util::stringReplace(levelId, std::string(1, ILLEGAL_FILE_CHARACTERS[i]), "");
if ((int)levelId.length() == 0) {
levelId = "saved_world";
}
minecraft->getLevelSource()->renameLevel(_levelId, levelId);
}
}
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
}
#endif
}

View File

@@ -1,18 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__RenameMPLevelScreen_H__
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__RenameMPLevelScreen_H__
#include "../Screen.h"
class RenameMPLevelScreen: public Screen
{
public:
RenameMPLevelScreen(const std::string& levelId);
virtual void init();
virtual void render(int xm, int ym, float a);
private:
std::string _levelId;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__RenameMPLevelScreen_H__*/

View File

@@ -1,5 +1,6 @@
#include "ScreenChooser.h"
#include "StartMenuScreen.h"
#include "MinecraftClient.h"
#include "SelectWorldScreen.h"
#include "JoinGameScreen.h"
#include "PauseScreen.h"
@@ -58,6 +59,6 @@ Screen* ScreenChooser::createScreen( ScreenId id )
Screen* ScreenChooser::setScreen(ScreenId id)
{
Screen* screen = createScreen(id);
_mc->setScreen(screen);
_mc.setScreen(screen);
return screen;
}

View File

@@ -14,19 +14,17 @@ enum ScreenId {
};
class Screen;
class Minecraft;
class MinecraftClient;
class ScreenChooser
{
public:
ScreenChooser(Minecraft* mc)
: _mc(mc)
{}
ScreenChooser(MinecraftClient& mc) : _mc(mc) {}
Screen* createScreen(ScreenId id);
Screen* setScreen(ScreenId id);
private:
Minecraft* _mc;
MinecraftClient& _mc;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__ScreenChooser_H__*/

View File

@@ -1,4 +1,5 @@
#include "SelectWorldScreen.h"
#include "MinecraftClient.h"
#include "StartMenuScreen.h"
#include "ProgressScreen.h"
#include "DialogDefinitions.h"
@@ -22,7 +23,7 @@ static float Max(float a, float b) {
//
// World Selection List
//
WorldSelectionList::WorldSelectionList( Minecraft* minecraft, int width, int height )
WorldSelectionList::WorldSelectionList( MinecraftClient& minecraft, int width, int height )
: _height(height),
hasPickedLevel(false),
currentTick(0),

View File

@@ -5,11 +5,11 @@
#include "../TweenData.h"
#include "../components/Button.h"
#include "../components/RolledSelectionListH.h"
#include "../../Minecraft.h"
#include "../../../world/level/storage/LevelStorageSource.h"
class SelectWorldScreen;
class MinecraftClient;
//
// Scrolling World selection list
@@ -17,7 +17,7 @@ class SelectWorldScreen;
class WorldSelectionList : public RolledSelectionListH
{
public:
WorldSelectionList(Minecraft* _minecraft, int _width, int _height);
WorldSelectionList(MinecraftClient& _minecraft, int _width, int _height);
virtual void tick();
void stepLeft();
void stepRight();

View File

@@ -3,7 +3,7 @@
#include "../../Screen.h"
#include "../../components/ImageButton.h"
#include "../../components/InventoryPane.h"
#include "../../../gamemode/GameMode.h"
#include <gamemode/GameMode.h>
#include "../../../renderer/TileRenderer.h"
#include "../../../player/LocalPlayer.h"
#include "../../../renderer/gles.h"
@@ -91,8 +91,7 @@ void IngameBlockSelectionScreen::init()
//for (int i = 0; i < inventory->getContainerSize(); ++i)
//LOGI("> %d - %s\n", i, inventory->getItem(i)? inventory->getItem(i)->getDescriptionId().c_str() : "<-->\n");
// Grid indices are 0..N-1 for main inventory only; slots 0..MAX_SELECTION_SIZE-1 are hotbar links.
InventorySize = inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE;
InventorySize = inventory->getContainerSize();
InventoryRows = 1 + (InventorySize-1) / InventoryColumns;
//
@@ -266,8 +265,7 @@ void IngameBlockSelectionScreen::buttonClicked(Button* button) {
bool IngameBlockSelectionScreen::isAllowed( int slot )
{
const int gridCount = minecraft->player->inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE;
if (slot < 0 || slot >= gridCount)
if (slot < 0 || slot >= minecraft->player->inventory->getContainerSize())
return false;
#ifdef DEMO_MODE

View File

@@ -1,5 +1,5 @@
#include "HumanoidModel.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../../util/Mth.h"
#include "../../world/entity/player/Player.h"
#include "../../world/entity/player/Inventory.h"

View File

@@ -1,6 +1,5 @@
#include "LocalPlayer.h"
#include "../Minecraft.h"
#include "../../ErrorCodes.h"
#include <Minecraft.h>
#include "../../world/entity/EntityEvent.h"
#include "../../world/entity/player/Player.h"
#include "../../world/inventory/BaseContainerMenu.h"
@@ -35,7 +34,7 @@
#include <errno.h>
#endif
#ifndef STANDALONE_SERVER
#include "../gui/Screen.h"
#include "../gui/screens/FurnaceScreen.h"
#include "../gui/screens/ChestScreen.h"
@@ -44,13 +43,13 @@
#include "../gui/screens/InBedScreen.h"
#include "../gui/screens/TextEditScreen.h"
#include "../particle/TakeAnimationParticle.h"
#endif
#include "../../network/packet/AnimatePacket.h"
#include "../../world/item/ArmorItem.h"
#include "../../network/packet/PlayerArmorEquipmentPacket.h"
#include <MinecraftClient.h>
namespace {
#ifndef STANDALONE_SERVER
static bool isBase64(unsigned char c) {
return (std::isalnum(c) || (c == '+') || (c == '/'));
@@ -233,7 +232,7 @@ static bool fileExists(const std::string& path) {
#endif
}
#ifndef STANDALONE_SERVER
static void* fetchSkinForPlayer(void* param) {
LocalPlayer* player = (LocalPlayer*)param;
@@ -345,33 +344,21 @@ static bool isJumpable(int tileId) {
} // anonymous namespace
LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, const std::string& username, int dimension, bool isCreative)
: Player(level, isCreative),
minecraft(minecraft),
input(NULL),
sentInventoryItemId(-1),
sentInventoryItemData(-1),
autoJumpEnabled(true),
armorTypeHash(0),
sprinting(false),
sprintDoubleTapTimer(0),
prevForwardHeld(false)
{
LocalPlayer::LocalPlayer(MinecraftClient& minecraft, Level* level, const std::string& username, int dimension, bool isCreative)
: Player(level, isCreative), minecraft(minecraft) {
this->dimension = dimension;
_init();
#ifndef STANDALONE_SERVER
if (minecraft->options.getStringValue(OPTIONS_USERNAME).size() != 0) {
if (minecraft.options().getStringValue(OPTIONS_USERNAME).size() != 0) {
textureName = "mob/char.png";
this->name = minecraft->options.getStringValue(OPTIONS_USERNAME);
this->name = minecraft.options().getStringValue(OPTIONS_USERNAME);
printf("test \n");
// 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);
}
#endif
}
LocalPlayer::~LocalPlayer() {
@@ -381,8 +368,8 @@ LocalPlayer::~LocalPlayer() {
/*private*/
void LocalPlayer::calculateFlight(float xa, float ya, float za) {
float flySpeed = minecraft->options.getProgressValue(OPTIONS_FLY_SPEED);
float sensivity = minecraft->options.getProgressValue(OPTIONS_SENSITIVITY);
float flySpeed = minecraft.options().getProgressValue(OPTIONS_FLY_SPEED);
float sensivity = minecraft.options().getProgressValue(OPTIONS_SENSITIVITY);
xa = xa * flySpeed;
ya = 0;
@@ -434,12 +421,12 @@ void LocalPlayer::tick() {
stopUsingItem();
}
}
if (minecraft->isOnline())
if (minecraft.isOnline())
{
if (std::abs(x - sentX) > .1f || std::abs(y - sentY) > .01f || std::abs(z - sentZ) > .1f || std::abs(sentRotX - xRot) > 1 || std::abs(sentRotY - yRot) > 1)
{
MovePlayerPacket packet(entityId, x, y - heightOffset, z, xRot, yRot);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
sentX = x;
sentY = y;
sentZ = z;
@@ -457,7 +444,7 @@ void LocalPlayer::tick() {
sentInventoryItemId = newItemId;
sentInventoryItemData = newItemData;
PlayerEquipmentPacket packet(entityId, newItemId, newItemData);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
}
/*
@@ -472,15 +459,14 @@ void LocalPlayer::tick() {
*/
updateArmorTypeHash();
#ifndef STANDALONE_SERVER
if (!minecraft->screen && containerMenu) {
if (!minecraft.getScreen() && containerMenu) {
static bool hasPostedError = false;
if (!hasPostedError) {
minecraft->gui.postError( ErrorCodes::ContainerRefStillExistsAfterDestruction );
// @todo
// minecraft.gui().postError( ErrorCodes::ContainerRefStillExistsAfterDestruction );
hasPostedError = true;
}
}
#endif
//LOGI("biome: %s\n", level->getBiomeSource()->getBiome((int)x >> 4, (int)z >> 4)->name.c_str());
}
@@ -491,15 +477,14 @@ void LocalPlayer::aiStep() {
descendTriggerTime--;
bool wasJumping = input->jumping;
#ifndef STANDALONE_SERVER
bool screenCovering = minecraft->screen && !minecraft->screen->passEvents;
bool screenCovering = minecraft.getScreen() && !minecraft.getScreen()->passEvents;
if (!screenCovering)
input->tick(this);
// Sprint: detect W double-tap
{
bool forwardHeld = (input->ya > 0);
if (forwardHeld && !prevForwardHeld && minecraft->options.getBooleanValue(OPTIONS_ALLOW_SPRINT)) {
if (forwardHeld && !prevForwardHeld && minecraft.options().getBooleanValue(OPTIONS_ALLOW_SPRINT)) {
// leading edge of W press
if (sprintDoubleTapTimer > 0)
sprinting = true;
@@ -518,7 +503,7 @@ void LocalPlayer::aiStep() {
if (input->sneaking) {
if (ySlideOffset < 0.2f) ySlideOffset = 0.2f;
}
#endif
if (abilities.mayfly) {
// Check for flight toggle
if (!wasJumping && input->jumping) {
@@ -559,16 +544,16 @@ void LocalPlayer::aiStep() {
void LocalPlayer::closeContainer() {
if (level->isClientSide) {
ContainerClosePacket packet(containerMenu->containerId);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
super::closeContainer();
minecraft->setScreen(NULL);
minecraft.setScreen(NULL);
}
//@Override
void LocalPlayer::move(float xa, float ya, float za) {
//@note: why is this == minecraft->player needed?
if (this == minecraft->player && minecraft->options.getBooleanValue(OPTIONS_IS_FLYING)) {
//@note: why is this == minecraft.player needed?
if (this == minecraft.getPlayer() && minecraft.options().getBooleanValue(OPTIONS_IS_FLYING)) {
noPhysics = true;
float tmp = walkDist; // update
calculateFlight((float) xa, (float) ya, (float) za);
@@ -588,7 +573,7 @@ void LocalPlayer::move(float xa, float ya, float za) {
float newX = x, newZ = z;
if (autoJumpTime <= 0 && minecraft->options.getBooleanValue(OPTIONS_AUTOJUMP))
if (autoJumpTime <= 0 && minecraft.options().getBooleanValue(OPTIONS_AUTOJUMP))
{
// auto-jump when crossing the middle of a tile, and the tile in the front is blocked
bool jump = false;
@@ -617,12 +602,9 @@ void LocalPlayer::updateAi() {
this->jumping = input->jumping || autoJumpTime > 0;
}
void LocalPlayer::take( Entity* e, int orgCount )
{
#ifndef STANDALONE_SERVER
void LocalPlayer::take( Entity* e, int orgCount ) {
if (e->isItemEntity())
minecraft->particleEngine->add(new TakeAnimationParticle(minecraft->level, (ItemEntity*)e, this, -0.5f));
#endif
minecraft.getParticleEngine()->add(new TakeAnimationParticle(minecraft.level, (ItemEntity*)e, this, -0.5f));
}
void LocalPlayer::setKey( int eventKey, bool eventKeyState )
@@ -684,28 +666,25 @@ void LocalPlayer::hurtTo( int newHealth )
lastHealth = health;
invulnerableTime = invulnerableDuration;
minecraft->player->bypassArmor = true;
minecraft.getPlayer()->bypassArmor = true;
actuallyHurt(dmg);
minecraft->player->bypassArmor = false;
minecraft.getPlayer()->bypassArmor = false;
hurtTime = hurtDuration = 10;
}
}
void LocalPlayer::actuallyHurt( int dmg )
{
#ifndef STANDALONE_SERVER
if (minecraft->screen && minecraft->screen->closeOnPlayerHurt()) {
void LocalPlayer::actuallyHurt( int dmg ) {
if (minecraft.getScreen() && minecraft.getScreen()->closeOnPlayerHurt()) {
if (containerMenu) closeContainer();
else minecraft->setScreen(NULL);
else minecraft.setScreen(NULL);
}
#endif
super::actuallyHurt(dmg);
}
void LocalPlayer::respawn()
{
minecraft->respawnPlayer();
void LocalPlayer::respawn() {
minecraft.respawnPlayer();
}
void LocalPlayer::die(Entity* source)
@@ -714,7 +693,7 @@ void LocalPlayer::die(Entity* source)
// If we're the server, drop the inventory immediately
if (level->isClientSide) {
SendInventoryPacket packet(this, true);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
inventory->dropAll(level->isClientSide);
for (int i = 0; i < NUM_ARMOR; ++i) {
@@ -735,7 +714,7 @@ void LocalPlayer::swing() {
AnimatePacket packet(AnimatePacket::Swing, this);
packet.reliability = UNRELIABLE;
packet.priority = MEDIUM_PRIORITY;
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
}
@@ -758,31 +737,23 @@ void LocalPlayer::_init() {
}
void LocalPlayer::startCrafting(int x, int y, int z, int tableSize) {
#ifndef STANDALONE_SERVER
if (!minecraft->isCreativeMode())
minecraft->setScreen( new WorkbenchScreen(tableSize) );
#endif
if (!minecraft.isCreativeMode())
minecraft.setScreen( new WorkbenchScreen(tableSize) );
}
void LocalPlayer::startStonecutting(int x, int y, int z) {
#ifndef STANDALONE_SERVER
if (!minecraft->isCreativeMode())
minecraft->setScreen( new StonecutterScreen() );
#endif
if (!minecraft.isCreativeMode())
minecraft.setScreen( new StonecutterScreen() );
}
void LocalPlayer::openFurnace( FurnaceTileEntity* e ) {
#ifndef STANDALONE_SERVER
if (!minecraft->isCreativeMode())
minecraft->setScreen( new FurnaceScreen(this, e) );
#endif
if (!minecraft.isCreativeMode())
minecraft.setScreen( new FurnaceScreen(this, e) );
}
void LocalPlayer::openContainer( ChestTileEntity* container ) {
#ifndef STANDALONE_SERVER
if (!minecraft->isCreativeMode())
minecraft->setScreen( new ChestScreen(this, container) );
#endif
if (!minecraft.isCreativeMode())
minecraft.setScreen( new ChestScreen(this, container) );
}
void LocalPlayer::drop( ItemInstance* item, bool randomly )
@@ -792,7 +763,7 @@ void LocalPlayer::drop( ItemInstance* item, bool randomly )
if (level->isClientSide) {
DropItemPacket packet(entityId, *item);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
// delete the ItemEntity here, since we don't add it to level
delete item;
} else {
@@ -806,7 +777,7 @@ void LocalPlayer::causeFallDamage( float distance )
if (dmg > 0) {
if (level->isClientSide) {
SetHealthPacket packet(SetHealthPacket::HEALTH_MODIFY_OFFSET + dmg);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
}
super::causeFallDamage(distance);
@@ -814,35 +785,33 @@ void LocalPlayer::causeFallDamage( float distance )
}
void LocalPlayer::displayClientMessage( const std::string& messageId ) {
#ifndef STANDALONE_SERVER
minecraft->gui.displayClientMessage(messageId);
#endif
minecraft.gui().displayClientMessage(messageId);
}
int LocalPlayer::startSleepInBed( int x, int y, int z ) {
int startSleepInBedReturnValue = super::startSleepInBed(x, y, z);
#ifndef STANDALONE_SERVER
if(startSleepInBedReturnValue == BedSleepingResult::OK)
minecraft->setScreen(new InBedScreen());
#endif
minecraft.setScreen(new InBedScreen());
return startSleepInBedReturnValue;
}
void LocalPlayer::stopSleepInBed( bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint ) {
if(level->isClientSide) {
PlayerActionPacket packet(PlayerActionPacket::STOP_SLEEPING, 0, 0, 0, 0, entityId);
minecraft->raknetInstance->send(packet);
minecraft.raknetInstance->send(packet);
}
#ifndef STANDALONE_SERVER
minecraft->setScreen(NULL);
#endif
minecraft.setScreen(NULL);
super::stopSleepInBed(forcefulWakeUp, updateLevelList, saveRespawnPoint);
}
void LocalPlayer::openTextEdit( TileEntity* tileEntity ) {
#if !defined(STANDALONE_SERVER) && !defined(RPI)
#if !defined(RPI)
if(tileEntity->type == TileEntityType::Sign)
minecraft->setScreen(new TextEditScreen((SignTileEntity*) tileEntity));
minecraft.setScreen(new TextEditScreen((SignTileEntity*) tileEntity));
#endif
}
@@ -850,7 +819,7 @@ void LocalPlayer::updateArmorTypeHash() {
int hash = getArmorTypeHash();
if (hash != armorTypeHash) {
PlayerArmorEquipmentPacket p(this);
minecraft->raknetInstance->send(p);
minecraft.raknetInstance->send(p);
armorTypeHash = hash;
}
}

View File

@@ -7,7 +7,7 @@
#include "../../util/SmoothFloat.h"
#include "../../world/entity/player/Player.h"
class Minecraft;
class MinecraftClient;
class Stat;
class CompoundTag;
@@ -15,7 +15,7 @@ class LocalPlayer: public Player
{
typedef Player super;
public:
LocalPlayer(Minecraft* minecraft, Level* level, const std::string& username, int dimension, bool isCreative);
LocalPlayer(MinecraftClient& minecraft, Level* level, const std::string& username, int dimension, bool isCreative);
~LocalPlayer();
void _init();
@@ -74,10 +74,10 @@ private:
bool isSolidTile(int x, int y, int z);
void updateArmorTypeHash();
public:
IMoveInput* input;
bool autoJumpEnabled;
IMoveInput* input = nullptr;
bool autoJumpEnabled = true;
protected:
Minecraft* minecraft;
MinecraftClient& minecraft;
int jumpTriggerTime;
int ascendTriggerTime;
int descendTriggerTime;
@@ -94,15 +94,15 @@ private:
int autoJumpTime;
int sentInventoryItemId;
int sentInventoryItemData;
int sentInventoryItemId = -1;
int sentInventoryItemData = -1;
int armorTypeHash;
int armorTypeHash = 0;
// sprinting
bool sprinting;
int sprintDoubleTapTimer;
bool prevForwardHeld;
bool sprinting = false;
int sprintDoubleTapTimer = 0;
bool prevForwardHeld = false;
public:
void setSprinting(bool sprint) { sprinting = sprint; }
};

View File

@@ -44,7 +44,7 @@ private:
range(b);
range(a);
}
__inline void range(GLfloat& v) {
inline void range(GLfloat& v) {
if (v < 0) v = 0;
if (v > 1) v = 1;
}

View File

@@ -9,7 +9,7 @@
#include "culling/AllowAllCuller.h"
#include "culling/FrustumCuller.h"
#include "entity/EntityRenderDispatcher.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../gamemode/GameMode.h"
#include "../particle/ParticleEngine.h"
#include "../player/LocalPlayer.h"

View File

@@ -5,7 +5,7 @@
#include "entity/EntityRenderDispatcher.h"
#include "entity/EntityRenderer.h"
#include "entity/MobRenderer.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../player/LocalPlayer.h"
#include "../../world/entity/player/Player.h"
#include "../../world/item/Item.h"

View File

@@ -4,7 +4,7 @@
#include "DistanceChunkSorter.h"
#include "Chunk.h"
#include "TileRenderer.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../../util/Mth.h"
#include "../../world/entity/player/Player.h"
#include "../../world/level/tile/LevelEvent.h"

View File

@@ -9,7 +9,7 @@
#include "gles.h"
#include <vector>
class Minecraft;
class MinecraftClient;
class Textures;
class Culler;
class Chunk;
@@ -33,7 +33,7 @@ public:
float zOld;
float destroyProgress;
LevelRenderer(Minecraft* mc);
LevelRenderer(MinecraftClient& mc);
~LevelRenderer();
void setLevel(Level* level);
@@ -77,7 +77,7 @@ private:
void resortChunks(int xc, int yc, int zc);
void deleteChunks();
//void checkQueryResults(int from, int to);
__inline int getLinearCoord(int x, int y, int z) {
inline int getLinearCoord(int x, int y, int z) {
return (z * yChunks + y) * xChunks + x;
}
int noEntityRenderFrames;

View File

@@ -18,7 +18,7 @@ public:
void add(int list);
void addR(const RenderChunk& chunk);
__inline void next() { ++listIndex; }
inline void next() { ++listIndex; }
void render();
void renderChunks();

View File

@@ -72,18 +72,18 @@ public:
int getColor();
__inline void beginOverride() {
inline void beginOverride() {
begin();
voidBeginAndEndCalls(true);
}
__inline void endOverrideAndDraw() {
inline void endOverrideAndDraw() {
voidBeginAndEndCalls(false);
draw();
}
__inline bool isOverridden() {
inline bool isOverridden() {
return _voidBeginEnd;
}
__inline RenderChunk endOverride(int bufferId) {
inline RenderChunk endOverride(int bufferId) {
voidBeginAndEndCalls(false);
return end(true, bufferId);
}

View File

@@ -4,34 +4,20 @@
#include "ptexture/DynamicTexture.h"
#include "../Options.h"
#include "../../platform/time.h"
#include "../../AppPlatform.h"
#include "../../util/StringUtils.h"
/*static*/ int Textures::textureChanges = 0;
/*static*/ bool Textures::MIPMAP = false;
/*static*/ const TextureId Textures::InvalidId = -1;
Textures::Textures( Options* options_, AppPlatform* platform_ )
: clamp(false),
blur(false),
options(options_),
platform(platform_),
lastBoundTexture(Textures::InvalidId)
{
}
Textures::~Textures()
{
Textures::~Textures() {
clear();
for (unsigned int i = 0; i < dynamicTextures.size(); ++i)
delete dynamicTextures[i];
}
void Textures::clear()
{
void Textures::clear() {
for (TextureMap::iterator it = idMap.begin(); it != idMap.end(); ++it) {
if (it->second != Textures::InvalidId)
if (it->second != TEXTURES_INVALID_ID)
glDeleteTextures(1, &it->second);
}
for (TextureImageMap::iterator it = loadedImages.begin(); it != loadedImages.end(); ++it) {
@@ -41,7 +27,7 @@ void Textures::clear()
idMap.clear();
loadedImages.clear();
lastBoundTexture = Textures::InvalidId;
lastBoundTexture = TEXTURES_INVALID_ID;
}
TextureId Textures::loadAndBindTexture( const std::string& resourceName )
@@ -51,7 +37,7 @@ TextureId Textures::loadAndBindTexture( const std::string& resourceName )
//t.start();
TextureId id = loadTexture(resourceName);
//t.stop();
if (id != Textures::InvalidId)
if (id != TEXTURES_INVALID_ID)
bind(id);
//t.printEvery(1000);
@@ -59,25 +45,24 @@ TextureId Textures::loadAndBindTexture( const std::string& resourceName )
return id;
}
TextureId Textures::loadTexture( const std::string& resourceName, bool inTextureFolder /* = true */ )
{
TextureId Textures::loadTexture(const std::string& resourceName, bool inTextureFolder) {
TextureMap::iterator it = idMap.find(resourceName);
if (it != idMap.end())
return it->second;
bool isUrl = Util::startsWith(resourceName, "http://") || Util::startsWith(resourceName, "https://");
TextureData texdata = platform->loadTexture(resourceName, isUrl ? false : inTextureFolder);
TextureData texdata = m_platform.loadTexture(resourceName, isUrl ? false : inTextureFolder);
if (texdata.data)
return assignTexture(resourceName, texdata);
else if (texdata.identifier != InvalidId) {
else if (texdata.identifier != TEXTURES_INVALID_ID) {
//LOGI("Adding id: %d for %s\n", texdata.identifier, resourceName.c_str());
idMap.insert(std::make_pair(resourceName, texdata.identifier));
}
else {
idMap.insert(std::make_pair(resourceName, Textures::InvalidId));
idMap.insert(std::make_pair(resourceName, TEXTURES_INVALID_ID));
//loadedImages.insert(std::make_pair(InvalidId, texdata));
}
return Textures::InvalidId;
return TEXTURES_INVALID_ID;
}
TextureId Textures::assignTexture( const std::string& resourceName, const TextureData& img )
@@ -87,13 +72,14 @@ TextureId Textures::assignTexture( const std::string& resourceName, const Textur
bind(id);
if (MIPMAP) {
#ifdef TEXTURES_MIPMAP
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
#else
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
#endif
if (blur) {
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

View File

@@ -6,9 +6,13 @@
#include <string>
#include <map>
#include <utility>
#include <IPlatform.h>
#include "gles.h"
#include "TextureData.h"
#define TEXTURES_INVALID_ID -1
#define TEXTURES_MIPMAP 0
class DynamicTexture;
class Options;
class AppPlatform;
@@ -24,20 +28,21 @@ typedef std::map<TextureId, TextureData> TextureImageMap;
class Textures
{
public:
Textures(Options* options_, AppPlatform* platform_);
Textures(Options& options, IPlatform& platform) : m_options(options), m_platform(platform) {}
~Textures();
void addDynamicTexture(DynamicTexture* dynamicTexture);
__inline void bind(TextureId id) {
if (id != Textures::InvalidId && lastBoundTexture != id) {
inline void bind(TextureId id) {
if (id != TEXTURES_INVALID_ID && lastBoundTexture != id) {
glBindTexture2(GL_TEXTURE_2D, id);
lastBoundTexture = id;
++textureChanges;
} else if (id == Textures::InvalidId){
} else if (id == TEXTURES_INVALID_ID){
LOGI("invalidId!\n");
}
}
TextureId loadTexture(const std::string& resourceName, bool inTextureFolder = true);
TextureId loadAndBindTexture(const std::string& resourceName);
@@ -49,28 +54,26 @@ public:
void clear();
void reloadAll();
__inline static bool isTextureIdValid(TextureId t) { return t != Textures::InvalidId; }
inline static bool isTextureIdValid(TextureId t) { return t != TEXTURES_INVALID_ID; }
private:
int smoothBlend(int c0, int c1);
int crispBlend(int c0, int c1);
public:
static bool MIPMAP;
static int textureChanges;
static const TextureId InvalidId;
private:
TextureMap idMap;
TextureImageMap loadedImages;
Options* options;
AppPlatform* platform;
Options& m_options;
IPlatform& m_platform;
bool clamp;
bool blur;
bool clamp = false;
bool blur = false;
int lastBoundTexture;
int lastBoundTexture = TEXTURES_INVALID_ID;
std::vector<DynamicTexture*> dynamicTextures;
};

View File

@@ -1,6 +1,6 @@
#include "TileRenderer.h"
#include "Chunk.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "Tesselator.h"
#include "../../world/level/LevelSource.h"

View File

@@ -1,6 +1,6 @@
#include "SoundEngine.h"
#include "../Options.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../../world/entity/Mob.h"

View File

@@ -1,6 +1,6 @@
#include "SoundEngine.h"
#include "../Options.h"
#include "../Minecraft.h"
#include <Minecraft.h>
#include "../../world/entity/Mob.h"
/*