Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Point of interest #5379

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -51,6 +51,7 @@ target_sources(
MonsterConfig.cpp
NetherPortalScanner.cpp
OverridesSettingsRepository.cpp
PointOfInterest.cpp
ProbabDistrib.cpp
RankManager.cpp
RCONServer.cpp
Expand Down Expand Up @@ -129,6 +130,7 @@ target_sources(
NetherPortalScanner.h
OpaqueWorld.h
OverridesSettingsRepository.h
PointOfInterest.h
ProbabDistrib.h
RankManager.h
RCONServer.h
Expand Down
12 changes: 12 additions & 0 deletions src/Chunk.cpp
Expand Up @@ -28,6 +28,7 @@
#include "SetChunkData.h"
#include "BoundingBox.h"
#include "Blocks/ChunkInterface.h"
#include "PointOfInterest.h"

#include "json/json.h"

Expand Down Expand Up @@ -1285,6 +1286,9 @@ void cChunk::SetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_Blo
// Wake up the simulators for this block:
GetWorld()->GetSimulatorManager()->WakeUp(*this, a_RelPos);

// If there was a POI, remove it:
m_PoiData.RemovePoi(a_RelPos);

// If there was a block entity, remove it:
if (const auto FindResult = m_BlockEntities.find(cChunkDef::MakeIndex(a_RelPos)); FindResult != m_BlockEntities.end())
{
Expand All @@ -1302,6 +1306,14 @@ void cChunk::SetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_Blo
{
AddBlockEntity(cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, RelativeToAbsolute(a_RelPos), m_World));
}

// Adding POI if the block placed is a POI:
ePointOfInterestType PoiType = cPointOfInterest::GetPointOnInterestType(a_BlockType, a_BlockMeta);

if (PoiType != poiNone)
{
m_PoiData.AddPoi({a_RelPos, PoiType});
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/Chunk.h
Expand Up @@ -406,6 +406,9 @@ class cChunk
return UnboundedRelFastSetBlock({a_RelX, a_RelY, a_RelZ}, a_BlockType, a_BlockMeta);
}

const ChunkPoiData::PoiArray & GetPoies(size_t a_Y) { return m_PoiData.GetPoies(a_Y); }
void AddPoi(const cPointOfInterest & a_Poi) { m_PoiData.AddPoi(a_Poi); }
void RemovePoi(Vector3i a_Position) { m_PoiData.RemovePoi(a_Position); }


// Per-chunk simulator data:
Expand Down Expand Up @@ -509,6 +512,7 @@ class cChunk

ChunkBlockData m_BlockData;
ChunkLightData m_LightData;
ChunkPoiData m_PoiData;

cChunkDef::HeightMap m_HeightMap;
cChunkDef::BiomeMap m_BiomeMap;
Expand Down
37 changes: 37 additions & 0 deletions src/ChunkData.cpp
Expand Up @@ -229,6 +229,43 @@ void ChunkLightData::SetSection(const SectionType & a_BlockLightSource, const Se



void ChunkPoiData::Assign(const ChunkPoiData & a_Other)
{
m_Poies = std::move(a_Other.m_Poies);
}





void ChunkPoiData::AddPoi(const cPointOfInterest & a_Poi)
{
m_Poies.at(a_Poi.GetBlockPosition().y % 16).push_back(a_Poi);
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
}





void ChunkPoiData::RemovePoi(Vector3i a_Position)
{
PoiArray & SectionPoies = m_Poies.at(a_Position.y % 16);
auto It = std::find_if(SectionPoies.begin(), SectionPoies.end(), [&a_Position](const cPointOfInterest & a_Poi)
{
return a_Position == a_Poi.GetBlockPosition();
});

if (It != SectionPoies.end())
{
SectionPoies.erase(It);
}

}





template struct ChunkDataStore<BLOCKTYPE, ChunkBlockData::SectionBlockCount, ChunkBlockData::DefaultValue>;
template struct ChunkDataStore<NIBBLETYPE, ChunkBlockData::SectionMetaCount, ChunkLightData::DefaultBlockLightValue>;
template struct ChunkDataStore<NIBBLETYPE, ChunkLightData::SectionLightCount, ChunkLightData::DefaultSkyLightValue>;
24 changes: 24 additions & 0 deletions src/ChunkData.h
Expand Up @@ -11,6 +11,7 @@

#include "FunctionRef.h"
#include "ChunkDef.h"
#include "PointOfInterest.h"



Expand Down Expand Up @@ -130,6 +131,29 @@ class ChunkLightData



class ChunkPoiData
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
{
private:

std::array<std::vector<cPointOfInterest>, cChunkDef::SectionHeight> m_Poies;

public:

using PoiArray = decltype(m_Poies)::value_type;

void Assign(const ChunkPoiData & a_Other);

void AddPoi(const cPointOfInterest & a_Poi);
// Only removes POI if it exists
void RemovePoi(Vector3i a_Position);

const PoiArray & GetPoies(size_t a_Y) const { return m_Poies.at(a_Y); }
};





/** Invokes the callback functor for every chunk section containing at least one present block or light section data.
This is used to collect all data for all sections.
In macro form to work around a Visual Studio 2017 ICE bug. */
Expand Down
249 changes: 249 additions & 0 deletions src/PointOfInterest.cpp
@@ -0,0 +1,249 @@

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules

#include "BlockType.h"
#include "PointOfInterest.h"





ePointOfInterestType cPointOfInterest::GetPointOnInterestType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
switch (a_BlockType)
{
/*
case E_BLOCK_BLAST_FURNACE:
{
return poiArmorer;
}

case E_BLOCK_SMOKER:
{
return poiButcher;
}

case E_BLOCK_CARTOGRAPHY_TABLE:
{
return poiCartographer;
}
*/

case E_BLOCK_BREWING_STAND:
{
return poiCleric;
}

/*
case E_BLOCK_COMPOSTER:
{
return poiFarmer;
}

case E_BLOCK_BARREL:
{
return poiFisherman;
}

case E_BLOCK_FLETCHING_TABLE:
{
return poiFletcher;
}
*/

case E_BLOCK_CAULDRON:
{
return poiLetherworker;
}

/*
case E_BLOCK_LECTERN:
{
return poiLibrairian;
}

case E_BLOCK_STONECUTTER:
{
return poiMason;
}

case E_BLOCK_LOOM:
{
return poiShepherd;
}

case E_BLOCK_SMITHING_TABLE:
{
return poiToolsmith;
}

case E_BLOCK_GRINDSTONE:
{
return poiWeaponsmith;
}
*/

// The bed is a special case: only the head is a poi
case E_BLOCK_BED:
{
if ((a_BlockMeta >> 3 & 1) == 1)
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
{
return poiHome;
}
else
{
return poiNone;
}
}

/*
case E_BLOCK_BELL:
{
return poiMeeting;
}

case E_BLOCK_BEEHIVE:
{
return poiBeehive;
}

case E_BLOCK_BEE_NEST:
{
return poiBeeNest;
}
*/

case E_BLOCK_NETHER_PORTAL:
{
return poiNetherPortal;
}

/*
case E_BLOCK_LODESTONE:
{
return poiLodestone;
}

case E_BLOCK_LIGHTNING_ROD:
{
return poiLightningRod;
}
*/

default:
{
return poiNone;
}
}
}





int cPointOfInterest::GetMaxFreeTickets(ePointOfInterestType a_Type)
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
{
switch (a_Type)
{
case poiArmorer:
case poiButcher:
case poiCartographer:
case poiCleric:
case poiFarmer:
case poiFisherman:
case poiFletcher:
case poiLetherworker:
case poiLibrairian:
case poiMason:
case poiShepherd:
case poiToolsmith:
case poiWeaponsmith:
case poiHome:
{
return 1;
}

case poiMeeting:
{
return 32;
}

default:
{
return 0;
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}
}





std::string cPointOfInterest::GetPoiTypeName(ePointOfInterestType a_Type)
Persson-dev marked this conversation as resolved.
Show resolved Hide resolved
{
switch (a_Type)
{
case poiArmorer: return "minecraft:armorer";
case poiBeehive: return "minecraft:beehive";
case poiBeeNest: return "minecraft:beenest";
case poiButcher: return "minecraft:butcher";
case poiCartographer: return "minecraft:cartographer";
case poiCleric: return "minecraft:cleric";
case poiFarmer: return "minecraft:farmer";
case poiFisherman: return "minecraft:fisherman";
case poiFletcher: return "minecraft:fletcher";
case poiHome: return "minecraft:home";
case poiLetherworker: return "minecraft:letherworker";
case poiLibrairian: return "minecraft:librairian";
case poiLightningRod: return "minecraft:lightning_rod";
case poiLodestone: return "minecraft:lodestone";
case poiMason: return "minecraft:mason";
case poiMeeting: return "minecraft:meeting";
case poiNetherPortal: return "minecraft:nether_portal";
case poiShepherd: return "minecraft:shepherd";
case poiToolsmith: return "minecraft:toolsmith";
case poiWeaponsmith: return "minecraft:weaponsmith";

case poiNone: return "none";
}
}





ePointOfInterestType cPointOfInterest::GetPoiFromString(const std::string & a_PoiName)
{
static const std::map<std::string, ePointOfInterestType> StringToPoi
{
{ "minecraft:armorer", poiArmorer },
{ "minecraft:beehive", poiBeehive },
{ "minecraft:beenest", poiBeeNest },
{ "minecraft:butcher", poiButcher },
{ "minecraft:cartographer", poiCartographer },
{ "minecraft:cleric", poiCleric },
{ "minecraft:farmer", poiFarmer },
{ "minecraft:fisherman", poiFisherman },
{ "minecraft:fletcher", poiFletcher },
{ "minecraft:home", poiHome },
{ "minecraft:letherworker", poiLetherworker },
{ "minecraft:librairian", poiLibrairian },
{ "minecraft:lightning_rod", poiLightningRod },
{ "minecraft:lodestone", poiLodestone },
{ "minecraft:mason", poiMason },
{ "minecraft:meeting", poiMeeting },
{ "minecraft:nether_portal", poiNetherPortal },
{ "minecraft:shepherd", poiShepherd },
{ "minecraft:toolsmith", poiToolsmith },
{ "minecraft:weaponsmith", poiWeaponsmith },
};

const auto It = StringToPoi.find(a_PoiName);

if (It != StringToPoi.end())
{
return It->second;
}

return poiNone;
}