Functional block breaking!
This commit is contained in:
parent
e7d18f7dff
commit
ddf9a7fa20
|
@ -328,6 +328,19 @@ namespace Feather
|
||||||
template <>
|
template <>
|
||||||
void DedicatedServer::HandlePacket(MinecraftClient& client, const Play::ServerboundPlayerAction& action)
|
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();
|
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)
|
std::unique_ptr<Chunk> World::LoadChunk(ChunkPos pos)
|
||||||
{
|
{
|
||||||
fs::path worldPath = fs::path(m_name);
|
fs::path worldPath = fs::path(m_name);
|
||||||
|
@ -136,4 +150,4 @@ namespace Feather
|
||||||
|
|
||||||
return std::make_unique<Chunk>(pos, std::move(nbt));
|
return std::make_unique<Chunk>(pos, std::move(nbt));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,10 @@ namespace Feather
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
// Min and max build height, inclusive
|
||||||
|
static constexpr int MIN_BUILD_HEIGHT = 0, MAX_BUILD_HEIGHT = 255;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
World(std::string name);
|
World(std::string name);
|
||||||
|
|
||||||
|
@ -29,16 +33,21 @@ namespace Feather
|
||||||
|
|
||||||
Chunk* GetChunk(ChunkPos pos);
|
Chunk* GetChunk(ChunkPos pos);
|
||||||
|
|
||||||
|
bool SetBlock(const BlockPos& pos, const BlockState& state);
|
||||||
|
|
||||||
LevelData GetLevelData() const { return m_levelData; }
|
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:
|
private:
|
||||||
std::unique_ptr<Chunk> LoadChunk(ChunkPos pos);
|
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;
|
LevelData m_levelData;
|
||||||
|
|
||||||
// TODO nuke this shit
|
// TODO nuke this shit
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue