Level::BlockPalettePtr replace Level::BlockPalette

This commit is contained in:
Qiuzhizhe 2023-02-09 23:03:14 -08:00
parent bcd2a1f717
commit 67688fe8e7
5 changed files with 18 additions and 7 deletions

View File

@ -4,13 +4,20 @@
#include "../Global.h" #include "../Global.h"
#define BEFORE_EXTRA #define BEFORE_EXTRA
class BlockLegacy;
#include <MC/Bedrock.hpp>
#undef BEFORE_EXTRA #undef BEFORE_EXTRA
class BlockPalette { class BlockPalette {
#define AFTER_EXTRA #define AFTER_EXTRA
public:
std::mutex mLegacyBlockStatesConversionWarningMutex;
std::set<std::pair<int,int>> mLegacyBlockStatesConversionWarningSet;
std::map<std::string,BlockLegacy const*> mNameLookup;
std::map<CompoundTag,Block const*>mBlockFromSerId;
std::vector<Block const*>mBlockFromRuntimeId;
Level *mLevel;
#undef AFTER_EXTRA #undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_BLOCKPALETTE #ifndef DISABLE_CONSTRUCTOR_PREVENTION_BLOCKPALETTE
public: public:

View File

@ -83,7 +83,7 @@ public:
//Helper //Helper
LIAPI static BlockSource* getBlockSource(int dimid); LIAPI static BlockSource* getBlockSource(int dimid);
LIAPI static BlockSource* getBlockSource(Actor* actor); LIAPI static BlockSource* getBlockSource(Actor* actor);
//LIAPI static BlockPalette* getBlockPalette(); LIAPI static BlockPalette* getBlockPalettePtr();
//LIAPI static Dimension* getDimension(class AutomaticID<class Dimension, int> a0); //LIAPI static Dimension* getDimension(class AutomaticID<class Dimension, int> a0);
LIAPI static Actor* getDamageSourceEntity(ActorDamageSource* ads); LIAPI static Actor* getDamageSourceEntity(ActorDamageSource* ads);
LIAPI static void broadcastText(const string& text, TextType type); LIAPI static void broadcastText(const string& text, TextType type);

View File

@ -9,8 +9,8 @@
#include <MC/Level.hpp> #include <MC/Level.hpp>
Block* Block::create(const string& name, unsigned short tileData) { Block* Block::create(const string& name, unsigned short tileData) {
BlockPalette& generator = Global<Level>->getBlockPalette(); BlockPalette* generator = Global<Level>->getBlockPalettePtr();
auto blk = generator.getBlockLegacy(name); auto blk = generator->getBlockLegacy(name);
if (!blk) if (!blk)
return nullptr; return nullptr;
return (Block*)((BlockLegacy*)blk)->toBlock(tileData); return (Block*)((BlockLegacy*)blk)->toBlock(tileData);

View File

@ -62,6 +62,10 @@ Block* Level::getBlock(const BlockPos& pos, BlockSource* blockSource) {
return (Block*)&(blockSource->getBlock(pos)); return (Block*)&(blockSource->getBlock(pos));
} }
BlockPalette* Level::getBlockPalettePtr(){
// MovingBlockActor::load Line69
return dAccess<BlockPalette*>(Global<Level>,2000);
};
// Return nullptr when failing to get block // Return nullptr when failing to get block
Block* Level::getBlockEx(const BlockPos& pos, int dimId) { Block* Level::getBlockEx(const BlockPos& pos, int dimId) {

View File

@ -41,13 +41,13 @@
#include <MC/BlockPalette.hpp> #include <MC/BlockPalette.hpp>
bool StructureTemplate::toWorld(int dimID, BlockPos const& p1, Mirror mirror, Rotation rotation) { bool StructureTemplate::toWorld(int dimID, BlockPos const& p1, Mirror mirror, Rotation rotation) {
auto& palette = Global<Level>->getBlockPalette(); auto palette = Global<Level>->getBlockPalettePtr();
auto bs = Level::getBlockSource(dimID); auto bs = Level::getBlockSource(dimID);
auto setting = StructureSettings(); auto setting = StructureSettings();
setting.setMirror(mirror); setting.setMirror(mirror);
setting.setStructureSize(getSize()); setting.setStructureSize(getSize());
setting.setRotation(rotation); setting.setRotation(rotation);
placeInWorld(*bs, palette, p1, setting, nullptr, false); placeInWorld(*bs, *palette, p1, setting, nullptr, false);
return true; return true;
}; };