Skip to content

Commit

Permalink
Prevent the cursor from re-centering when switching between AE2 scree…
Browse files Browse the repository at this point in the history
…ns (#7735)
  • Loading branch information
shartte authored Mar 9, 2024
1 parent 0685fb2 commit 5e8d42e
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main/java/appeng/menu/implementations/MenuTypeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand Down Expand Up @@ -148,14 +147,30 @@ private boolean open(Player player, MenuHostLocator locator, boolean fromSubMenu

Component title = menuTitleStrategy.apply(accessInterface);

MenuProvider menu = new SimpleMenuProvider((wnd, p, pl) -> {
M m = factory.create(wnd, p, accessInterface);
// Set the original locator on the opened server-side menu for it to more
// easily remember how to re-open after being closed.
m.setLocator(locator);
return m;
}, title);
player.openMenu(menu, buffer -> {
class AppEngMenuProvider implements MenuProvider {
@Override
public Component getDisplayName() {
return title;
}

@Nullable
@Override
public AbstractContainerMenu createMenu(int wnd, Inventory p, Player pl) {
M m = factory.create(wnd, p, accessInterface);
// Set the original locator on the opened server-side menu for it to more
// easily remember how to re-open after being closed.
m.setLocator(locator);
return m;
}

@Override
public boolean shouldTriggerClientSideContainerClosingOnOpen() {
// Do not send close packets when switching between AE menus
return !(player.containerMenu instanceof AEBaseMenu);
}
}

player.openMenu(new AppEngMenuProvider(), buffer -> {
MenuLocators.writeToPacket(buffer, locator);
buffer.writeBoolean(fromSubMenu);
if (initialDataSerializer != null) {
Expand Down

0 comments on commit 5e8d42e

Please sign in to comment.