![]() |
Botcraft 1.21.5
|
#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 Model & | GetModel (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< AABB > | GetCollidersAtPos (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< BestTool > | best_tools |
std::map< const std::string *, const std::string *, string_ptr_compare > | variables |
Static Private Attributes | |
static std::set< std::string > | unique_strings |
static std::deque< Model > | unique_models |
static std::map< std::string, ProtocolCraft::Json::Value > | cached_jsons |
Definition at line 98 of file Blockstate.hpp.
|
strongprivate |
Definition at line 205 of file Blockstate.hpp.
Botcraft::Blockstate::Blockstate | ( | const BlockstateProperties & | properties | ) |
Create a blockstate reading files from properties path.
properties | The properties of this blockstate |
Definition at line 248 of file Blockstate.cpp.
References cached_jsons, Botcraft::CheckCondition(), Botcraft::BlockstateProperties::colliders, ProtocolCraft::Json::Value::contains(), Botcraft::BlockstateProperties::custom, ProtocolCraft::Json::Value::get_array(), ProtocolCraft::Json::Value::get_object(), Botcraft::Model::GetModel(), ProtocolCraft::Json::Value::is_array(), ProtocolCraft::Json::Value::is_null(), ProtocolCraft::Json::Value::is_object(), LoadProperties(), LoadWeightedModels(), LOG_ERROR, MatchCondition(), Botcraft::ModelModificationFromJson(), Botcraft::ModelNameFromJson(), Botcraft::BlockstateProperties::path, ProtocolCraft::Json::Value::push_back(), Botcraft::Utilities::SplitString(), Botcraft::BlockstateProperties::variables, Botcraft::WeightFromJson(), and weights_sum.
Botcraft::Blockstate::Blockstate | ( | const BlockstateProperties & | properties, |
const Model & | model_ | ||
) |
Create a blockstate from a given model, ignoring path in properties.
properties | The properties of this blockstate |
model_ | The model of this blockstate |
Definition at line 571 of file Blockstate.cpp.
References LoadProperties(), and LoadWeightedModels().
|
static |
Definition at line 945 of file Blockstate.cpp.
References cached_jsons, and unique_models.
Referenced by Botcraft::AssetsManager::ClearCaches().
|
private |
Definition at line 1093 of file Blockstate.cpp.
References ProtocolCraft::Json::Value::get(), ProtocolCraft::Json::Value::get_string(), GetName(), ProtocolCraft::Json::Value::is_bool(), ProtocolCraft::Json::Value::is_string(), and MatchCondition().
Referenced by LoadProperties().
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.
block_pos | Block position |
pos | Reference position to find the closest point from |
Definition at line 657 of file Blockstate.cpp.
References GetCollidersAtPos(), and Botcraft::Vector3< T >::SqrDist().
Referenced by Botcraft::DigImpl().
Definition at line 642 of file Blockstate.cpp.
References Botcraft::Model::GetColliders(), GetHorizontalOffsetAtPos(), GetModel(), and GetModelId().
Referenced by GetClosestPoint(), Botcraft::World::GetColliders(), Botcraft::World::GetSupportingBlockPos(), Botcraft::World::IsFree(), Botcraft::PathfindingBlockstate::PathfindingBlockstate(), and Botcraft::World::Raycast().
float Botcraft::Blockstate::GetFluidHeight | ( | ) | const |
Get fluid height for this block.
Does not take into account neighbouring blocks
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().
float Botcraft::Blockstate::GetFriction | ( | ) | const |
Definition at line 827 of file Blockstate.cpp.
References friction.
Referenced by Botcraft::PhysicsManager::MovePlayer(), and Botcraft::Renderer::RenderingManager::Run().
float Botcraft::Blockstate::GetHardness | ( | ) | const |
Definition at line 822 of file Blockstate.cpp.
References hardness.
Referenced by Botcraft::DigImpl(), and Botcraft::Renderer::RenderingManager::Run().
Definition at line 621 of file Blockstate.cpp.
References flags, HorizontalOffset0_125, HorizontalOffset0_25, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
Referenced by GetCollidersAtPos(), and Botcraft::Renderer::WorldRenderer::UpdateChunk().
BlockstateId Botcraft::Blockstate::GetId | ( | ) | const |
Definition at line 578 of file Blockstate.cpp.
References blockstate_id.
Referenced by Botcraft::DigImpl(), Botcraft::Renderer::WorldRenderer::GetColorModifier(), Botcraft::PrimedTntEntity::PrimedTntEntity(), and Botcraft::Chunk::SetBlock().
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.
tool_type | The tool used to mine |
tool_material | The material the tool is made of |
tool_efficiency_additional_speed | Additional speed added by current tool level of efficiency enchantment (efficiency² + (efficiency > 0)) |
haste | Level of haste applied to the player |
fatigue | Level of mining fatigue applied to the player |
on_ground | Boolean indicating whether or not the player is currently on the ground |
speed_factor | Speed multiplier to apply (e.g. 0.2 if under water with no aqua affinity) |
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().
const Model & Botcraft::Blockstate::GetModel | ( | const unsigned short | index | ) | const |
Definition at line 583 of file Blockstate.cpp.
References models_indices, and unique_models.
Referenced by GetCollidersAtPos(), and Botcraft::Renderer::WorldRenderer::UpdateChunk().
unsigned char Botcraft::Blockstate::GetModelId | ( | const Position & | pos | ) | const |
Definition at line 588 of file Blockstate.cpp.
References models_weights, and weights_sum.
Referenced by GetCollidersAtPos(), and Botcraft::Renderer::WorldRenderer::UpdateChunk().
const std::string & Botcraft::Blockstate::GetName | ( | ) | const |
Definition at line 611 of file Blockstate.cpp.
References m_name.
Referenced by Botcraft::DigImpl(), Botcraft::AssetsManager::GetBlockstate(), GetBoolFromCondition(), Botcraft::PlaceBlockImpl(), Botcraft::Renderer::RenderingManager::Run(), and Botcraft::Renderer::WorldRenderer::UpdateChunk().
size_t Botcraft::Blockstate::GetNumModels | ( | ) | const |
Definition at line 1000 of file Blockstate.cpp.
References models_indices.
TintType Botcraft::Blockstate::GetTintType | ( | ) | const |
Definition at line 832 of file Blockstate.cpp.
References tint_type.
Referenced by Botcraft::Renderer::WorldRenderer::GetColorModifier().
|
staticprivate |
Definition at line 1137 of file Blockstate.cpp.
References Botcraft::Model::IsSame(), and unique_models.
Referenced by LoadWeightedModels().
|
staticprivate |
Definition at line 1132 of file Blockstate.cpp.
References unique_strings.
Referenced by LoadProperties().
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().
bool Botcraft::Blockstate::IsAir | ( | ) | const |
Definition at line 675 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks(), Botcraft::DigImpl(), Botcraft::GoToImpl(), Botcraft::Move(), Botcraft::PlaceBlockImpl(), Botcraft::World::Raycast(), Botcraft::Renderer::RenderingManager::Run(), and Botcraft::Renderer::WorldRenderer::UpdateChunk().
bool Botcraft::Blockstate::IsBed | ( | ) | const |
Definition at line 746 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::ApplyMovement(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsBerryBush | ( | ) | const |
Definition at line 804 of file Blockstate.cpp.
References BerryBush, and flags.
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsBubbleColumn | ( | ) | const |
Definition at line 774 of file Blockstate.cpp.
References IsDownBubbleColumn(), and IsUpBubbleColumn().
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks().
bool Botcraft::Blockstate::IsClimbable | ( | ) | const |
Definition at line 731 of file Blockstate.cpp.
References Climbable, and flags.
Referenced by Botcraft::FindPath(), Botcraft::GoToImpl(), Botcraft::PhysicsManager::IsInClimbable(), Botcraft::PathfindingBlockstate::PathfindingBlockstate(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsCobweb | ( | ) | const |
Definition at line 799 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsDownBubbleColumn | ( | ) | const |
Definition at line 789 of file Blockstate.cpp.
References DownBubbleColumn, and flags.
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks(), IsBubbleColumn(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsFluid | ( | ) | const |
Definition at line 690 of file Blockstate.cpp.
References flags, Lava, and Water.
Referenced by Botcraft::DigImpl(), Botcraft::PhysicsManager::FluidPhysics(), Botcraft::GoToImpl(), IsFluidOrWaterlogged(), Botcraft::World::IsFree(), Botcraft::PhysicsManager::PhysicsTick(), and Botcraft::PlaceBlockImpl().
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().
bool Botcraft::Blockstate::IsFluidOrWaterlogged | ( | ) | const |
Definition at line 696 of file Blockstate.cpp.
References flags, IsFluid(), and WaterLogged.
Referenced by Botcraft::World::GetFlow(), GetFluidHeight(), Botcraft::Move(), and Botcraft::PathfindingBlockstate::PathfindingBlockstate().
bool Botcraft::Blockstate::IsHazardous | ( | ) | const |
Definition at line 736 of file Blockstate.cpp.
References flags, and Hazardous.
Referenced by Botcraft::PathfindingBlockstate::PathfindingBlockstate(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsHoney | ( | ) | const |
Definition at line 756 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::ApplyMovement(), Botcraft::PhysicsManager::CheckInsideBlocks(), Botcraft::PhysicsManager::InputsToJump(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsLava | ( | ) | const |
Definition at line 701 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::FluidPhysics(), GetMiningTimeSeconds(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsPowderSnow | ( | ) | const |
Definition at line 813 of file Blockstate.cpp.
References flags, and PowderSnow.
Referenced by Botcraft::PhysicsManager::CheckInsideBlocks(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsScaffolding | ( | ) | const |
Definition at line 765 of file Blockstate.cpp.
References flags, and Scaffolding.
Referenced by Botcraft::Move(), Botcraft::PhysicsManager::MovePlayer(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsSlime | ( | ) | const |
Definition at line 741 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::ApplyMovement(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsSolid | ( | ) | const |
Definition at line 680 of file Blockstate.cpp.
Referenced by Botcraft::FindPath(), Botcraft::World::GetColliders(), Botcraft::World::GetFlow(), Botcraft::World::GetSupportingBlockPos(), Botcraft::World::IsFree(), Botcraft::PathfindingBlockstate::PathfindingBlockstate(), Botcraft::PlaceBlockImpl(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsSoulSand | ( | ) | const |
Definition at line 751 of file Blockstate.cpp.
References flags, and SoulSand.
Referenced by Botcraft::PhysicsManager::ApplyMovement(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsTransparent | ( | ) | const |
Definition at line 685 of file Blockstate.cpp.
References flags, and Transparent.
Referenced by Botcraft::Renderer::RenderingManager::Run().
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().
bool Botcraft::Blockstate::IsWater | ( | ) | const |
Definition at line 711 of file Blockstate.cpp.
Referenced by Botcraft::PhysicsManager::FluidPhysics(), GetMiningTimeSeconds(), IsWaterOrWaterlogged(), Botcraft::Renderer::RenderingManager::Run(), and Botcraft::PhysicsManager::UpdateSwimming().
bool Botcraft::Blockstate::IsWaterlogged | ( | ) | const |
Definition at line 716 of file Blockstate.cpp.
References flags, and WaterLogged.
Referenced by GetFluidHeight(), IsWaterOrWaterlogged(), and Botcraft::Renderer::RenderingManager::Run().
bool Botcraft::Blockstate::IsWaterOrWaterlogged | ( | ) | const |
Definition at line 726 of file Blockstate.cpp.
References IsWater(), and IsWaterlogged().
Referenced by Botcraft::World::GetFlow().
|
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().
|
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().
|
private |
Check if a given string condition match this blockstate variables.
condition | String to check, example: "layers=1" |
Definition at line 1106 of file Blockstate.cpp.
References Botcraft::Utilities::Contains(), Botcraft::Utilities::SplitString(), and variables.
Referenced by Blockstate(), and GetBoolFromCondition().
|
static |
Definition at line 952 of file Blockstate.cpp.
References Botcraft::Renderer::Animated, Botcraft::Renderer::TextureData::animation, Botcraft::Renderer::Atlas::GetData(), Botcraft::Renderer::Atlas::GetHeight(), Botcraft::Renderer::Atlas::GetWidth(), Botcraft::Renderer::Opaque, Botcraft::Renderer::TextureData::position, Botcraft::Renderer::TextureData::size, Botcraft::Renderer::Static, Botcraft::Renderer::TextureData::transparency, and unique_models.
Referenced by Botcraft::AssetsManager::UpdateModelsWithAtlasData().
|
private |
Definition at line 245 of file Blockstate.hpp.
Referenced by GetMiningTimeSeconds(), and LoadProperties().
|
private |
Definition at line 202 of file Blockstate.hpp.
Referenced by GetId(), and LoadProperties().
|
staticprivate |
Definition at line 191 of file Blockstate.hpp.
Referenced by Blockstate(), and ClearCache().
|
private |
Definition at line 235 of file Blockstate.hpp.
Referenced by GetFluidHeight(), GetHorizontalOffsetAtPos(), GetMiningTimeSeconds(), IsAir(), IsBed(), IsBerryBush(), IsClimbable(), IsCobweb(), IsDownBubbleColumn(), IsFluid(), IsFluidFalling(), IsFluidOrWaterlogged(), IsHazardous(), IsHoney(), IsLava(), IsPowderSnow(), IsScaffolding(), IsSlime(), IsSolid(), IsSoulSand(), IsTransparent(), IsUpBubbleColumn(), IsWater(), IsWaterlogged(), and LoadProperties().
|
private |
Definition at line 237 of file Blockstate.hpp.
Referenced by GetFriction(), and LoadProperties().
|
private |
Definition at line 236 of file Blockstate.hpp.
Referenced by GetHardness(), GetMiningTimeSeconds(), and LoadProperties().
|
private |
Definition at line 239 of file Blockstate.hpp.
Referenced by GetName(), and LoadProperties().
|
private |
Definition at line 241 of file Blockstate.hpp.
Referenced by GetModel(), GetNumModels(), and LoadWeightedModels().
|
private |
Definition at line 242 of file Blockstate.hpp.
Referenced by GetModelId(), and LoadWeightedModels().
|
private |
Definition at line 238 of file Blockstate.hpp.
Referenced by GetTintType(), and LoadProperties().
|
staticprivate |
Definition at line 189 of file Blockstate.hpp.
Referenced by ClearCache(), GetModel(), GetUniqueModelIndex(), LoadWeightedModels(), and UpdateModelsWithAtlasData().
|
staticprivate |
Definition at line 187 of file Blockstate.hpp.
Referenced by GetUniqueStringPtr().
|
private |
Definition at line 247 of file Blockstate.hpp.
Referenced by GetVariableValue(), LoadProperties(), and MatchCondition().
|
private |
Definition at line 243 of file Blockstate.hpp.
Referenced by Blockstate(), GetModelId(), and LoadWeightedModels().