Skip to content

InvMenu v4.3 Changelog and Migration Notes

Muqsit Rayyan edited this page Jun 9, 2021 · 5 revisions

InvMenu v4.3 Changelog

InvMenu v4.3 focuses on refactoring invmenu\metadata for the purpose of ease in registering custom InvMenu types and gaining more flexibility. The changes made in this version should not affect you if you are not registering custom InvMenu types.

Noticeable Changes

  • InvMenuHandler is no longer a MenuMetadata registry.
    To register custom InvMenu types, use InvMenuHandler::getRegistry()->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. As construction of these classes could seem complicated at first, builder patterns have been added for each implementation of InvMenuType.

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::getRegistry()->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::getRegistry()->register(self::TYPE_DISPENSER, InvMenuTypeBuilders::BLOCK_ACTOR_FIXED()
	->setBlock(BlockFactory::get(Block::DISPENSER))
	->setBlockActorId("Dispenser")
	->setSize(9)
	->setNetworkWindowType(WindowTypes::DISPENSER)
->build());
Clone this wiki locally