Botcraft 1.21.5
Loading...
Searching...
No Matches
Botcraft::Blockstate Class Reference

#include <Blockstate.hpp>

Classes

struct  string_ptr_compare
 

Public Member Functions

 Blockstate (const BlockstateProperties &properties)
 Create a blockstate reading files from properties path.
 
 Blockstate (const BlockstateProperties &properties, const Model &model_)
 Create a blockstate from a given model, ignoring path in properties.
 
BlockstateId GetId () const
 
const ModelGetModel (const unsigned short index) const
 
unsigned char GetModelId (const Position &pos) const
 
size_t GetNumModels () const
 
const std::string & GetName () const
 
const std::string & GetVariableValue (const std::string &variable) const
 
Vector3< double > GetHorizontalOffsetAtPos (const Position &pos) const
 
std::set< AABBGetCollidersAtPos (const Position &pos) const
 
Vector3< double > GetClosestPoint (const Position &block_pos, const Vector3< double > &pos) const
 Get the closest point on this blockstate placed at block_pos from a reference pos.
 
bool IsAir () const
 
bool IsSolid () const
 
bool IsTransparent () const
 
bool IsFluid () const
 
bool IsFluidOrWaterlogged () const
 
bool IsLava () const
 
bool IsFluidFalling () const
 
bool IsWater () const
 
bool IsWaterlogged () const
 
bool IsWaterOrWaterlogged () const
 
bool IsClimbable () const
 
bool IsHazardous () const
 
bool IsSlime () const
 
bool IsBed () const
 
bool IsSoulSand () const
 
bool IsHoney () const
 
bool IsScaffolding () const
 
bool IsCobweb () const
 
bool IsBubbleColumn () const
 
bool IsUpBubbleColumn () const
 
bool IsDownBubbleColumn () const
 
bool IsBerryBush () const
 
bool IsPowderSnow () const
 
float GetHardness () const
 
float GetFriction () const
 
TintType GetTintType () const
 
float GetFluidHeight () const
 Get fluid height for this block.
 
float GetMiningTimeSeconds (const ToolType tool_type, const ToolMaterial tool_material, const float tool_efficiency_additional_speed=0.0f, const unsigned char haste=0, const unsigned char fatigue=0, const bool on_ground=true, const float speed_factor=1.0f) const
 Compute the amount of time (in s) required to mine this block.
 

Static Public Member Functions

static void ClearCache ()
 
static void UpdateModelsWithAtlasData (const Renderer::Atlas *atlas)
 

Private Types

enum class  BlockstateFlags : size_t {
  Air = 0 , Solid , Transparent , Lava ,
  Water , WaterLogged , FluidFalling , FluidLevelBit_0 ,
  FluidLevelBit_1 , FluidLevelBit_2 , Climbable , Hazardous ,
  AnyToolHarvest , Slime , Bed , SoulSand ,
  Honey , Scaffolding , Cobweb , UpBubbleColumn ,
  DownBubbleColumn , BerryBush , PowderSnow , HorizontalOffset0_25 ,
  HorizontalOffset0_125 , NUM_FLAGS
}
 

Private Member Functions

void LoadProperties (const BlockstateProperties &properties)
 
void LoadWeightedModels (const std::deque< std::pair< Model, int > > &models_to_load)
 
bool GetBoolFromCondition (const ProtocolCraft::Json::Value &condition) const
 
bool MatchCondition (const std::string &condition) const
 Check if a given string condition match this blockstate variables.
 

Static Private Member Functions

static const std::string * GetUniqueStringPtr (const std::string &s)
 
static size_t GetUniqueModelIndex (const Model &model)
 

Private Attributes

BlockstateId blockstate_id
 
std::bitset< static_cast< size_t >(BlockstateFlags::NUM_FLAGS)> flags
 
float hardness
 
float friction
 
TintType tint_type
 
const std::string * m_name
 
std::vector< size_t > models_indices
 
std::vector< int > models_weights
 
int weights_sum
 
std::vector< BestToolbest_tools
 
std::map< const std::string *, const std::string *, string_ptr_comparevariables
 

Static Private Attributes

static std::set< std::string > unique_strings
 
static std::deque< Modelunique_models
 
static std::map< std::string, ProtocolCraft::Json::Valuecached_jsons
 

Detailed Description

Definition at line 98 of file Blockstate.hpp.

Member Enumeration Documentation

◆ BlockstateFlags

