Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect inventory sent when replacing an existing chest | PMMP 4.18 #207

Closed
Nat392 opened this issue Mar 30, 2023 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@Nat392
Copy link

Nat392 commented Mar 30, 2023

Hello, I have a bug with your code and PMMP v.4.18

RPReplay_Final1680089941.mov
RPReplay_Final1680089970.mov
@Muqsit
Copy link
Owner

Muqsit commented Mar 31, 2023

Hi, can you explain what the bug is and what the video demonstrates?

@Nat392
Copy link
Author

Nat392 commented Mar 31, 2023

When you try to open a GUI, if a chest is nearby, the interface that opens is "bug". The video shows a player trying to open a GUI by tapping on a minion, he gets a double empty chest, but by pressing the slots, the real interface appears.

@Nat392
Copy link
Author

Nat392 commented Mar 31, 2023

image

Or a member who opens an enderchest with the command /ec, and the open interface is a double chest.

@Nat392
Copy link
Author

Nat392 commented Mar 31, 2023

Look the video

2023-03-31.15-26-42.mp4

@Nat392
Copy link
Author

Nat392 commented Apr 2, 2023

Hello @Muqsit , any news ?

@Muqsit
Copy link
Owner

Muqsit commented Apr 9, 2023

I have been able to reproduce this bug on my end, but due to time constraints I am unable to work on a nice way to address it.
A simple workaround to this bug is to set the block left and right of the chest to air while the player has the chest open. This can be done by overriding InvMenu::TYPE_CHEST during plugin enable:

protected function onEnable() : void{
	if(!InvMenuHandler::isRegistered()){
		InvMenuHandler::register($this);
	}

+	$registry = InvMenuHandler::getTypeRegistry();
+	$registry->register(InvMenu::TYPE_CHEST, new class($registry->get(InvMenu::TYPE_CHEST)) implements InvMenuType{
+		public function __construct(
+			private InvMenuType $inner
+		){}

+		public function createGraphic(InvMenu $menu, Player $player) : ?InvMenuGraphic{
+			$parent = $this->inner->createGraphic($menu, $player);
+			if(!($parent instanceof PositionedInvMenuGraphic)){
+				return null;
+			}

+			// Workaround for https://github.com/Muqsit/InvMenu/issues/207
+			// Set block at east and west of InvMenu::TYPE_CHEST to air.
+			$pos = $parent->getPosition();
+			return new MultiBlockInvMenuGraphic([
+				$parent,
+				new BlockInvMenuGraphic(VanillaBlocks::AIR(), $pos->east(), null, 0),
+				new BlockInvMenuGraphic(VanillaBlocks::AIR(), $pos->west(), null, 0)
+			]);
+		}

+		public function createInventory() : Inventory{
+			return $this->inner->createInventory();
+		}
+	});
}

An example script plugin using this workaround is listed here: https://gist.github.com/Muqsit/18400e53b132d166f13189e7f316658e

@Muqsit Muqsit added the bug Something isn't working label Apr 9, 2023
@Muqsit Muqsit changed the title Bug | PMMP 4.18 Incorrect inventory sent when replacing an existing chest | PMMP 4.18 Apr 9, 2023
@Nat392
Copy link
Author

Nat392 commented Apr 11, 2023

I tried this workaround but it didn't work, the bug still occurs.

@Jack10270
Copy link

The workaround fixes it but my suggestion is this method:- if a block already exists find another spot to set the block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants