Files
mcpe/source/world/gamemode/SurvivalMode.cpp
Brent f12a3c1c61 Visual Studio Project Overhaul + Cleanup (#80)
* Visual Studio Project Overhaul + Cleanup
* SDL2 project for Windows
* Re-added game client icon to SDL2 code
* Renamed "AppPlatform_windows" to "AppPlatform_win32" (this is the name of the Windows API and is not representative of the architecture type)
* Renamed "LoggerWindows" to "LoggerWin32"
* Renamed "SoundSystemWindows to "SoundSystemDS" (DirectSound). This may be used for the 360, so it wouldn't really be Windows-specific then.
* Moved "ClientSideNetworkHandler" from "network" to "client/network". We don't need it being compiled for the server if the client's the only thing that needs it.
* I wonder if this still works on macOS...

* Bugfixes & Fixed for macOS

* Options::savePropertiesToFile Logging Bugfix

* Silence Winsock Deprecation Warnings in RakNet

* VS Project Improvements
- Replaced 50 billion relative paths with $(MC_ROOT)
- Added $(RAKNET_PATH) variable to override RakNet location
- Re-added gitignore for .vcxproj.user files
- Added debugging config to Directory.Builds.props
- Slimmed down project configurations for SDL2

* VS Project Config Bugfixes
- Fixed RakNet header path for additional includes

* RakNet Target for XCode

* XCode Project Config Fixes

* Packet logging

* Network VS Project Filter Fix

* Fix RakNet Packet ID Length
We previously didn't have consistency between old and new C++ regarding PacketType enum length. Now we do. This is required or else it completely breaks networking between the versions.

* Additional RakNet Error Handling

* Disable packet logging

* * Fix CMakeLists.txt

This reflects the relocation of ClientSideNetworkHandler.cpp.

* * Also add renderer/GL/GL.cpp to the CMakeLists.txt

* * Replace libpng with stb_image

* * Fix buggy water behavior.

* * Put the CMakeLists of the SDL project in debug mode

* Visual Studio 2010 Support

* * Change the SdlIoCallbacks from an array to a single member.

This fixes compilation of the sdl2 target on VS.

* * Fix missing _error label.

* Revert "* Fix missing _error label."

This reverts commit 99a057fc84049a16c864bd840fb439a008af5c74.

* Revert "* Replace libpng with stb_image"

* info_updateGame Tiles

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
2023-10-22 10:08:59 +03:00

163 lines
3.6 KiB
C++

/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "SurvivalMode.hpp"
#include "client/app/Minecraft.hpp"
SurvivalMode::SurvivalMode(Minecraft* pMC) : GameMode(pMC),
m_destroyingX(-1), m_destroyingY(-1), m_destroyingZ(-1),
m_destroyProgress(0.0f),
m_lastDestroyProgress(0.0f),
m_destroyTicks(0),
m_destroyCooldown(0)
{
}
void SurvivalMode::initPlayer(Player* p)
{
p->m_yaw = -180.0f;
p->m_pInventory->prepareSurvivalInventory();
}
bool SurvivalMode::canHurtPlayer()
{
return true;
}
void SurvivalMode::startDestroyBlock(int x, int y, int z, int i)
{
TileID tile = m_pMinecraft->m_pLevel->getTile(x, y, z);
if (tile <= 0)
return;
if (m_destroyProgress == 0.0f)
{
Tile::tiles[tile]->attack(m_pMinecraft->m_pLevel, x, y, z, m_pMinecraft->m_pLocalPlayer);
}
if (Tile::tiles[tile]->getDestroyProgress(m_pMinecraft->m_pLocalPlayer) >= 1.0f)
{
destroyBlock(x, y, z, i);
}
return;
}
bool SurvivalMode::destroyBlock(int x, int y, int z, int i)
{
m_pMinecraft->m_pParticleEngine->destroy(x, y, z);
TileID tile = m_pMinecraft->m_pLevel->getTile(x, y, z);
int data = m_pMinecraft->m_pLevel->getData(x, y, z);
if (!GameMode::destroyBlock(x, y, z, i))
return false;
//@HUH: check too late?
bool bCanDestroy = m_pMinecraft->m_pLocalPlayer->canDestroy(Tile::tiles[tile]);
if (bCanDestroy)
{
Tile::tiles[tile]->playerDestroy(m_pMinecraft->m_pLevel, m_pMinecraft->m_pLocalPlayer, x, y, z, data);
if (m_pMinecraft->isOnline())
{
m_pMinecraft->m_pRakNetInstance->send(new RemoveBlockPacket(m_pMinecraft->m_pLocalPlayer->m_EntityID, x, y, z));
}
}
return true;
}
void SurvivalMode::continueDestroyBlock(int x, int y, int z, int i)
{
if (m_destroyCooldown > 0)
{
m_destroyCooldown--;
return;
}
if (m_destroyingX != x || m_destroyingY != y || m_destroyingZ != z)
{
m_destroyProgress = 0.0f;
m_lastDestroyProgress = 0.0f;
m_destroyTicks = 0;
m_destroyingX = x;
m_destroyingY = y;
m_destroyingZ = z;
return;
}
TileID tile = m_pMinecraft->m_pLevel->getTile(m_destroyingX, m_destroyingY, m_destroyingZ);
if (!tile)
return;
Tile* pTile = Tile::tiles[tile];
float destroyProgress = pTile->getDestroyProgress(m_pMinecraft->m_pLocalPlayer);
m_destroyProgress += 16.0f * destroyProgress;
m_destroyTicks++;
if ((m_destroyTicks & 3) == 1)
{
m_pMinecraft->m_pSoundEngine->play("step." + pTile->m_pSound->m_name,
float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f,
0.5f * (1.0f + pTile->m_pSound->field_18), 0.8f * pTile->m_pSound->field_1C);
}
if (m_destroyProgress >= 1.0f)
{
destroyBlock(m_destroyingX, m_destroyingY, m_destroyingZ, i);
m_destroyTicks = 0;
m_destroyCooldown = 5;
m_destroyProgress = 0.0f;
m_lastDestroyProgress = 0.0f;
}
}
void SurvivalMode::stopDestroyBlock()
{
m_destroyProgress = 0.0f;
m_destroyCooldown = 0;
}
void SurvivalMode::tick()
{
m_lastDestroyProgress = m_destroyProgress;
}
void SurvivalMode::render(float f)
{
if (m_destroyProgress <= 0.0f)
{
m_pMinecraft->m_gui.field_8 = 0.0f;
m_pMinecraft->m_pLevelRenderer->field_10 = 0.0f;
}
else
{
float x = m_lastDestroyProgress + (m_destroyProgress - m_lastDestroyProgress) * f;
m_pMinecraft->m_gui.field_8 = x;
m_pMinecraft->m_pLevelRenderer->field_10 = x;
}
}
float SurvivalMode::getPickRange()
{
return 5.0f;
}
bool SurvivalMode::isCreativeType()
{
return false;
}
bool SurvivalMode::isSurvivalType()
{
return true;
}