* Improve survival mode stuff.

This commit is contained in:
iProgramInCpp
2023-08-04 11:18:28 +03:00
parent 1921552b18
commit 1386b3d658
20 changed files with 458 additions and 88 deletions

View File

@@ -16,7 +16,8 @@ CreativeMode::CreativeMode(Minecraft* pMC) : GameMode(pMC)
void CreativeMode::initPlayer(Player* p)
{
p->m_yaw = -180.0;
p->m_yaw = -180.0f;
p->m_pInventory->prepareCreativeInventory();
}
void CreativeMode::startDestroyBlock(int x, int y, int z, int i)
@@ -144,26 +145,3 @@ bool CreativeMode::isSurvivalType()
{
return true;
}
bool GameMode::useItem(Player* player, Level* level, ItemInstance* instance)
{
int oldAmount = instance->m_amount;
if (instance == instance->use(level, player))
return instance->m_amount != oldAmount;
return true;
}
bool GameMode::useItemOn(Player* player, Level* level, ItemInstance* instance, int x, int y, int z, int d)
{
TileID tile = level->getTile(x, y, z);
if (tile > 0 && Tile::tiles[tile]->use(level, x, y, z, player))
return true;
if (instance)
return instance->useOn(player, level, x, y, z, d);
return false;
}

View File

@@ -15,16 +15,16 @@ class CreativeMode : public GameMode
public:
CreativeMode(Minecraft*);
virtual void startDestroyBlock(int x, int y, int z, int i) override;
virtual bool destroyBlock(int x, int y, int z, int i);
virtual void continueDestroyBlock(int x, int y, int z, int i);
virtual void stopDestroyBlock() override;
virtual void tick() override;
virtual void render(float f) override;
virtual float getPickRange() override;
virtual bool isCreativeType() override;
virtual bool isSurvivalType() override;
virtual void initPlayer(Player*) override;
void startDestroyBlock(int x, int y, int z, int i) override;
bool destroyBlock(int x, int y, int z, int i);
void continueDestroyBlock(int x, int y, int z, int i);
void stopDestroyBlock() override;
void tick() override;
void render(float f) override;
float getPickRange() override;
bool isCreativeType() override;
bool isSurvivalType() override;
void initPlayer(Player*) override;
public:
int m_destroyingX = -1;

View File

@@ -116,3 +116,26 @@ bool GameMode::isSurvivalType()
{
return false;
}
bool GameMode::useItem(Player* player, Level* level, ItemInstance* instance)
{
int oldAmount = instance->m_amount;
if (instance == instance->use(level, player))
return instance->m_amount != oldAmount;
return true;
}
bool GameMode::useItemOn(Player* player, Level* level, ItemInstance* instance, int x, int y, int z, int d)
{
TileID tile = level->getTile(x, y, z);
if (tile > 0 && Tile::tiles[tile]->use(level, x, y, z, player))
return true;
if (instance)
return instance->useOn(player, level, x, y, z, d);
return false;
}

View File

@@ -0,0 +1,158 @@
/********************************************************************
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 "Minecraft.hpp"
SurvivalMode::SurvivalMode(Minecraft* pMC) : GameMode(pMC)
{
}
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 (field_18 == 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 (field_24 > 0)
{
field_24--;
return;
}
if (m_destroyingX != x || m_destroyingY != y || m_destroyingZ != z)
{
field_18 = 0.0f;
field_1C = 0.0f;
field_20 = 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);
field_18 += 16.0f * destroyProgress;
field_20++;
if ((field_20 & 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 (field_18 >= 1.0f)
{
destroyBlock(m_destroyingX, m_destroyingY, m_destroyingZ, i);
field_20 = 0;
field_24 = 5;
field_18 = 0.0f;
field_1C = 0.0f;
}
}
void SurvivalMode::stopDestroyBlock()
{
field_18 = 0.0f;
field_24 = 0;
}
void SurvivalMode::tick()
{
field_1C = field_18;
}
void SurvivalMode::render(float f)
{
if (field_18 <= 0.0f)
{
m_pMinecraft->m_gui.field_8 = 0.0f;
m_pMinecraft->m_pLevelRenderer->field_10 = 0.0f;
}
else
{
float x = field_1C + (field_18 - field_1C) * 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;
}

View File

@@ -0,0 +1,39 @@
/********************************************************************
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
********************************************************************/
#pragma once
#include "GameMode.hpp"
class SurvivalMode : public GameMode
{
public:
SurvivalMode(Minecraft*);
void startDestroyBlock(int x, int y, int z, int i) override;
bool destroyBlock(int x, int y, int z, int i);
void continueDestroyBlock(int x, int y, int z, int i);
void stopDestroyBlock() override;
void tick() override;
void render(float f) override;
float getPickRange() override;
bool isCreativeType() override;
bool isSurvivalType() override;
void initPlayer(Player*) override;
bool canHurtPlayer() override;
public:
int m_destroyingX = -1;
int m_destroyingY = -1;
int m_destroyingZ = -1;
float field_18 = 0.0f;
float field_1C = 0.0f;
int field_20 = 0;
int field_24 = 0;
};