forked from Kolyah35/minecraft-pe-0.6.1
Whool Fix part 1
This commit is contained in:
@@ -1,69 +1,56 @@
|
|||||||
#include "CreativeMode.h"
|
#include "CreativeMode.h"
|
||||||
#include "../Minecraft.h"
|
#include "../Minecraft.h"
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "../particle/ParticleEngine.h"
|
#include "../particle/ParticleEngine.h"
|
||||||
#endif
|
#endif
|
||||||
#include "../player/LocalPlayer.h"
|
#include "../player/LocalPlayer.h"
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "../renderer/LevelRenderer.h"
|
#include "../renderer/LevelRenderer.h"
|
||||||
#include "../sound/SoundEngine.h"
|
#include "../sound/SoundEngine.h"
|
||||||
#endif
|
#endif
|
||||||
#include "../../world/level/Level.h"
|
#include "../../world/level/Level.h"
|
||||||
//#include "../../network/Packet.h"
|
//#include "../../network/Packet.h"
|
||||||
#include "../../network/packet/RemoveBlockPacket.h"
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
#include "../../world/entity/player/Abilities.h"
|
#include "../../world/entity/player/Abilities.h"
|
||||||
|
|
||||||
static const int DestructionTickDelay = 5;
|
static const int DestructionTickDelay = 5;
|
||||||
|
|
||||||
CreativeMode::CreativeMode(Minecraft* minecraft)
|
CreativeMode::CreativeMode(Minecraft* minecraft)
|
||||||
: super(minecraft)
|
: super(minecraft)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreativeMode::startDestroyBlock(int x, int y, int z, int face) {
|
void CreativeMode::startDestroyBlock(int x, int y, int z, int face) {
|
||||||
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
creativeDestroyBlock(x, y, z, face);
|
creativeDestroyBlock(x, y, z, face);
|
||||||
destroyDelay = DestructionTickDelay;
|
destroyDelay = DestructionTickDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreativeMode::creativeDestroyBlock(int x, int y, int z, int face) {
|
void CreativeMode::creativeDestroyBlock(int x, int y, int z, int face) {
|
||||||
minecraft->level->extinguishFire(x, y, z, face);
|
minecraft->level->extinguishFire(x, y, z, face);
|
||||||
destroyBlock(x, y, z, face);
|
destroyBlock(x, y, z, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) {
|
void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) {
|
||||||
destroyDelay--;
|
destroyDelay--;
|
||||||
if (destroyDelay <= 0) {
|
if (destroyDelay <= 0) {
|
||||||
destroyDelay = DestructionTickDelay;
|
destroyDelay = DestructionTickDelay;
|
||||||
creativeDestroyBlock(x, y, z, face);
|
creativeDestroyBlock(x, y, z, face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreativeMode::stopDestroyBlock() {
|
void CreativeMode::stopDestroyBlock() {
|
||||||
destroyDelay = 0;
|
destroyDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreativeMode::initAbilities( Abilities& abilities ) {
|
void CreativeMode::initAbilities( Abilities& abilities ) {
|
||||||
abilities.mayfly = true;
|
abilities.mayfly = true;
|
||||||
abilities.instabuild = true;
|
abilities.instabuild = true;
|
||||||
abilities.invulnerable = true;
|
abilities.invulnerable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreativeMode::isCreativeType() {
|
bool CreativeMode::isCreativeType() {
|
||||||
return true;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
||||||
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gamemode;
|
//package net.minecraft.client.gamemode;
|
||||||
|
|
||||||
#include "GameMode.h"
|
#include "GameMode.h"
|
||||||
|
|
||||||
class CreativeMode: public GameMode
|
class CreativeMode: public GameMode
|
||||||
{
|
{
|
||||||
typedef GameMode super;
|
typedef GameMode super;
|
||||||
public:
|
public:
|
||||||
CreativeMode(Minecraft* minecraft);
|
CreativeMode(Minecraft* minecraft);
|
||||||
|
|
||||||
void startDestroyBlock(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 continueDestroyBlock(int x, int y, int z, int face);
|
||||||
void stopDestroyBlock();
|
void stopDestroyBlock();
|
||||||
|
|
||||||
bool isCreativeType();
|
bool isCreativeType();
|
||||||
|
|
||||||
void initAbilities(Abilities& abilities);
|
void initAbilities(Abilities& abilities);
|
||||||
|
|
||||||
void releaseUsingItem(Player* player);
|
private:
|
||||||
private:
|
void creativeDestroyBlock(int x, int y, int z, int face);
|
||||||
void creativeDestroyBlock(int x, int y, int z, int face);
|
};
|
||||||
};
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/
|
||||||
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/
|
|
||||||
|
|||||||
@@ -1,115 +1,102 @@
|
|||||||
#include "CreatorMode.h"
|
#include "CreatorMode.h"
|
||||||
#include "../Minecraft.h"
|
#include "../Minecraft.h"
|
||||||
#include "../particle/ParticleEngine.h"
|
#include "../particle/ParticleEngine.h"
|
||||||
#include "../player/LocalPlayer.h"
|
#include "../player/LocalPlayer.h"
|
||||||
#include "../renderer/LevelRenderer.h"
|
#include "../renderer/LevelRenderer.h"
|
||||||
#include "../sound/SoundEngine.h"
|
#include "../sound/SoundEngine.h"
|
||||||
#include "../../world/level/Level.h"
|
#include "../../world/level/Level.h"
|
||||||
//#include "../../network/Packet.h"
|
//#include "../../network/Packet.h"
|
||||||
#include "../../network/packet/RemoveBlockPacket.h"
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
#include "../../world/entity/player/Abilities.h"
|
#include "../../world/entity/player/Abilities.h"
|
||||||
|
|
||||||
static const int DestructionTickDelay = 5;
|
static const int DestructionTickDelay = 5;
|
||||||
|
|
||||||
class Creator: public ICreator {
|
class Creator: public ICreator {
|
||||||
//virtual void getEvents();
|
//virtual void getEvents();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Creator(/*int eventLifeTime*/)
|
Creator(/*int eventLifeTime*/)
|
||||||
: _tileEvents(32),
|
: _tileEvents(32),
|
||||||
_tickId(0)
|
_tickId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTick(int tick) {
|
void setTick(int tick) {
|
||||||
_tickId = tick;
|
_tickId = tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventList<TileEvent>& getTileEvents() { return _tileEvents; }
|
EventList<TileEvent>& getTileEvents() { return _tileEvents; }
|
||||||
|
|
||||||
void addevent_blockUse(int entityId, int x, int y, int z, int face) {
|
void addevent_blockUse(int entityId, int x, int y, int z, int face) {
|
||||||
TileEvent t = {
|
TileEvent t = {
|
||||||
entityId,
|
entityId,
|
||||||
x,y,z,
|
x,y,z,
|
||||||
face
|
face
|
||||||
};
|
};
|
||||||
_tileEvents.add(t, _tickId);
|
_tileEvents.add(t, _tickId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventList<TileEvent> _tileEvents;
|
EventList<TileEvent> _tileEvents;
|
||||||
int _tickId;
|
int _tickId;
|
||||||
};
|
};
|
||||||
|
|
||||||
CreatorMode::CreatorMode(Minecraft* minecraft)
|
CreatorMode::CreatorMode(Minecraft* minecraft)
|
||||||
: super(minecraft)
|
: super(minecraft)
|
||||||
{
|
{
|
||||||
_creator = new Creator();
|
_creator = new Creator();
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatorMode::~CreatorMode() {
|
CreatorMode::~CreatorMode() {
|
||||||
delete _creator;
|
delete _creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::startDestroyBlock(int x, int y, int z, int face) {
|
void CreatorMode::startDestroyBlock(int x, int y, int z, int face) {
|
||||||
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CreatorDestroyBlock(x, y, z, face);
|
CreatorDestroyBlock(x, y, z, face);
|
||||||
destroyDelay = DestructionTickDelay;
|
destroyDelay = DestructionTickDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::CreatorDestroyBlock(int x, int y, int z, int face) {
|
void CreatorMode::CreatorDestroyBlock(int x, int y, int z, int face) {
|
||||||
minecraft->level->extinguishFire(x, y, z, face);
|
minecraft->level->extinguishFire(x, y, z, face);
|
||||||
destroyBlock(x, y, z, face);
|
destroyBlock(x, y, z, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::continueDestroyBlock(int x, int y, int z, int face) {
|
void CreatorMode::continueDestroyBlock(int x, int y, int z, int face) {
|
||||||
destroyDelay--;
|
destroyDelay--;
|
||||||
if (destroyDelay <= 0) {
|
if (destroyDelay <= 0) {
|
||||||
destroyDelay = DestructionTickDelay;
|
destroyDelay = DestructionTickDelay;
|
||||||
CreatorDestroyBlock(x, y, z, face);
|
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 ) {
|
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)
|
if (item && item->id == ((Item*)Item::sword_iron)->id)
|
||||||
_creator->addevent_blockUse(player->entityId, x, y, z, face);
|
_creator->addevent_blockUse(player->entityId, x, y, z, face);
|
||||||
return super::useItemOn(player, level, item, x, y, z, face, hit);
|
return super::useItemOn(player, level, item, x, y, z, face, hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::stopDestroyBlock() {
|
void CreatorMode::stopDestroyBlock() {
|
||||||
destroyDelay = 0;
|
destroyDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::initAbilities( Abilities& abilities ) {
|
void CreatorMode::initAbilities( Abilities& abilities ) {
|
||||||
abilities.mayfly = true;
|
abilities.mayfly = true;
|
||||||
abilities.instabuild = true;
|
abilities.instabuild = true;
|
||||||
abilities.invulnerable = true;
|
abilities.invulnerable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreatorMode::isCreativeType() {
|
bool CreatorMode::isCreativeType() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatorMode::releaseUsingItem( Player* player ) {
|
ICreator* CreatorMode::getCreator() {
|
||||||
if(player->getCarriedItem() != NULL) {
|
return _creator;
|
||||||
int oldItemId = player->getCarriedItem()->id;
|
}
|
||||||
int oldAux = player->getAuxData();
|
|
||||||
super::releaseUsingItem(player);
|
void CreatorMode::tick() {
|
||||||
if(player->getCarriedItem() != NULL && player->getCarriedItem()->id == oldItemId) {
|
_creator->setTick(minecraft->level->getTime());
|
||||||
player->getCarriedItem()->setAuxValue(oldAux);
|
super::tick();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
super::releaseUsingItem(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ICreator* CreatorMode::getCreator() {
|
|
||||||
return _creator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreatorMode::tick() {
|
|
||||||
_creator->setTick(minecraft->level->getTime());
|
|
||||||
super::tick();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,61 +1,61 @@
|
|||||||
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
||||||
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gamemode;
|
//package net.minecraft.client.gamemode;
|
||||||
|
|
||||||
#include "GameMode.h"
|
#include "GameMode.h"
|
||||||
#include "../../world/PosTranslator.h"
|
#include "../../world/PosTranslator.h"
|
||||||
|
|
||||||
class ICreator {
|
class ICreator {
|
||||||
public:
|
public:
|
||||||
virtual ~ICreator() {}
|
virtual ~ICreator() {}
|
||||||
|
|
||||||
struct TileEvent {
|
struct TileEvent {
|
||||||
int entityId;
|
int entityId;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
int face;
|
int face;
|
||||||
|
|
||||||
void write(std::stringstream& ss, IPosTranslator& t) const {
|
void write(std::stringstream& ss, IPosTranslator& t) const {
|
||||||
int xx = x, yy = y, zz = z;
|
int xx = x, yy = y, zz = z;
|
||||||
t.to(xx, yy, zz);
|
t.to(xx, yy, zz);
|
||||||
ss << xx << "," << yy << "," << zz << "," << face << "," << entityId;
|
ss << xx << "," << yy << "," << zz << "," << face << "," << entityId;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class EventList {
|
class EventList {
|
||||||
public:
|
public:
|
||||||
EventList(int size) {
|
EventList(int size) {
|
||||||
_events.reserve(size);
|
_events.reserve(size);
|
||||||
_maxSize = (int)size;
|
_maxSize = (int)size;
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
void clear() {
|
void clear() {
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
void add(const T& item, int tick) {
|
void add(const T& item, int tick) {
|
||||||
if (_size < _maxSize) {
|
if (_size < _maxSize) {
|
||||||
_events.push_back(Item());
|
_events.push_back(Item());
|
||||||
++_size;
|
++_size;
|
||||||
}
|
}
|
||||||
Item& e = _events[_nextIndex()];
|
Item& e = _events[_nextIndex()];
|
||||||
e.item = item;
|
e.item = item;
|
||||||
e.timestamp = tick;
|
e.timestamp = tick;
|
||||||
}
|
}
|
||||||
int size() const {
|
int size() const {
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator[](int i) const {
|
const T& operator[](int i) const {
|
||||||
return _events[_getIndex(i)].item;
|
return _events[_getIndex(i)].item;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator[](int i) {
|
T& operator[](int i) {
|
||||||
return _events[_getIndex(i)].item;
|
return _events[_getIndex(i)].item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(std::stringstream& ss, IPosTranslator& t, int minTimetamp) const {
|
void write(std::stringstream& ss, IPosTranslator& t, int minTimetamp) const {
|
||||||
int i = _getFirstNewerIndex(minTimetamp);
|
int i = _getFirstNewerIndex(minTimetamp);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return;
|
return;
|
||||||
@@ -66,63 +66,62 @@ public:
|
|||||||
ss << "|";
|
ss << "|";
|
||||||
if (++i == _size) i = 0;
|
if (++i == _size) i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _getIndex(int i) const { return (1 + _index + i) % _size; }
|
int _getIndex(int i) const { return (1 + _index + i) % _size; }
|
||||||
int _nextIndex() {
|
int _nextIndex() {
|
||||||
if (++_index == _size) _index = 0;
|
if (++_index == _size) _index = 0;
|
||||||
return _index;
|
return _index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getFirstNewerIndex(int timestamp) const {
|
int _getFirstNewerIndex(int timestamp) const {
|
||||||
for (int i = _index + 1, j = 0; j < _size; ++i, ++j) {
|
for (int i = _index + 1, j = 0; j < _size; ++i, ++j) {
|
||||||
if (i == _size) i = 0;
|
if (i == _size) i = 0;
|
||||||
if (_events[i].timestamp >= timestamp) return i;
|
if (_events[i].timestamp >= timestamp) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct Item {
|
struct Item {
|
||||||
int timestamp;
|
int timestamp;
|
||||||
T item;
|
T item;
|
||||||
};
|
};
|
||||||
|
|
||||||
int _index;
|
int _index;
|
||||||
int _size;
|
int _size;
|
||||||
int _maxSize;
|
int _maxSize;
|
||||||
std::vector<Item> _events;
|
std::vector<Item> _events;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual EventList<TileEvent>& getTileEvents() = 0;
|
virtual EventList<TileEvent>& getTileEvents() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Creator;
|
class Creator;
|
||||||
|
|
||||||
class CreatorMode: public GameMode
|
class CreatorMode: public GameMode
|
||||||
{
|
{
|
||||||
typedef GameMode super;
|
typedef GameMode super;
|
||||||
public:
|
public:
|
||||||
CreatorMode(Minecraft* minecraft);
|
CreatorMode(Minecraft* minecraft);
|
||||||
~CreatorMode();
|
~CreatorMode();
|
||||||
|
|
||||||
void startDestroyBlock(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 continueDestroyBlock(int x, int y, int z, int face);
|
||||||
void stopDestroyBlock();
|
void stopDestroyBlock();
|
||||||
|
|
||||||
bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
ICreator* getCreator();
|
ICreator* getCreator();
|
||||||
|
|
||||||
bool isCreativeType();
|
bool isCreativeType();
|
||||||
|
|
||||||
void initAbilities(Abilities& abilities);
|
void initAbilities(Abilities& abilities);
|
||||||
|
|
||||||
void releaseUsingItem(Player* player);
|
private:
|
||||||
private:
|
void CreatorDestroyBlock(int x, int y, int z, int face);
|
||||||
void CreatorDestroyBlock(int x, int y, int z, int face);
|
|
||||||
|
Creator* _creator;
|
||||||
Creator* _creator;
|
};
|
||||||
};
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__*/
|
||||||
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__*/
|
|
||||||
|
|||||||
@@ -1,174 +1,174 @@
|
|||||||
#include "GameMode.h"
|
#include "GameMode.h"
|
||||||
#include "../Minecraft.h"
|
#include "../Minecraft.h"
|
||||||
#include "../../network/packet/UseItemPacket.h"
|
#include "../../network/packet/UseItemPacket.h"
|
||||||
#include "../../network/packet/PlayerActionPacket.h"
|
#include "../../network/packet/PlayerActionPacket.h"
|
||||||
#include "../../world/level/Level.h"
|
#include "../../world/level/Level.h"
|
||||||
#include "../../world/item/ItemInstance.h"
|
#include "../../world/item/ItemInstance.h"
|
||||||
#include "../player/LocalPlayer.h"
|
#include "../player/LocalPlayer.h"
|
||||||
#include "client/Options.h"
|
#include "client/Options.h"
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "../sound/SoundEngine.h"
|
#include "../sound/SoundEngine.h"
|
||||||
#include "../particle/ParticleEngine.h"
|
#include "../particle/ParticleEngine.h"
|
||||||
#endif
|
#endif
|
||||||
#include "../../network/RakNetInstance.h"
|
#include "../../network/RakNetInstance.h"
|
||||||
#include "../../network/packet/RemoveBlockPacket.h"
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "../renderer/LevelRenderer.h"
|
#include "../renderer/LevelRenderer.h"
|
||||||
#endif
|
#endif
|
||||||
#include "../../world/level/material/Material.h"
|
#include "../../world/level/material/Material.h"
|
||||||
|
|
||||||
GameMode::GameMode( Minecraft* minecraft)
|
GameMode::GameMode( Minecraft* minecraft)
|
||||||
: minecraft(minecraft),
|
: minecraft(minecraft),
|
||||||
destroyProgress(0),
|
destroyProgress(0),
|
||||||
oDestroyProgress(0),
|
oDestroyProgress(0),
|
||||||
destroyTicks(0),
|
destroyTicks(0),
|
||||||
destroyDelay(0)
|
destroyDelay(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
Player* GameMode::createPlayer(Level* level) {
|
Player* GameMode::createPlayer(Level* level) {
|
||||||
return new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType());
|
return new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
void GameMode::interact(Player* player, Entity* entity) {
|
void GameMode::interact(Player* player, Entity* entity) {
|
||||||
player->interact(entity);
|
player->interact(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
void GameMode::attack(Player* player, Entity* entity) {
|
void GameMode::attack(Player* player, Entity* entity) {
|
||||||
if (minecraft->level->adventureSettings.noPvP && entity->isPlayer())
|
if (minecraft->level->adventureSettings.noPvP && entity->isPlayer())
|
||||||
return;
|
return;
|
||||||
if (minecraft->level->adventureSettings.noPvM && entity->isMob())
|
if (minecraft->level->adventureSettings.noPvM && entity->isMob())
|
||||||
return;
|
return;
|
||||||
player->attack(entity);
|
player->attack(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
void GameMode::startDestroyBlock( int x, int y, int z, int face ) {
|
void GameMode::startDestroyBlock( int x, int y, int z, int face ) {
|
||||||
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
return;
|
return;
|
||||||
destroyBlock(x, y, z, face);
|
destroyBlock(x, y, z, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
bool GameMode::destroyBlock(int x, int y, int z, int face) {
|
bool GameMode::destroyBlock(int x, int y, int z, int face) {
|
||||||
Level* level = minecraft->level;
|
Level* level = minecraft->level;
|
||||||
Tile* oldTile = Tile::tiles[level->getTile(x, y, z)];
|
Tile* oldTile = Tile::tiles[level->getTile(x, y, z)];
|
||||||
if (!oldTile)
|
if (!oldTile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (level->adventureSettings.immutableWorld) {
|
if (level->adventureSettings.immutableWorld) {
|
||||||
if (oldTile != (Tile*)Tile::leaves
|
if (oldTile != (Tile*)Tile::leaves
|
||||||
&& oldTile->material != Material::plant) {
|
&& oldTile->material != Material::plant) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
minecraft->particleEngine->destroy(x, y, z);
|
minecraft->particleEngine->destroy(x, y, z);
|
||||||
#endif
|
#endif
|
||||||
int data = level->getData(x, y, z);
|
int data = level->getData(x, y, z);
|
||||||
bool changed = level->setTile(x, y, z, 0);
|
bool changed = level->setTile(x, y, z, 0);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
#ifndef STANDALONE_SERVER
|
#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);
|
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
|
#endif
|
||||||
oldTile->destroy(level, x, y, z, data);
|
oldTile->destroy(level, x, y, z, data);
|
||||||
if (minecraft->options.getBooleanValue(OPTIONS_DESTROY_VIBRATION)) minecraft->platform()->vibrate(24);
|
if (minecraft->options.getBooleanValue(OPTIONS_DESTROY_VIBRATION)) minecraft->platform()->vibrate(24);
|
||||||
|
|
||||||
if (minecraft->isOnline()) {
|
if (minecraft->isOnline()) {
|
||||||
RemoveBlockPacket packet(minecraft->player, x, y, z);
|
RemoveBlockPacket packet(minecraft->player, x, y, z);
|
||||||
minecraft->raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
bool GameMode::useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit) {
|
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 clickX = hit.x - x;
|
||||||
float clickY = hit.y - y;
|
float clickY = hit.y - y;
|
||||||
float clickZ = hit.z - z;
|
float clickZ = hit.z - z;
|
||||||
item = player->inventory->getSelected();
|
if (level->isClientSide) {
|
||||||
if(level->isClientSide) {
|
item = player->inventory->getSelected();
|
||||||
UseItemPacket packet(x, y, z, face, item, player->entityId, clickX, clickY, clickZ);
|
UseItemPacket packet(x, y, z, face, item, player->entityId, clickX, clickY, clickZ);
|
||||||
minecraft->raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
int t = level->getTile(x, y, z);
|
int t = level->getTile(x, y, z);
|
||||||
if (t == Tile::invisible_bedrock->id) return false;
|
if (t == Tile::invisible_bedrock->id) return false;
|
||||||
if (t > 0 && Tile::tiles[t]->use(level, x, y, z, player))
|
if (t > 0 && Tile::tiles[t]->use(level, x, y, z, player))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (item == NULL) return false;
|
if (item == NULL) return false;
|
||||||
if(isCreativeType()) {
|
if(isCreativeType()) {
|
||||||
int aux = item->getAuxValue();
|
int aux = item->getAuxValue();
|
||||||
int count = item->count;
|
int count = item->count;
|
||||||
bool success = item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
|
bool success = item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
|
||||||
item->setAuxValue(aux);
|
item->setAuxValue(aux);
|
||||||
item->count = count;
|
item->count = count;
|
||||||
return success;
|
return success;
|
||||||
} else {
|
} else {
|
||||||
return item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
|
return item->useOn(player, level, x, y, z, face, clickX, clickY, clickZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameMode::useItem( Player* player, Level* level, ItemInstance* item ) {
|
bool GameMode::useItem( Player* player, Level* level, ItemInstance* item ) {
|
||||||
int oldCount = item->count;
|
int oldCount = item->count;
|
||||||
|
|
||||||
ItemInstance* itemInstance = item->use(level, player);
|
ItemInstance* itemInstance = item->use(level, player);
|
||||||
if(level->isClientSide) {
|
if(level->isClientSide) {
|
||||||
UseItemPacket packet(item, player->entityId, player->aimDirection);
|
UseItemPacket packet(item, player->entityId, player->aimDirection);
|
||||||
minecraft->raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
if (itemInstance != item || (itemInstance != NULL && itemInstance->count != oldCount)) {
|
if (itemInstance != item || (itemInstance != NULL && itemInstance->count != oldCount)) {
|
||||||
//player.inventory.items[player.inventory.selected] = itemInstance;
|
//player.inventory.items[player.inventory.selected] = itemInstance;
|
||||||
//if (itemInstance.count == 0) {
|
//if (itemInstance.count == 0) {
|
||||||
// player.inventory.items[player.inventory.selected] = NULL;
|
// player.inventory.items[player.inventory.selected] = NULL;
|
||||||
//}
|
//}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemInstance* GameMode::handleInventoryMouseClick( int containerId, int slotNum, int buttonNum, Player* player ) {
|
ItemInstance* GameMode::handleInventoryMouseClick( int containerId, int slotNum, int buttonNum, Player* player ) {
|
||||||
//return player.containerMenu.clicked(slotNum, buttonNum, player);
|
//return player.containerMenu.clicked(slotNum, buttonNum, player);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::handleCloseInventory( int containerId, Player* player ) {
|
void GameMode::handleCloseInventory( int containerId, Player* player ) {
|
||||||
//player.containerMenu.removed(player);
|
//player.containerMenu.removed(player);
|
||||||
//player.containerMenu = player.inventoryMenu;
|
//player.containerMenu = player.inventoryMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GameMode::getPickRange() {
|
float GameMode::getPickRange() {
|
||||||
return 5.0f;
|
return 5.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::initPlayer( Player* player ) {
|
void GameMode::initPlayer( Player* player ) {
|
||||||
initAbilities(player->abilities);
|
initAbilities(player->abilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::releaseUsingItem(Player* player){
|
void GameMode::releaseUsingItem(Player* player){
|
||||||
if(minecraft->level->isClientSide) {
|
if (minecraft->level->isClientSide && player->isUsingItem()) {
|
||||||
PlayerActionPacket packet(PlayerActionPacket::RELEASE_USE_ITEM, 0, 0, 0, 0, player->entityId);
|
PlayerActionPacket packet(PlayerActionPacket::RELEASE_USE_ITEM, 0, 0, 0, 0, player->entityId);
|
||||||
minecraft->raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
player->releaseUsingItem();
|
player->releaseUsingItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::tick() {
|
void GameMode::tick() {
|
||||||
oDestroyProgress = destroyProgress;
|
oDestroyProgress = destroyProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::render( float a ) {
|
void GameMode::render( float a ) {
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
if (destroyProgress <= 0) {
|
if (destroyProgress <= 0) {
|
||||||
minecraft->gui.progress = 0;
|
minecraft->gui.progress = 0;
|
||||||
minecraft->levelRenderer->destroyProgress = 0;
|
minecraft->levelRenderer->destroyProgress = 0;
|
||||||
} else {
|
} else {
|
||||||
float dp = oDestroyProgress + (destroyProgress - oDestroyProgress) * a;
|
float dp = oDestroyProgress + (destroyProgress - oDestroyProgress) * a;
|
||||||
minecraft->gui.progress = dp;
|
minecraft->gui.progress = dp;
|
||||||
minecraft->levelRenderer->destroyProgress = dp;
|
minecraft->levelRenderer->destroyProgress = dp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user