mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-20 06:53:30 +00:00
the whole game
This commit is contained in:
72
src/client/gamemode/CreativeMode.cpp
Executable file
72
src/client/gamemode/CreativeMode.cpp
Executable file
@@ -0,0 +1,72 @@
|
||||
#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 = 10;
|
||||
|
||||
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) {
|
||||
//if (!
|
||||
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() {
|
||||
}
|
||||
|
||||
void CreativeMode::initAbilities( Abilities& abilities ) {
|
||||
abilities.mayfly = true;
|
||||
abilities.instabuild = true;
|
||||
abilities.invulnerable = true;
|
||||
}
|
||||
|
||||
bool CreativeMode::isCreativeType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreativeMode::releaseUsingItem( Player* player ) {
|
||||
if(player->getCarriedItem() != NULL) {
|
||||
int oldItemId = player->getCarriedItem()->id;
|
||||
int oldAux = player->getAuxData();
|
||||
super::releaseUsingItem(player);
|
||||
if(player->getCarriedItem() != NULL && player->getCarriedItem()->id == oldItemId) {
|
||||
player->getCarriedItem()->setAuxValue(oldAux);
|
||||
}
|
||||
} else {
|
||||
super::releaseUsingItem(player);
|
||||
}
|
||||
}
|
||||
27
src/client/gamemode/CreativeMode.h
Executable file
27
src/client/gamemode/CreativeMode.h
Executable file
@@ -0,0 +1,27 @@
|
||||
#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);
|
||||
|
||||
void releaseUsingItem(Player* player);
|
||||
private:
|
||||
void creativeDestroyBlock(int x, int y, int z, int face);
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/
|
||||
118
src/client/gamemode/CreatorMode.cpp
Executable file
118
src/client/gamemode/CreatorMode.cpp
Executable file
@@ -0,0 +1,118 @@
|
||||
#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 = 10;
|
||||
|
||||
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) {
|
||||
//if (!
|
||||
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() {
|
||||
}
|
||||
|
||||
void CreatorMode::initAbilities( Abilities& abilities ) {
|
||||
abilities.mayfly = true;
|
||||
abilities.instabuild = true;
|
||||
abilities.invulnerable = true;
|
||||
}
|
||||
|
||||
bool CreatorMode::isCreativeType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreatorMode::releaseUsingItem( Player* player ) {
|
||||
if(player->getCarriedItem() != NULL) {
|
||||
int oldItemId = player->getCarriedItem()->id;
|
||||
int oldAux = player->getAuxData();
|
||||
super::releaseUsingItem(player);
|
||||
if(player->getCarriedItem() != NULL && player->getCarriedItem()->id == oldItemId) {
|
||||
player->getCarriedItem()->setAuxValue(oldAux);
|
||||
}
|
||||
} else {
|
||||
super::releaseUsingItem(player);
|
||||
}
|
||||
}
|
||||
|
||||
ICreator* CreatorMode::getCreator() {
|
||||
return _creator;
|
||||
}
|
||||
|
||||
void CreatorMode::tick() {
|
||||
_creator->setTick(minecraft->level->getTime());
|
||||
super::tick();
|
||||
}
|
||||
128
src/client/gamemode/CreatorMode.h
Executable file
128
src/client/gamemode/CreatorMode.h
Executable file
@@ -0,0 +1,128 @@
|
||||
#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);
|
||||
|
||||
void releaseUsingItem(Player* player);
|
||||
private:
|
||||
void CreatorDestroyBlock(int x, int y, int z, int face);
|
||||
|
||||
Creator* _creator;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__*/
|
||||
173
src/client/gamemode/GameMode.cpp
Executable file
173
src/client/gamemode/GameMode.cpp
Executable file
@@ -0,0 +1,173 @@
|
||||
#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"
|
||||
#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->user, 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.destroyVibration) 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;
|
||||
item = player->inventory->getSelected();
|
||||
if(level->isClientSide) {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
63
src/client/gamemode/GameMode.h
Executable file
63
src/client/gamemode/GameMode.h
Executable file
@@ -0,0 +1,63 @@
|
||||
#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__*/
|
||||
98
src/client/gamemode/SurvivalMode.cpp
Executable file
98
src/client/gamemode/SurvivalMode.cpp
Executable file
@@ -0,0 +1,98 @@
|
||||
#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);
|
||||
}
|
||||
31
src/client/gamemode/SurvivalMode.h
Executable file
31
src/client/gamemode/SurvivalMode.h
Executable file
@@ -0,0 +1,31 @@
|
||||
#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__*/
|
||||
Reference in New Issue
Block a user