From 243083e01a4b6b496ca4c0ed0a4a33499cd41936 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Mon, 15 Mar 2021 03:47:55 +0100 Subject: Adding basic Banner functionality (#4806) + Added item and block for banners Co-authored-by: 12xx12 <12xx12100@gmail.com> Co-authored-by: Tiger Wang --- src/WorldStorage/WSSAnvil.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/WorldStorage/WSSAnvil.cpp') diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e2a9b1539..dae1ca825 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -19,6 +19,7 @@ #include "../BlockType.h" #include "../JsonUtils.h" +#include "../BlockEntities/BannerEntity.h" #include "../BlockEntities/BeaconEntity.h" #include "../BlockEntities/BedEntity.h" #include "../BlockEntities/BrewingstandEntity.h" @@ -635,7 +636,11 @@ OwnedBlockEntity cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int // Load the specific BlockEntity type: switch (a_BlockType) { - // Specific entity loaders: + // Banners: + case E_BLOCK_STANDING_BANNER: + case E_BLOCK_WALL_BANNER: return LoadBannerFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); + + // Others: case E_BLOCK_BEACON: return LoadBeaconFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); case E_BLOCK_BED: return LoadBedFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); case E_BLOCK_BREWING_STAND: return LoadBrewingstandFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); @@ -657,7 +662,6 @@ OwnedBlockEntity cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int case E_BLOCK_SIGN_POST: return LoadSignFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); case E_BLOCK_TRAPPED_CHEST: return LoadChestFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); case E_BLOCK_WALLSIGN: return LoadSignFromNBT (a_NBT, a_Tag, a_BlockType, a_BlockMeta, a_Pos); - default: { // All the other blocktypes should have no entities assigned to them. Report an error: @@ -889,6 +893,29 @@ bool cWSSAnvil::CheckBlockEntityType(const cParsedNBT & a_NBT, int a_TagIdx, con +OwnedBlockEntity cWSSAnvil::LoadBannerFromNBT(const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos) +{ + static const AStringVector expectedTypes({"Banner", "minecraft:standingbanner","minecraft:wallbanner"}); + if (!CheckBlockEntityType(a_NBT, a_TagIdx, expectedTypes, a_Pos)) + { + return nullptr; + } + + // Reads base color from NBT + int CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Base"); + if (CurrentLine >= 0) + { + const auto Color = static_cast(a_NBT.GetInt(CurrentLine)); + return std::make_unique(a_BlockType, a_BlockMeta, a_Pos, m_World, Color); + } + + return nullptr; +} + + + + + OwnedBlockEntity cWSSAnvil::LoadBeaconFromNBT(const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos) { // Check if the data has a proper type: -- cgit v1.2.3