enum class Botcraft::Blockstate::BlockstateFlags : size_t
strongprivate
Enumerator
Air 
Solid 
Transparent 
Lava 
Water 
WaterLogged 
FluidFalling 
FluidLevelBit_0 
FluidLevelBit_1 
FluidLevelBit_2 
Climbable 
Hazardous 
AnyToolHarvest 
Slime 
Bed 
SoulSand 
Honey 
Scaffolding 
Cobweb 
UpBubbleColumn 
DownBubbleColumn 
BerryBush 
PowderSnow 
HorizontalOffset0_25 
HorizontalOffset0_125 
NUM_FLAGS 

Definition at line 205 of file Blockstate.hpp.

Constructor & Destructor Documentation

◆ Blockstate() [1/2]

◆ Blockstate() [2/2]

Botcraft::Blockstate::Blockstate ( const BlockstateProperties properties,
const Model model_ 
)

Create a blockstate from a given model, ignoring path in properties.

Parameters
propertiesThe properties of this blockstate
model_The model of this blockstate

Definition at line 571 of file Blockstate.cpp.

References LoadProperties(), and LoadWeightedModels().

Member Function Documentation

◆ ClearCache()

void Botcraft::Blockstate::ClearCache ( )
static

Definition at line 945 of file Blockstate.cpp.

References cached_jsons, and unique_models.

Referenced by Botcraft::AssetsManager::ClearCaches().

◆ GetBoolFromCondition()

bool Botcraft::Blockstate::GetBoolFromCondition ( const ProtocolCraft::Json::Value condition) const
private

◆ GetClosestPoint()

Vector3< double > Botcraft::Blockstate::GetClosestPoint ( const Position block_pos,
const Vector3< double > &  pos 
) const

Get the closest point on this blockstate placed at block_pos from a reference pos.

Parameters
block_posBlock position
posReference position to find the closest point from
Returns
The closest point inside the block AABB shapes

Definition at line 657 of file Blockstate.cpp.

References GetCollidersAtPos(), and Botcraft::Vector3< T >::SqrDist().

Referenced by Botcraft::DigImpl().

◆ GetCollidersAtPos()

◆ GetFluidHeight()

float Botcraft::Blockstate::GetFluidHeight ( ) const

Get fluid height for this block.

Does not take into account neighbouring blocks

Returns
Height of fluid in this block, between 0 and 1

Definition at line 837 of file Blockstate.cpp.

References flags, FluidFalling, FluidLevelBit_0, FluidLevelBit_1, FluidLevelBit_2, IsFluidOrWaterlogged(), and IsWaterlogged().

Referenced by Botcraft::PhysicsManager::FluidPhysics(), Botcraft::World::GetFlow(), and Botcraft::Renderer::RenderingManager::Run().

◆ GetFriction()

float Botcraft::Blockstate::GetFriction ( ) const

◆ GetHardness()

float Botcraft::Blockstate::GetHardness ( ) const

Definition at line 822 of file Blockstate.cpp.

References hardness.

Referenced by Botcraft::DigImpl(), and Botcraft::Renderer::RenderingManager::Run().

◆ GetHorizontalOffsetAtPos()

Vector3< double > Botcraft::Blockstate::GetHorizontalOffsetAtPos ( const Position pos) const

◆ GetId()

◆ GetMiningTimeSeconds()

float Botcraft::Blockstate::GetMiningTimeSeconds ( const ToolType  tool_type,
const ToolMaterial  tool_material,
const float  tool_efficiency_additional_speed = 0.0f,
const unsigned char  haste = 0,
const unsigned char  fatigue = 0,
const bool  on_ground = true,
const float  speed_factor = 1.0f 
) const

Compute the amount of time (in s) required to mine this block.

Parameters
tool_typeThe tool used to mine
tool_materialThe material the tool is made of
tool_efficiency_additional_speedAdditional speed added by current tool level of efficiency enchantment (efficiency² + (efficiency > 0))
hasteLevel of haste applied to the player
fatigueLevel of mining fatigue applied to the player
on_groundBoolean indicating whether or not the player is currently on the ground
speed_factorSpeed multiplier to apply (e.g. 0.2 if under water with no aqua affinity)
Returns
The time required to mine this block in these conditions, or -1 if can't be mined

Definition at line 859 of file Blockstate.cpp.

References AnyToolHarvest, Botcraft::Axe, best_tools, flags, hardness, Botcraft::Hoe, IsLava(), IsWater(), LOG_WARNING, Botcraft::NUM_TOOL_MATERIAL, Botcraft::Pickaxe, Botcraft::Shears, Botcraft::Shovel, and Botcraft::Sword.

Referenced by Botcraft::DigImpl().

◆ GetModel()

const Model & Botcraft::Blockstate::GetModel ( const unsigned short  index) const

◆ GetModelId()

unsigned char Botcraft::Blockstate::GetModelId ( const Position pos) const

◆ GetName()

◆ GetNumModels()

size_t Botcraft::Blockstate::GetNumModels ( ) const

