Skip to content

InvMenu v4.3 Changelog and Migration Notes

Muqsit Rayyan edited this page Jun 19, 2022 · 5 revisions

InvMenu v4.3 Changelog

InvMenu v4.3 focuses on refactoring of invmenu\metadata to make registering custom InvMenu types simpler, and gaining more flexibility when dealing with sending graphic portion of an InvMenu type. If you are not registering custom InvMenu types, the changes made in this version will not affect you.

Noticeable Changes

  • InvMenuHandler is no longer a MenuMetadata registry.
    To register custom InvMenu types, use InvMenuHandler::getTypeRegistry()->register() instead.
  • MenuMetadata has been replaced with InvMenuType
    Unlike what MenuMetadata was, InvMenuType is block-agnostic as not all inventories may be backed by a block.
    By default, InvMenu comes with three implementations of InvMenuTypeBlockFixedInvMenuType, BlockActorFixedInvMenuType and DoublePairableBlockActorFixedInvMenuType. Constructing these classes may be quite complicated, however each of the three implementations of InvMenuTypes can be instantiated using built-in builder patterns.

Other Changes

  • InvMenu::getType() now returns InvMenuType rather than MenuMetadata
  • InvMenu::getInventory() now returns Inventory rather than InvMenuInventory

Migrating from InvMenu <= v4.2.x to InvMenu v4.3.0

To register a custom InvMenu type, use InvMenuHandler::getTypeRegistry()->register() instead.
While you can still create custom implementations of InvMenuType, the built-in InvMenuTypes can be instantiated using builder patterns specified in InvMenuTypeBuilders.

// InvMenu <= v4.2.x
$type = new SingleBlockMenuMetadata(
	self::TYPE_DISPENSER, // identifier
	9, // number of slots
	WindowTypes::DISPENSER, // mcpe window type id
	BlockFactory::get(Block::DISPENSER), // Block
	"Dispenser" // block entity identifier
);
InvMenuHandler::registerMenuType($type);

// InvMenu v4.3.0
InvMenuHandler::getTypeRegistry()->register(self::TYPE_DISPENSER, InvMenuTypeBuilders::BLOCK_ACTOR_FIXED()
	->setBlock(BlockFactory::getInstance()->get(BlockLegacyIds::DISPENSER, 0))
	->setBlockActorId("Dispenser")
	->setSize(9)
	->setNetworkWindowType(WindowTypes::DISPENSER)
->build());