Functional block breaking!
This commit is contained in:
parent
e7d18f7dff
commit
ddf9a7fa20
|
@ -328,6 +328,19 @@ namespace Feather
|
|||
template <>
|
||||
void DedicatedServer::HandlePacket(MinecraftClient& client, const Play::ServerboundPlayerAction& action)
|
||||
{
|
||||
using Action = Play::ServerboundPlayerAction::Action;
|
||||
switch (action.action)
|
||||
{
|
||||
case Action::StartBreakBlock: break;
|
||||
case Action::AbortBreakBlock: break;
|
||||
case Action::FinishedBreakBlock:
|
||||
m_worldManager.GetOverworld()->SetBlock(action.pos, World::GLOBAL_PALETTE.GetDefault());
|
||||
break;
|
||||
case Action::DropItemStack: break;
|
||||
case Action::DropItem: break;
|
||||
case Action::ReleaseUseItem: break;
|
||||
case Action::SwapItemHands: break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,20 @@ namespace Feather
|
|||
return chunks[pos].get();
|
||||
}
|
||||
|
||||
bool World::SetBlock(const BlockPos& pos, const BlockState& state)
|
||||
{
|
||||
if (IsOutsideBuildHeight(pos)) return false;
|
||||
|
||||
Chunk* chunk = GetChunk(ChunkPos(pos));
|
||||
|
||||
Log::Debug("World::SetBlock at BlockPos({}, {}, {}) -> ChunkPos({}, {})",
|
||||
pos.x, pos.y, pos.z,
|
||||
chunk->pos.x, chunk->pos.z
|
||||
);
|
||||
|
||||
return chunk->SetBlock(pos, state);
|
||||
}
|
||||
|
||||
std::unique_ptr<Chunk> World::LoadChunk(ChunkPos pos)
|
||||
{
|
||||
fs::path worldPath = fs::path(m_name);
|
||||
|
@ -136,4 +150,4 @@ namespace Feather
|
|||
|
||||
return std::make_unique<Chunk>(pos, std::move(nbt));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,6 +19,10 @@ namespace Feather
|
|||
|
||||
class World
|
||||
{
|
||||
public:
|
||||
// Min and max build height, inclusive
|
||||
static constexpr int MIN_BUILD_HEIGHT = 0, MAX_BUILD_HEIGHT = 255;
|
||||
|
||||
public:
|
||||
World(std::string name);
|
||||
|
||||
|
@ -29,16 +33,21 @@ namespace Feather
|
|||
|
||||
Chunk* GetChunk(ChunkPos pos);
|
||||
|
||||
bool SetBlock(const BlockPos& pos, const BlockState& state);
|
||||
|
||||
LevelData GetLevelData() const { return m_levelData; }
|
||||
|
||||
inline bool IsOutsideBuildHeight(BlockPos pos) { return IsOutsideBuildHeight(pos.y); }
|
||||
inline bool IsOutsideBuildHeight(int y) { return y < MIN_BUILD_HEIGHT || y > MAX_BUILD_HEIGHT; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Chunk> LoadChunk(ChunkPos pos);
|
||||
|
||||
Lockable<std::map<ChunkPos, std::unique_ptr<Chunk>>> m_chunks;
|
||||
LockableMap<ChunkPos, std::unique_ptr<Chunk>> m_chunks;
|
||||
|
||||
LevelData m_levelData;
|
||||
|
||||
// TODO nuke this shit
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue