refactor: extract method placeBlock and move some code from PlayerController to BlocksController
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
|
||||
#include "../typedefs.hpp"
|
||||
#include "../maths/fastmaths.hpp"
|
||||
#include "../voxels/voxel.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Player;
|
||||
class Block;
|
||||
@@ -10,6 +14,16 @@ class Level;
|
||||
class Chunks;
|
||||
class Lighting;
|
||||
|
||||
enum class BlockInteraction {
|
||||
step,
|
||||
destruction,
|
||||
placing
|
||||
};
|
||||
|
||||
using on_block_interaction = std::function<void(
|
||||
Player*, glm::ivec3, const Block*, BlockInteraction type
|
||||
)>;
|
||||
|
||||
class Clock {
|
||||
int tickRate;
|
||||
int tickParts;
|
||||
@@ -38,6 +52,7 @@ class BlocksController {
|
||||
Clock worldTickClock;
|
||||
uint padding;
|
||||
FastRandom random;
|
||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||
public:
|
||||
BlocksController(Level* level, uint padding);
|
||||
|
||||
@@ -45,6 +60,7 @@ public:
|
||||
void updateBlock(int x, int y, int z);
|
||||
|
||||
void breakBlock(Player* player, const Block* def, int x, int y, int z);
|
||||
void placeBlock(Player* player, const Block* def, blockstate state, int x, int y, int z);
|
||||
|
||||
void update(float delta);
|
||||
void randomTick(int tickid, int parts);
|
||||
@@ -52,6 +68,15 @@ public:
|
||||
int64_t createBlockInventory(int x, int y, int z);
|
||||
void bindInventory(int64_t invid, int x, int y, int z);
|
||||
void unbindInventory(int x, int y, int z);
|
||||
|
||||
void onBlockInteraction(
|
||||
Player* player,
|
||||
glm::ivec3 pos,
|
||||
const Block* def,
|
||||
BlockInteraction type
|
||||
);
|
||||
|
||||
void listenBlockInteraction(const on_block_interaction& callback);
|
||||
};
|
||||
|
||||
#endif // LOGIC_BLOCKS_CONTROLLER_HPP_
|
||||
|
||||
Reference in New Issue
Block a user