Added some docs to test

This commit is contained in:
Liriosha 2026-03-13 19:50:43 -04:00
parent 07ab03d812
commit d57e2ae906
No known key found for this signature in database
GPG key ID: 1A9AA2EFDA5F83E9
2 changed files with 172 additions and 46 deletions

View file

@ -1,10 +1,17 @@
#include "../Platform/stdafx.h"
#include "../Headers/net.minecraft.locale.h"
#include "../Items/ItemInstance.h"
#include "Achievements.h"
#include "../Platform/stdafx.h"
#include "../Util/DescFormatter.h"
#include "Achievement.h"
#include "Achievements.h"
/**
* @brief Performs internal initialization for the achievement.
*
* Updates the global achievement grid bounds.
* These bounds are used for rendering the
* achievement UI.
*/
void Achievement::_init() {
isGoldenVar = false;
@ -14,6 +21,16 @@ void Achievement::_init() {
if (y > Achievements::yMax) Achievements::yMax = y;
}
/**
* @brief Creates an achievement with an item icon.
*
* @param id Local achievement ID
* @param name Internal achievement name used for localization
* @param x X position in the achievement tree
* @param y Y position in the achievement tree
* @param icon Item used as the achievement icon
* @param requires Achievement object that is required to unlock this one
*/
Achievement::Achievement(int id, const std::wstring& name, int x, int y,
Item* icon, Achievement* requires)
: Stat(Achievements::ACHIEVEMENT_OFFSET + id,
@ -48,16 +65,52 @@ Achievement::Achievement(int id, const std::wstring& name, int x, int y,
y(y),
requires(requires) {}
Achievement
* Achievement::setAwardLocallyOnly() {
/**
* @brief Sets the decription formatter (DescFormatter)
* @param descFormatter Pointer to the DescFormatter formatting the description text.
* @return self
**/
Achievement* Achievement::setDescFormatter(DescFormatter* descFormatter) {
this->descFormatter = descFormatter;
return this;
}
/**
* @brief Returns whether the Achivement is golden
* @return boolean
*/
bool Achievement::isGolden() { return isGoldenVar; }
int Achievement::getAchievementID() {
return id - Achievements::ACHIEVEMENT_OFFSET;
}
/**
* @brief Marks the achievement as locally awarded only.
* @return self
*/
Achievement* Achievement::setAwardLocallyOnly() {
awardLocallyOnly = true;
return this;
}
/**
* @brief Marks the achievement as a golden achievement.
*
* Golden achievements are rendered differently
* in the achievement UI.
*
* @return self
*/
Achievement* Achievement::setGolden() {
isGoldenVar = true;
return this;
}
/**
* @brief Adds the achievement to the global achievement registry.
* @return This achievement instance
*/
Achievement* Achievement::postConstruct() {
Stat::postConstruct();
@ -67,22 +120,20 @@ Achievement* Achievement::postConstruct() {
return this;
}
/**
* @brief Indicates that this stat represents an achievement.
*
* @return Always true
*/
bool Achievement::isAchievement() { return true; }
/**
* @brief Gets the description of an Achivement according to it's DescFormatter'
* @return wstring
**/
std::wstring Achievement::getDescription() {
if (descFormatter != NULL) {
return descFormatter->format(desc);
}
return desc;
}
Achievement* Achievement::setDescFormatter(DescFormatter* descFormatter) {
this->descFormatter = descFormatter;
return this;
}
bool Achievement::isGolden() { return isGoldenVar; }
int Achievement::getAchievementID() {
return id - Achievements::ACHIEVEMENT_OFFSET;
}

View file

@ -2,6 +2,14 @@
#include "../../Util/Arrays.h"
#include "FixedBiomeSource.h"
/**
* @brief Constructs a FixedBiomeSource with a single biome, temperature, and
* downfall.
*
* @param fixed Biome to use for the entire source
* @param temperature Temperature value for all blocks
* @param downfall Downfall value for all blocks
*/
FixedBiomeSource::FixedBiomeSource(Biome* fixed, float temperature,
float downfall) {
this->biome = fixed;
@ -9,22 +17,61 @@ FixedBiomeSource::FixedBiomeSource(Biome* fixed, float temperature,
this->downfall = downfall;
}
/**
* @brief Returns the biome at a given ChunkPos.
*
* @param cp Target chunk position
* @return Biome* Always returns the fixed biome
*/
Biome* FixedBiomeSource::getBiome(ChunkPos* cp) { return biome; }
/**
* @brief Returns the biome at specific coordinates.
*
* @param x X coordinate
* @param z Z coordinate
* @return Biome* Always returns the fixed biome
*/
Biome* FixedBiomeSource::getBiome(int x, int z) { return biome; }
/**
* @brief Returns the temperature at specific coordinates.
*
* @param x X coordinate
* @param z Z coordinate
* @return float The fixed temperature
*/
float FixedBiomeSource::getTemperature(int x, int z) { return temperature; }
/**
* @brief Fills a float array with temperature values for a rectangular region.
*
* If the array is null or too small, it will be reallocated.
*
* @param temperatures Array to fill with temperature values
* @param x Starting X coordinate
* @param z Starting Z coordinate
* @param w Width of the region
* @param h Height of the region
*/
void FixedBiomeSource::getTemperatureBlock(floatArray& temperatures, int x,
int z, int w, int h) const {
if (temperatures.data == NULL || temperatures.length < w * h) {
if (temperatures.data != NULL) delete[] temperatures.data;
if (!temperatures.data || temperatures.length < w * h) {
if (temperatures.data) delete[] temperatures.data;
temperatures = floatArray(w * h);
}
Arrays::fill(temperatures, 0, w * h, temperature);
}
/**
* @brief Convenience overload: returns a floatArray filled with temperatures.
*
* @param x Starting X coordinate
* @param z Starting Z coordinate
* @param w Width of the region
* @param h Height of the region
* @return floatArray Filled with temperature values
*/
floatArray FixedBiomeSource::getTemperatureBlock(int x, int z, int w,
int h) const {
floatArray temps(w * h);
@ -32,24 +79,36 @@ floatArray FixedBiomeSource::getTemperatureBlock(int x, int z, int w,
return temps;
}
// 4J - note that caller is responsible for deleting returned array.
// temperatures array is for output only.
/**
* @brief Fills a double array with temperature values.
*
* @param temperatures Array to fill (memory allocated inside)
* @param x Starting X coordinate
* @param z Starting Z coordinate
* @param w Width of the region
* @param h Height of the region
*/
void FixedBiomeSource::getTemperatureBlock(doubleArray& temperatures, int x,
int z, int w, int h) const {
temperatures = doubleArray(w * h);
Arrays::fill(temperatures, 0, w * h, (double)temperature);
Arrays::fill(temperatures, 0, w * h, static_cast<double>(temperature));
}
/**
* @brief Fills a float array with downfall values for a rectangular region.
*/
void FixedBiomeSource::getDownfallBlock(floatArray& downfalls, int x, int z,
int w, int h) const {
if (downfalls.data == NULL || downfalls.length < w * h) {
if (downfalls.data != NULL) delete[] downfalls.data;
if (!downfalls.data || downfalls.length < w * h) {
if (downfalls.data) delete[] downfalls.data;
downfalls = floatArray(w * h);
}
Arrays::fill(downfalls, 0, w * h, downfall);
}
/**
* @brief Returns a floatArray filled with downfall values.
*/
floatArray FixedBiomeSource::getDownfallBlock(int x, int z, int w,
int h) const {
floatArray downfalls(w * h);
@ -57,30 +116,37 @@ floatArray FixedBiomeSource::getDownfallBlock(int x, int z, int w,
return downfalls;
}
/**
* @brief Returns the fixed downfall value at given coordinates.
*/
float FixedBiomeSource::getDownfall(int x, int z) const { return downfall; }
/**
* @brief Fills a double array with downfall values.
*/
void FixedBiomeSource::getDownfallBlock(doubleArray downfalls, int x, int z,
int w, int h) {
if (downfalls.data == NULL || downfalls.length < w * h) {
if (downfalls.data != NULL) delete[] downfalls.data;
if (!downfalls.data || downfalls.length < w * h) {
if (downfalls.data) delete[] downfalls.data;
downfalls = doubleArray(w * h);
}
Arrays::fill(downfalls, 0, w * h, (double)downfall);
Arrays::fill(downfalls, 0, w * h, static_cast<double>(downfall));
}
// 4J - caller is responsible for deleting biomes array, plus any optional
// arrays output if pointers are passed in (_temperatures, _downfalls)
/**
* @brief Fills a BiomeArray with the fixed biome for a region.
*/
void FixedBiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w,
int h, bool useCache) const {
MemSect(36);
biomes = BiomeArray(w * h);
MemSect(0);
Arrays::fill(biomes, 0, w * h, biome);
}
// 4J - caller is responsible for deleting biomes array, plus any optional
// arrays output if pointers are passed in (_temperatures, _downfalls)
/**
* @brief Fills a byteArray with the biome index for a region.
*/
void FixedBiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z,
int w, int h, bool useCache) const {
MemSect(36);
@ -90,21 +156,20 @@ void FixedBiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z,
Arrays::fill(biomeIndices, 0, w * h, biomeIndex);
}
// 4J-PB added in from beyond 1.8.2
// 4J - caller is responsible for deleting biomes array, plus any optional
// arrays output if pointers are passed in (_temperatures, _downfalls)
/**
* @brief Fills a BiomeArray with the fixed biome for a region (raw version).
*/
void FixedBiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w,
int h) const {
MemSect(36);
biomes = BiomeArray(w * h);
MemSect(0);
Arrays::fill(biomes, 0, w * h, biome);
}
// 4J-PB added in from beyond 1.8.2
// 4J - caller is responsible for deleting biomes array, plus any optional
// arrays output if pointers are passed in (_temperatures, _downfalls)
/**
* @brief Convenience overload returning a raw BiomeArray.
*/
BiomeArray FixedBiomeSource::getRawBiomeBlock(int x, int z, int w,
int h) const {
BiomeArray biomes;
@ -112,32 +177,42 @@ BiomeArray FixedBiomeSource::getRawBiomeBlock(int x, int z, int w,
return biomes;
}
/**
* @brief Finds a biome within a radius randomly.
*/
TilePos* FixedBiomeSource::findBiome(int x, int z, int r, Biome* toFind,
Random* random) {
if (toFind == biome) {
return new TilePos(x - r + random->nextInt(r * 2 + 1), 0,
z - r + random->nextInt(r * 2 + 1));
}
return NULL;
return nullptr;
}
/**
* @brief Finds a biome from a list of allowed biomes randomly.
*/
TilePos* FixedBiomeSource::findBiome(int x, int z, int r,
std::vector<Biome*> allowed,
const std::vector<Biome*>& allowed,
Random* random) {
if (find(allowed.begin(), allowed.end(), biome) != allowed.end()) {
return new TilePos(x - r + random->nextInt(r * 2 + 1), 0,
z - r + random->nextInt(r * 2 + 1));
}
return NULL;
return nullptr;
}
/**
* @brief Checks if the allowed biome matches the fixed biome.
*/
bool FixedBiomeSource::containsOnly(int x, int z, int r, Biome* allowed) {
return allowed == biome;
}
/**
* @brief Checks if the fixed biome is in the allowed list.
*/
bool FixedBiomeSource::containsOnly(int x, int z, int r,
std::vector<Biome*> allowed) {
const std::vector<Biome*>& allowed) {
return find(allowed.begin(), allowed.end(), biome) != allowed.end();
}
}