Definition at line 1000 of file Blockstate.cpp.

References models_indices.

◆ GetTintType()

TintType Botcraft::Blockstate::GetTintType ( ) const

Definition at line 832 of file Blockstate.cpp.

References tint_type.

Referenced by Botcraft::Renderer::WorldRenderer::GetColorModifier().

◆ GetUniqueModelIndex()

size_t Botcraft::Blockstate::GetUniqueModelIndex ( const Model model)
staticprivate

Definition at line 1137 of file Blockstate.cpp.

References Botcraft::Model::IsSame(), and unique_models.

Referenced by LoadWeightedModels().

◆ GetUniqueStringPtr()

const std::string * Botcraft::Blockstate::GetUniqueStringPtr ( const std::string &  s)
staticprivate

Definition at line 1132 of file Blockstate.cpp.

References unique_strings.

Referenced by LoadProperties().

◆ GetVariableValue()

const std::string & Botcraft::Blockstate::GetVariableValue ( const std::string &  variable) const

Definition at line 616 of file Blockstate.cpp.

References variables.

Referenced by Botcraft::Renderer::WorldRenderer::GetColorModifier().

◆ IsAir()

◆ IsBed()

bool Botcraft::Blockstate::IsBed ( ) const

◆ IsBerryBush()

bool Botcraft::Blockstate::IsBerryBush ( ) const

◆ IsBubbleColumn()

bool Botcraft::Blockstate::IsBubbleColumn ( ) const

◆ IsClimbable()

◆ IsCobweb()

bool Botcraft::Blockstate::IsCobweb ( ) const

◆ IsDownBubbleColumn()

bool Botcraft::Blockstate::IsDownBubbleColumn ( ) const

◆ IsFluid()

◆ IsFluidFalling()

bool Botcraft::Blockstate::IsFluidFalling ( ) const

Definition at line 706 of file Blockstate.cpp.

References flags, and FluidFalling.

Referenced by Botcraft::World::GetFlow(), and Botcraft::Renderer::RenderingManager::Run().

◆ IsFluidOrWaterlogged()

bool Botcraft::Blockstate::IsFluidOrWaterlogged ( ) const

◆ IsHazardous()

bool Botcraft::Blockstate::IsHazardous ( ) const

◆ IsHoney()

◆ IsLava()

bool Botcraft::Blockstate::IsLava ( ) const

◆ IsPowderSnow()

bool Botcraft::Blockstate::IsPowderSnow ( ) const

◆ IsScaffolding()

bool Botcraft::Blockstate::IsScaffolding ( ) const

◆ IsSlime()

bool Botcraft::Blockstate::IsSlime ( ) const

◆ IsSolid()

◆ IsSoulSand()

bool Botcraft::Blockstate::IsSoulSand ( ) const

◆ IsTransparent()

bool Botcraft::Blockstate::IsTransparent ( ) const

Definition at line 685 of file Blockstate.cpp.

References flags, and Transparent.

Referenced by Botcraft::Renderer::RenderingManager::Run().

◆ IsUpBubbleColumn()

bool Botcraft::Blockstate::IsUpBubbleColumn ( ) const

Definition at line 779 of file Blockstate.cpp.

References flags, and UpBubbleColumn.

Referenced by IsBubbleColumn(), and Botcraft::Renderer::RenderingManager::Run().

◆ IsWater()

◆ IsWaterlogged()

bool Botcraft::Blockstate::IsWaterlogged ( ) const

◆ IsWaterOrWaterlogged()

bool Botcraft::Blockstate::IsWaterOrWaterlogged ( ) const

Definition at line 726 of file Blockstate.cpp.

References IsWater(), and IsWaterlogged().

Referenced by Botcraft::World::GetFlow().

◆ LoadProperties()

void Botcraft::Blockstate::LoadProperties ( const BlockstateProperties properties)
private

Definition at line 1005 of file Blockstate.cpp.

