feat: remove bonus chests

This commit is contained in:
str1k3r committed 2026-09-30 02:54:29 -04:00
1 parent 7272b62d38
commit ca003f1afa
30 files changed
+8 -246

No files matched your search

-88
View File
@@ -1,88 +0,0 @@
#include "stdafx.h"
#include "BonusChestFeature.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "WeighedTreasure.h"
#include "StructurePiece.h"
BonusChestFeature::BonusChestFeature(WeighedTreasureArray treasureList, int numRolls) : treasureList(treasureList), numRolls(numRolls)
{
}
// 4J - original virtual method
bool BonusChestFeature::place(Level *level, Random *random, int x, int y, int z)
{
return place(level, random, x, y, z, false );
}
// 4J - added force parameter - trying to keep this as similar as possible to the original algorithm, but would also like it to definitely place a
// chest as it doesn't necessarily find somewhere in the original java. This method is called multple times for different x,y,z round the
// spawn point and force signifies that this is the last time this will be called. In this case, just place the chest exactly where the input
// parameters requested we place it (we know this will be one tile above the top solid block of a randomn column), and then do our best to place
// any surrounding torches where appropriate.
bool BonusChestFeature::place(Level *level, Random *random, int x, int y, int z, bool force)
{
if( !force )
{
int t = 0;
while (((t = level->getTile(x, y, z)) == 0 || t == Tile::leaves_Id) && y > 1)
y--;
if (y < 1)
{
return false;
}
y++;
}
for (int i = 0; i < 4; i++)
{
int x2, y2, z2;
if( force )
{
x2 = x;
y2 = y - 1; // 4J - the position passed in is actually two above the top solid block, as the calling function adds 1 to getTopSolidBlock, and that actually returns the block above anyway.
// this would explain why there is a while loop above here (not used in force mode) to move the y back down again, shouldn't really be needed if 1 wasn't added to the getTopSolidBlock return value.
z2 = z;
}
else
{
x2 = x + random->nextInt(4) - random->nextInt(4);
y2 = y + random->nextInt(3) - random->nextInt(3);
z2 = z + random->nextInt(4) - random->nextInt(4);
}
if (force || ( level->isEmptyTile(x2, y2, z2) && level->isTopSolidBlocking(x2, y2 - 1, z2)))
{
level->setTile(x2, y2, z2, Tile::chest_Id);
shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(level->getTileEntity(x2, y2, z2));
if (chest != NULL)
{
WeighedTreasure::addChestItems(random, treasureList, chest, numRolls);
chest->isBonusChest = true; // 4J added
}
if (level->isEmptyTile(x2 - 1, y2, z2) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
{
level->setTile(x2 - 1, y2, z2, Tile::torch_Id);
}
if (level->isEmptyTile(x2 + 1, y2, z2) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
{
level->setTile(x2 + 1, y2, z2, Tile::torch_Id);
}
if (level->isEmptyTile(x2, y2, z2 - 1) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
{
level->setTile(x2, y2, z2 - 1, Tile::torch_Id);
}
if (level->isEmptyTile(x2, y2, z2 + 1) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
{
level->setTile(x2, y2, z2 + 1, Tile::torch_Id);
}
return true;
}
}
return false;
}
-19
View File
@@ -1,19 +0,0 @@
#pragma once
#include "Feature.h"
class Random;
class Level;
class BonusChestFeature : public Feature
{
private:
const WeighedTreasureArray treasureList;
const int numRolls;
public:
BonusChestFeature(WeighedTreasureArray treasureList, int numRolls);
virtual bool place(Level *level, Random *random, int x, int y, int z);
bool place(Level *level, Random *random, int x, int y, int z, bool force); // 4J added this method with extra force parameter
};
+1 -4
View File
@@ -13,12 +13,11 @@ using namespace std;
ChestTileEntity::ChestTileEntity(bool isBonusChest/* = false*/) : TileEntity()
ChestTileEntity::ChestTileEntity() : TileEntity()
{
items = new ItemInstanceArray(9 * 4);
hasCheckedNeighbors = false;
this->isBonusChest = isBonusChest;
openness = 0.0f;
oOpenness = 0.0f;
@@ -108,7 +107,6 @@ void ChestTileEntity::load(CompoundTag *base)
unsigned int slot = tag->getByte(L"Slot") & 0xff;
if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag);
}
isBonusChest = base->getBoolean(L"bonus");
}
void ChestTileEntity::save(CompoundTag *base)
@@ -127,7 +125,6 @@ void ChestTileEntity::save(CompoundTag *base)
}
}
base->put(L"Items", listTag);
base->putBoolean(L"bonus", isBonusChest);
}
int ChestTileEntity::getMaxStackSize()
+1 -2
View File
@@ -19,14 +19,13 @@ public:
using TileEntity::setChanged;
public:
ChestTileEntity(bool isBonusChest = false); // 4J added param
ChestTileEntity();
virtual ~ChestTileEntity();
private:
ItemInstanceArray *items;
public:
bool isBonusChest; // 4J added
bool hasCheckedNeighbors;
weak_ptr<ChestTileEntity> n;
weak_ptr<ChestTileEntity> e;
-9
View File
@@ -42,7 +42,6 @@ LevelData::LevelData(CompoundTag *tag)
{
generateMapFeatures = true;
}
spawnBonusChest = tag->getBoolean(L"spawnBonusChest");
xSpawn = tag->getInt(L"SpawnX");
ySpawn = tag->getInt(L"SpawnY");
@@ -144,7 +143,6 @@ LevelData::LevelData(LevelSettings *levelSettings, const wstring& levelName)
this->seed = levelSettings->getSeed();
this->gameType = levelSettings->getGameType();
this->generateMapFeatures = levelSettings->isGenerateMapFeatures();
this->spawnBonusChest = levelSettings->hasStartingBonusItems();
this->levelName = levelName;
this->m_pGenerator = levelSettings->getLevelType();
this->hardcore = levelSettings->isHardcore();
@@ -200,7 +198,6 @@ LevelData::LevelData(LevelData *copy)
this->m_pGenerator = copy->m_pGenerator;
this->gameType = copy->gameType;
this->generateMapFeatures = copy->generateMapFeatures;
this->spawnBonusChest = copy->spawnBonusChest;
this->xSpawn = copy->xSpawn;
this->ySpawn = copy->ySpawn;
this->zSpawn = copy->zSpawn;
@@ -256,7 +253,6 @@ void LevelData::setTagData(CompoundTag *tag)
tag->putInt(L"generatorVersion", m_pGenerator->getVersion());
tag->putInt(L"GameType", gameType->getId());
tag->putBoolean(L"MapFeatures", generateMapFeatures);
tag->putBoolean(L"spawnBonusChest",spawnBonusChest);
tag->putInt(L"SpawnX", xSpawn);
tag->putInt(L"SpawnY", ySpawn);
tag->putInt(L"SpawnZ", zSpawn);
@@ -515,11 +511,6 @@ bool LevelData::isGenerateMapFeatures()
return generateMapFeatures;
}
bool LevelData::getSpawnBonusChest()
{
return spawnBonusChest;
}
void LevelData::setGameType(GameType *gameType)
{
this->gameType = gameType;
-2
View File
@@ -36,7 +36,6 @@ private:
bool initialized;
bool newSeaLevel; // 4J added
bool hasBeenInCreative; // 4J added
bool spawnBonusChest; // 4J added
int m_xzSize; // 4J Added
int m_hellScale; // 4J Added
@@ -116,7 +115,6 @@ public:
virtual void setRainTime(int rainTime);
virtual GameType *getGameType();
virtual bool isGenerateMapFeatures();
virtual bool getSpawnBonusChest();
virtual void setGameType(GameType *gameType);
virtual bool useNewSeaLevel();
virtual bool getHasBeenInCreative(); // 4J Added
+1 -14
View File
@@ -94,7 +94,6 @@ void LevelSettings::_init(__int64 seed, GameType *gameType, bool generateMapFeat
this->newSeaLevel = newSeaLevel;
this->levelType = levelType;
this->allowCommands = false;
this->startingBonusItems = false;
m_xzSize = xzSize;
m_hellScale = hellScale;
}
@@ -105,8 +104,7 @@ LevelSettings::LevelSettings(__int64 seed, GameType *gameType, bool generateMapF
hardcore(hardcore),
generateMapFeatures(generateMapFeatures),
newSeaLevel(newSeaLevel),
levelType(levelType),
startingBonusItems(false)
levelType(levelType)
{
_init(seed, gameType, generateMapFeatures, hardcore, newSeaLevel, levelType, xzSize, hellScale);
}
@@ -116,23 +114,12 @@ LevelSettings::LevelSettings(LevelData *levelData)
_init(levelData->getSeed(), levelData->getGameType(), levelData->isGenerateMapFeatures(), levelData->isHardcore(), levelData->useNewSeaLevel(), levelData->getGenerator(), levelData->getXZSize(), levelData->getHellScale() );
}
LevelSettings *LevelSettings::enableStartingBonusItems()
{
startingBonusItems = true;
return this;
}
LevelSettings *LevelSettings::enableSinglePlayerCommands()
{
allowCommands = true;
return this;
}
bool LevelSettings::hasStartingBonusItems()
{
return startingBonusItems;
}
__int64 LevelSettings::getSeed()
{
return seed;
-3
View File
@@ -42,7 +42,6 @@ private:
bool newSeaLevel;
LevelType *levelType;
bool allowCommands;
bool startingBonusItems; // 4J - brought forward from 1.3.2
int m_xzSize; // 4J Added
int m_hellScale;
@@ -51,9 +50,7 @@ private:
public:
LevelSettings(__int64 seed, GameType *gameType, bool generateMapFeatures, bool hardcore, bool newSeaLevel, LevelType *levelType, int xzSize, int hellScale); // 4J Added xzSize and hellScale param
LevelSettings(LevelData *levelData);
LevelSettings *enableStartingBonusItems(); // 4J - brought forward from 1.3.2
LevelSettings *enableSinglePlayerCommands();
bool hasStartingBonusItems(); // 4J - brought forward from 1.3.2
__int64 getSeed();
GameType *getGameType();
bool isHardcore();
-2
View File
@@ -1887,7 +1887,6 @@
<ClInclude Include="Boat.h" />
<ClInclude Include="BoatItem.h" />
<ClInclude Include="BodyControl.h" />
<ClInclude Include="BonusChestFeature.h" />
<ClInclude Include="BookItem.h" />
<ClInclude Include="BookshelfTile.h" />
<ClInclude Include="BossMob.h" />
@@ -2808,7 +2807,6 @@
<ClCompile Include="Boat.cpp" />
<ClCompile Include="BoatItem.cpp" />
<ClCompile Include="BodyControl.cpp" />
<ClCompile Include="BonusChestFeature.cpp" />
<ClCompile Include="BookItem.cpp" />
<ClCompile Include="BookshelfTile.cpp" />
<ClCompile Include="BossMob.cpp" />
@@ -1924,9 +1924,6 @@
<ClInclude Include="HellFlatLevelSource.h">
<Filter>net\minecraft\world\level\levelgen</Filter>
</ClInclude>
<ClInclude Include="BonusChestFeature.h">
<Filter>net\minecraft\world\level\levelgen\feature</Filter>
</ClInclude>
<ClInclude Include="StoneMonsterTileItem.h">
<Filter>net\minecraft\world\item</Filter>
</ClInclude>
@@ -4164,9 +4161,6 @@
<ClCompile Include="HellFlatLevelSource.cpp">
<Filter>net\minecraft\world\level\levelgen</Filter>
</ClCompile>
<ClCompile Include="BonusChestFeature.cpp">
<Filter>net\minecraft\world\level\levelgen\feature</Filter>
</ClCompile>
<ClCompile Include="StoneMonsterTileItem.cpp">
<Filter>net\minecraft\world\item</Filter>
</ClCompile>
@@ -27,7 +27,6 @@
#include "HugeMushroomFeature.h"
#include "SandFeature.h"
#include "SwampTreeFeature.h"
#include "BonusChestFeature.h"
#include "SpikeFeature.h"
#include "EndPodiumFeature.h"