Implementing banner
#1
I'm working on adding support for the banners. From what I understand, banner items have extra nbt data associated with them, containing information about the patterns and color. Currently I don't see how I can access this information, or can this be deduced from the meta flag?

Any insight on how to get the necessary info the create the block and blockentity would be great.


I already implemented most code for the item handler, blocks (wall and standing) and the entity. (by using the sign as an example) Also added the necessary networking code to send entity updates for the banners and currently looking on what to add to the chunk class and the chunk serializer.
Reply
Thanks given by: Jammet
#2
Hello, and welcome to the forum.

There's currently no extra storage associated with items. So far what we've done with other items (fireworks, to the best of my knowledge) is to simply add all the necessary fields directly into the cItem class.
Reply
Thanks given by: Jammet
#3
Hmm I think we need a more generic solution than to add extra fields to cItem for each item that has extra meta data. I'll experiment a bit with this myself.

Also, I just came across this code:
unique_ptr<class> ptr = make_unique<class>()

only to release it via release() on return. Doesn't this add more overhead as opposed to just make a heap allocation via 'new' and return the pointer?
Reply
Thanks given by: Jammet
#4
Wow, you're really implementing banners! :] I was just hoping someone would do that.
Reply
Thanks given by:
#5
Just an update, banners can now be placed but I only see them when reconnecting. I'm assuming I need to send an update to let the client know about the new banner. Looking at the other item handlers it must be something like this, but it doesn't work. Any pointers?

	virtual bool OnPlayerPlace(
		cWorld & a_World, cPlayer & a_Player, const cItem & a_EquippedItem,
		int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
		int a_CursorX, int a_CursorY, int a_CursorZ
	) override
	{
		// If the regular placement doesn't work, do no further processing:
		if (!super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
		{
			return false;
		}

		AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
		
		// Use a callback to set the properties of the banner entity
		class cCallback : public cBlockEntityCallback
		{
			cPlayer & m_Player;
			NIBBLETYPE m_BlockMeta;

			virtual bool Item(cBlockEntity * a_BlockEntity)
			{
				if (!(a_BlockEntity->GetBlockType() == E_BLOCK_STANDING_BANNER || a_BlockEntity->GetBlockType() == E_BLOCK_WALL_BANNER))
				{
					return false;
				}
				auto BannerEntity = static_cast<cBannerEntity *>(a_BlockEntity);

				//TODO base color and patterns

				BannerEntity->GetWorld()->BroadcastBlockEntity(BannerEntity->GetPosX(), BannerEntity->GetPosY(), BannerEntity->GetPosZ());
				//m_Player.GetClientHandle()->SendUpdateBlockEntity(*a_BlockEntity);
				return false;
			}

		public:
			cCallback(cPlayer & a_CBPlayer, NIBBLETYPE a_BlockMeta) :
				m_Player(a_CBPlayer),
				m_BlockMeta(a_BlockMeta)
			{}
		};
		cCallback Callback(a_Player, static_cast<NIBBLETYPE>(a_BlockFace));
		a_World.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback);

		return true;
	}
Reply
Thanks given by: Jammet
#6
I hope someone here knows the solution to that problem. Smile
Reply
Thanks given by:
#7
As for the unique_ptr question, I believe the code has other return paths that don't release the pointer, thus using its auto-delete feature.
Reply
Thanks given by:
#8
Yay! Got it working. Added a meta data storage system to cItem which reads/writes to/from NBT and JSON. Placement and data saving works (placed banners to chunks and items to json).

All that is left is adding the crafting recipes.
Reply
Thanks given by: Seadragon91
#9
I'm interested in the metadata storage system, what are you using for it?

Personally I'd probably go with Json::Value for a root value, which would be a dictionary of other values, as needed. Since there are plans to make the Json library available to plugins, it would mean the easiest bindings generation.
Reply
Thanks given by:
#10
Check https://github.com/cuberite/cuberite/com...age:banner

Item.h should give you a good idea. I made it as generic as possible.
Reply
Thanks given by:




Users browsing this thread: 14 Guest(s)