References Botcraft::BlockstateProperties::air, Air, Botcraft::BlockstateProperties::any_tool_harvest, AnyToolHarvest, Botcraft::BlockstateProperties::bed, Bed, Botcraft::BlockstateProperties::berry_bush, BerryBush, Botcraft::BlockstateProperties::best_tools, best_tools, blockstate_id, Botcraft::BlockstateProperties::climbable, Climbable, Botcraft::BlockstateProperties::cobweb, Cobweb, Botcraft::BlockstateProperties::down_bubble_column, DownBubbleColumn, flags, FluidFalling, FluidLevelBit_0, FluidLevelBit_1, FluidLevelBit_2, Botcraft::BlockstateProperties::friction, friction, GetBoolFromCondition(), GetUniqueStringPtr(), Botcraft::BlockstateProperties::hardness, hardness, Botcraft::BlockstateProperties::hazardous, Hazardous, Botcraft::BlockstateProperties::honey, Honey, Botcraft::BlockstateProperties::horizontal_offset, HorizontalOffset0_125, HorizontalOffset0_25, Botcraft::BlockstateProperties::id, Botcraft::BlockstateProperties::lava, Lava, m_name, Botcraft::BlockstateProperties::name, Botcraft::BlockstateProperties::powder_snow, PowderSnow, Botcraft::BlockstateProperties::scaffolding, Scaffolding, Botcraft::BlockstateProperties::slime, Slime, Botcraft::BlockstateProperties::solid, Solid, Botcraft::BlockstateProperties::soul_sand, SoulSand, Botcraft::Utilities::SplitString(), Botcraft::BlockstateProperties::tint_type, tint_type, Botcraft::BlockstateProperties::transparent, Transparent, Botcraft::BlockstateProperties::up_bubble_column, UpBubbleColumn, Botcraft::BlockstateProperties::variables, variables, Botcraft::BlockstateProperties::water, Water, Botcraft::BlockstateProperties::waterlogged, and WaterLogged.

Referenced by Blockstate(), and Blockstate().

◆ LoadWeightedModels()

void Botcraft::Blockstate::LoadWeightedModels ( const std::deque< std::pair< Model, int > > &  models_to_load)
private

Definition at line 1058 of file Blockstate.cpp.

References GetUniqueModelIndex(), models_indices, models_weights, unique_models, and weights_sum.

Referenced by Blockstate(), and Blockstate().

◆ MatchCondition()

bool Botcraft::Blockstate::MatchCondition ( const std::string &  condition) const
private

Check if a given string condition match this blockstate variables.

Parameters
conditionString to check, example: "layers=1"
Returns
True if variables values match, false otherwise

Definition at line 1106 of file Blockstate.cpp.

References Botcraft::Utilities::Contains(), Botcraft::Utilities::SplitString(), and variables.

Referenced by Blockstate(), and GetBoolFromCondition().

◆ UpdateModelsWithAtlasData()

Member Data Documentation

◆ best_tools

std::vector<BestTool> Botcraft::Blockstate::best_tools
private

Definition at line 245 of file Blockstate.hpp.

Referenced by GetMiningTimeSeconds(), and LoadProperties().

◆ blockstate_id

BlockstateId Botcraft::Blockstate::blockstate_id
private

Definition at line 202 of file Blockstate.hpp.

Referenced by GetId(), and LoadProperties().

◆ cached_jsons

std::map< std::string, Json::Value > Botcraft::Blockstate::cached_jsons
staticprivate

Definition at line 191 of file Blockstate.hpp.

Referenced by Blockstate(), and ClearCache().

◆ flags

◆ friction

float Botcraft::Blockstate::friction
private

Definition at line 237 of file Blockstate.hpp.

Referenced by GetFriction(), and LoadProperties().

◆ hardness

float Botcraft::Blockstate::hardness
private

Definition at line 236 of file Blockstate.hpp.

Referenced by GetHardness(), GetMiningTimeSeconds(), and LoadProperties().

◆ m_name

const std::string* Botcraft::Blockstate::m_name
private

Definition at line 239 of file Blockstate.hpp.

Referenced by GetName(), and LoadProperties().

◆ models_indices

std::vector<size_t> Botcraft::Blockstate::models_indices
private

Definition at line 241 of file Blockstate.hpp.

Referenced by GetModel(), GetNumModels(), and LoadWeightedModels().

◆ models_weights

std::vector<int> Botcraft::Blockstate::models_weights
private

Definition at line 242 of file Blockstate.hpp.

Referenced by GetModelId(), and LoadWeightedModels().

◆ tint_type

TintType Botcraft::Blockstate::tint_type
private

Definition at line 238 of file Blockstate.hpp.

Referenced by GetTintType(), and LoadProperties().

◆ unique_models

std::deque< Model > Botcraft::Blockstate::unique_models
staticprivate

◆ unique_strings

std::set< std::string > Botcraft::Blockstate::unique_strings
staticprivate

Definition at line 187 of file Blockstate.hpp.

Referenced by GetUniqueStringPtr().

◆ variables

std::map<const std::string*, const std::string*, string_ptr_compare> Botcraft::Blockstate::variables
private

Definition at line 247 of file Blockstate.hpp.

Referenced by GetVariableValue(), LoadProperties(), and MatchCondition().

◆ weights_sum

int Botcraft::Blockstate::weights_sum
private

Definition at line 243 of file Blockstate.hpp.

Referenced by Blockstate(), GetModelId(), and LoadWeightedModels().


The documentation for this class was generated from the following files: