Class UContainerMenu

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
Direct Known Subclasses:
UBlockEntityContainerMenu

public abstract class UContainerMenu extends FluidContainerMenu
A basic menu with synchronization capabilities that implements the FluidContainerMenu.
  • Constructor Details

    • UContainerMenu

      protected UContainerMenu(net.minecraft.world.inventory.MenuType<?> menuType, int containerId)
      Creates a new container. Must be implemented by a sub class to be used.
      Parameters:
      menuType - Menu type
      containerId - Container id
  • Method Details

    • stillValid

      public boolean stillValid(net.minecraft.world.entity.player.Player player)
      Default player interaction with this container to true
      Specified by:
      stillValid in class net.minecraft.world.inventory.AbstractContainerMenu
    • addDataHolderToClient

      protected <E extends DataHolder> E addDataHolderToClient(E holder)
      Adds a new DataHolder that will automatically synchronize values from the server to the client.
      Parameters:
      holder - Data holder
      Returns:
      The supplied data holder
    • addDataHolderToServer

      protected <E extends DataHolder> E addDataHolderToServer(E holder)
      Adds a new DataHolder that will synchronize values from the client to the server.

      To synchronize values automatically the screen must implement UContainerMenuScreen. If not you must manually call broadcastChangesToServer() every time you update values on the client that should be synchronized to the server.
      Parameters:
      holder - Data holder
      Returns:
      The supplied data holder
    • sendAllDataToRemote

      public void sendAllDataToRemote()
      Sends all menu data to the client.
      Overrides:
      sendAllDataToRemote in class FluidContainerMenu
    • broadcastChanges

      public void broadcastChanges()
      Broadcast changed data
      Overrides:
      broadcastChanges in class FluidContainerMenu
    • broadcastChangesToServer

      public void broadcastChangesToServer()
      Broadcast data from the client to the server if changed. Needs to be called everytime you want to send changed data from the client to the server. Will be called automatically every tick if the screens base class is UContainerMenuScreen.
      See Also:
    • setDataHolder

      public final void setDataHolder(net.minecraftforge.fml.LogicalSide side, int index, net.minecraft.network.FriendlyByteBuf dataHolderBuffer)
      Called by the packet handler to update the values on the right side.
      Parameters:
      side - Side that should set the values
      index - Index of the data holder in the list
      dataHolderBuffer - The buffer that should be set