diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/Painting.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/Painting.cpp')
| -rw-r--r-- | Minecraft.World/Painting.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/Minecraft.World/Painting.cpp b/Minecraft.World/Painting.cpp new file mode 100644 index 00000000..0d8f35fe --- /dev/null +++ b/Minecraft.World/Painting.cpp @@ -0,0 +1,148 @@ +#include "stdafx.h" +#include "net.minecraft.world.phys.h" +#include "net.minecraft.world.entity.item.h" +#include "net.minecraft.world.item.h" +#include "net.minecraft.world.level.h" +#include "net.minecraft.world.level.material.h" +#include "net.minecraft.world.damagesource.h" +#include "com.mojang.nbt.h" +#include "Painting.h" +#include "Material.h" + + + +typedef Painting::Motive _Motive; +const _Motive *Painting::Motive::values[] = { + new _Motive(L"Kebab", 16, 16, 0 * 16, 0 * 16), + new _Motive(L"Aztec", 16, 16, 1 * 16, 0 * 16), // + new _Motive(L"Alban", 16, 16, 2 * 16, 0 * 16), // + new _Motive(L"Aztec2", 16, 16, 3 * 16, 0 * 16), // + new _Motive(L"Bomb", 16, 16, 4 * 16, 0 * 16), // + new _Motive(L"Plant", 16, 16, 5 * 16, 0 * 16), // + new _Motive(L"Wasteland", 16, 16, 6 * 16, 0 * 16), // + + new _Motive(L"Pool", 32, 16, 0 * 16, 2 * 16), // + new _Motive(L"Courbet", 32, 16, 2 * 16, 2 * 16), // + new _Motive(L"Sea", 32, 16, 4 * 16, 2 * 16), // + new _Motive(L"Sunset", 32, 16, 6 * 16, 2 * 16), // + new _Motive(L"Creebet", 32, 16, 8 * 16, 2 * 16), // + + new _Motive(L"Wanderer", 16, 32, 0 * 16, 4 * 16), // + new _Motive(L"Graham", 16, 32, 1 * 16, 4 * 16), // + + new _Motive(L"Match", 32, 32, 0 * 16, 8 * 16), // + new _Motive(L"Bust", 32, 32, 2 * 16, 8 * 16), // + new _Motive(L"Stage", 32, 32, 4 * 16, 8 * 16), // + new _Motive(L"Void", 32, 32, 6 * 16, 8 * 16), // + new _Motive(L"SkullAndRoses", 32, 32, 8 * 16, 8 * 16), // + new _Motive(L"Wither", 32, 32, 10 * 16, 8 * 16), + new _Motive(L"Fighters", 64, 32, 0 * 16, 6 * 16), // + + new _Motive(L"Pointer", 64, 64, 0 * 16, 12 * 16), // + new _Motive(L"Pigscene", 64, 64, 4 * 16, 12 * 16), // + new _Motive(L"BurningSkull", 64, 64, 8 * 16, 12 * 16), // + + new _Motive(L"Skeleton", 64, 48, 12 * 16, 4 * 16), // + new _Motive(L"DonkeyKong", 64, 48, 12 * 16, 7 * 16), // +}; + +// 4J Stu - Rather than creating a new string object here I am just using the +// actual number value of the characters in "SkullandRoses" which should be the +// longest name from the above +const int Painting::Motive::MAX_MOTIVE_NAME_LENGTH = 13; //JAVA: "SkullAndRoses".length(); + +// 4J - added for common ctor code +void Painting::_init( Level *level ) +{ + motive = NULL; +}; + +Painting::Painting(Level *level) : HangingEntity( level ) +{ + // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that + // the derived version of the function is called + this->defineSynchedData(); + + _init( level ); +} + +Painting::Painting(Level *level, int xTile, int yTile, int zTile, int dir) : HangingEntity( level , xTile, yTile, zTile, dir) +{ + _init(level); + + // 4J Stu - If you use this ctor, then you need to call the PaintingPostConstructor +} + +// 4J Stu - Added this so that we can use some shared_ptr functions that were needed in the ctor +void Painting::PaintingPostConstructor(int dir) +{ + vector<Motive *> *survivableMotives = new vector<Motive *>(); + for (int i = 0 ; i < LAST_VALUE; i++) + { + this->motive = (Motive *)Motive::values[i]; + setDir(dir); + if (survives()) + { + survivableMotives->push_back(this->motive); + } + } + if (!survivableMotives->empty()) + { + this->motive = survivableMotives->at(random->nextInt((int)survivableMotives->size())); + } + setDir(dir); +} + +Painting::Painting(Level *level, int x, int y, int z, int dir, wstring motiveName) : HangingEntity( level , x, y, z, dir ) +{ + _init(level); + + for (int i = 0 ; i < LAST_VALUE; i++) + { + if ( (Motive::values[i])->name.compare(motiveName) == 0) + { + this->motive = (Motive *)Motive::values[i]; + break; + } + } + setDir(dir); +} + +void Painting::addAdditonalSaveData(CompoundTag *tag) +{ + ///TODO Safe to cast to non-const type? + tag->putString(L"Motive", motive->name); + + HangingEntity::addAdditonalSaveData(tag); + } + +void Painting::readAdditionalSaveData(CompoundTag *tag) +{ + wstring motiveName = tag->getString(L"Motive"); + vector<Motive *>::iterator it; + for (int i = 0 ; i < LAST_VALUE; i++) + { + if ( Motive::values[i]->name.compare(motiveName) == 0) + { + this->motive = (Motive *)Motive::values[i]; + } + } + if (this->motive == NULL) motive = (Motive *)Motive::values[ Kebab ]; + + HangingEntity::readAdditionalSaveData(tag); +} + +int Painting::getWidth() +{ + return motive->w; +} + +int Painting::getHeight() +{ + return motive->h; +} + +void Painting::dropItem() +{ + spawnAtLocation(shared_ptr<ItemInstance>(new ItemInstance(Item::painting)), 0.0f); +}
\ No newline at end of file |
