2015-02-06 01:44:16 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: Block.hpp
|
|
|
|
*
|
2018-06-05 01:24:54 +02:00
|
|
|
* Description:
|
2015-02-06 01:44:16 +01:00
|
|
|
*
|
|
|
|
* Created: 29/12/2014 04:56:02
|
|
|
|
*
|
2018-06-14 03:19:35 +02:00
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
2015-02-06 01:44:16 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef BLOCK_HPP_
|
|
|
|
#define BLOCK_HPP_
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
2018-06-25 18:12:15 +02:00
|
|
|
#include "BlockType.hpp"
|
2018-07-02 04:30:17 +02:00
|
|
|
#include "Box.hpp"
|
2018-06-25 18:42:50 +02:00
|
|
|
#include "IntTypes.hpp"
|
2018-06-29 21:18:48 +02:00
|
|
|
#include "ItemStack.hpp"
|
2015-02-06 01:44:16 +01:00
|
|
|
|
2018-06-20 04:22:42 +02:00
|
|
|
class Chunk;
|
2018-06-27 05:09:30 +02:00
|
|
|
class Player;
|
2018-06-24 01:09:32 +02:00
|
|
|
class World;
|
2018-06-20 04:22:42 +02:00
|
|
|
|
2015-02-06 01:44:16 +01:00
|
|
|
class Block {
|
|
|
|
public:
|
2018-07-06 15:08:13 +02:00
|
|
|
Block(u32 id, u32 textureID, const std::string &name);
|
2018-06-24 01:09:32 +02:00
|
|
|
virtual ~Block() = default;
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-28 09:58:37 +02:00
|
|
|
virtual void onTick(const glm::ivec3 &, Player &, Chunk &, World &) const {}
|
2018-06-27 05:09:30 +02:00
|
|
|
virtual bool onBlockActivated(const glm::ivec3 &, Player &, World &) const { return false; }
|
2018-06-28 09:58:37 +02:00
|
|
|
virtual void onNeighbourUpdate(const glm::ivec3 &, const glm::ivec3 &, Chunk &) const {}
|
2018-06-24 01:09:32 +02:00
|
|
|
|
2018-06-29 09:48:37 +02:00
|
|
|
virtual glm::vec4 getTexCoords(int face, u16 blockData) const;
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-28 09:22:57 +02:00
|
|
|
u16 id() const { return m_id & 0xffff; }
|
|
|
|
u16 data() const { return (m_id >> 16) & 0xffff; }
|
2018-06-25 18:12:15 +02:00
|
|
|
u32 textureID() const { return m_textureID; }
|
|
|
|
|
2018-07-06 15:08:13 +02:00
|
|
|
const std::string &name() const { return m_name; }
|
|
|
|
void setName(const std::string &name) { m_name = name; }
|
|
|
|
|
2018-06-13 21:48:35 +02:00
|
|
|
s8 selectedFace() const { return m_selectedFace; }
|
|
|
|
void setSelected(bool isSelected, s8 face) { m_isSelected = isSelected; m_selectedFace = face; }
|
|
|
|
|
2018-06-30 22:27:46 +02:00
|
|
|
bool isOpaque() const { return m_id != 0 && m_id != 4 && m_id != 8 && m_id != 9 && m_id != 16; }
|
2018-06-20 02:23:39 +02:00
|
|
|
|
2018-06-24 01:09:32 +02:00
|
|
|
bool canUpdate() const { return m_canUpdate; }
|
|
|
|
|
2018-06-29 21:18:48 +02:00
|
|
|
ItemStack getItemDrop() const { return ItemStack{m_itemDrop, m_itemDropAmount}; };
|
|
|
|
void setItemDrop(u16 itemDrop, u16 itemDropAmount = 1) { m_itemDrop = itemDrop; m_itemDropAmount = itemDropAmount; }
|
|
|
|
|
2018-06-29 21:55:47 +02:00
|
|
|
u8 harvestRequirements() const { return m_harvestRequirements; }
|
|
|
|
void setHarvestRequirements(u8 harvestRequirements) { m_harvestRequirements = harvestRequirements; }
|
|
|
|
|
|
|
|
float hardness() const { return m_hardness; }
|
|
|
|
void setHardness(float hardness) { m_hardness = hardness; }
|
|
|
|
|
|
|
|
float timeToBreak(u8 harvestCapability, float miningSpeed) const {
|
|
|
|
return ((m_harvestRequirements & harvestCapability) == m_harvestRequirements) ? 1.5 * m_hardness / miningSpeed : 5 * m_hardness;
|
|
|
|
}
|
|
|
|
|
2018-07-02 04:30:17 +02:00
|
|
|
const FloatBox &boundingBox() const { return m_boundingBox; }
|
|
|
|
void setBoundingBox(const FloatBox &boundingBox) { m_boundingBox = boundingBox; }
|
|
|
|
|
2018-06-24 01:09:32 +02:00
|
|
|
protected:
|
2018-06-29 09:48:37 +02:00
|
|
|
glm::vec4 getTexCoordsFromID(int textureID) const;
|
|
|
|
|
2018-06-24 01:09:32 +02:00
|
|
|
bool m_canUpdate = false;
|
|
|
|
|
2015-02-06 01:44:16 +01:00
|
|
|
private:
|
2018-06-12 23:08:42 +02:00
|
|
|
u32 m_id;
|
2018-06-25 18:12:15 +02:00
|
|
|
u32 m_textureID;
|
2018-06-13 21:48:35 +02:00
|
|
|
|
2018-07-06 15:08:13 +02:00
|
|
|
std::string m_name;
|
|
|
|
|
2018-06-13 21:48:35 +02:00
|
|
|
bool m_isSelected = false;
|
|
|
|
s8 m_selectedFace = -1;
|
2018-06-29 21:18:48 +02:00
|
|
|
|
|
|
|
u16 m_itemDrop;
|
|
|
|
u16 m_itemDropAmount;
|
2018-06-29 21:55:47 +02:00
|
|
|
|
|
|
|
u8 m_harvestRequirements = 0;
|
|
|
|
float m_hardness = 1.0f;
|
2018-07-02 04:30:17 +02:00
|
|
|
|
|
|
|
FloatBox m_boundingBox{0, 0, 0, 1, 1, 1};
|
2015-02-06 01:44:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BLOCK_HPP_
|