IF icon indicating copy to clipboard operation
IF copied to clipboard

How to update without reopening

Open Gorayan opened this issue 3 years ago • 1 comments

I would like a way to update items without reopening inventory.

When the update function is called, HumanEntity reopens the inventory. However, this has the following problems.

Problems

  • If a player closes their inventory at about the same time as the update, it will re-open on the client side
  • Flickering occurs the moment I refresh

These problems become more pronounced when creating UIs that require frequent updates(every ticks), such as timers

  public void update() {
      updating = true;

      for (HumanEntity viewer : getViewers()) {
          ItemStack cursor = viewer.getItemOnCursor();
          viewer.setItemOnCursor(new ItemStack(Material.AIR));

          show(viewer);  // <-Here

          viewer.setItemOnCursor(cursor);
      }

      if (!updating)
          throw new AssertionError("Gui#isUpdating became false before Gui#update finished");

      updating = false;
  }

Gorayan avatar Apr 11 '22 14:04 Gorayan