Interface EntityBlockProvider

All Superinterfaces:
net.minecraft.world.level.block.EntityBlock
All Known Implementing Classes:
UEntityBlock

public interface EntityBlockProvider extends net.minecraft.world.level.block.EntityBlock
Provides a convenience way to implement block entities for blocks.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.world.level.block.entity.BlockEntityType<?>
    blockEntityType(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
    Returns the BlockEntityType that is used for creating the BlockEntity when newBlockEntity(BlockPos, BlockState) is invoked.
    default <T extends net.minecraft.world.level.block.entity.BlockEntity>
    Optional<T>
    getBlockEntity(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos)
    Returns a optional with can contain the BlockEntity at that give position if the BlockEntityType is correct.
    default net.minecraft.world.level.block.entity.BlockEntity
    newBlockEntity(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
    Returns a new BlockEntity for the give BlockPos and BlockState.
    default net.minecraft.world.InteractionResult
    openMenu(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
    Opens the menu that is specified in the block entity with MenuConstructor.
    default net.minecraft.world.InteractionResult
    openMenu(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player, boolean canOpenWhenSecondaryUse)
    Opens the menu that is specified in the block entity with MenuConstructor.

    Methods inherited from interface net.minecraft.world.level.block.EntityBlock

    getListener, getTicker
  • Method Details

    • blockEntityType

      @Nullable net.minecraft.world.level.block.entity.BlockEntityType<?> blockEntityType(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
      Returns the BlockEntityType that is used for creating the BlockEntity when newBlockEntity(BlockPos, BlockState) is invoked. Can return null if for the current state or position no block entity should be created.
      Parameters:
      pos - Position of the block
      state - Block state
    • newBlockEntity

      @Nullable default net.minecraft.world.level.block.entity.BlockEntity newBlockEntity(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
      Returns a new BlockEntity for the give BlockPos and BlockState.
      The default implementation creates a new BlockEntity by using the blockEntityType(BlockPos, BlockState) method and invoke BlockEntityType.create(BlockPos, BlockState) Can return null if no block entity should be created for that position or state.
      Specified by:
      newBlockEntity in interface net.minecraft.world.level.block.EntityBlock
      Parameters:
      pos - Position of the block
      state - Block state
    • getBlockEntity

      default <T extends net.minecraft.world.level.block.entity.BlockEntity> Optional<T> getBlockEntity(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos)
      Returns a optional with can contain the BlockEntity at that give position if the BlockEntityType is correct. Otherwise returns an empty optional.
      Type Parameters:
      T - Block entity
      Parameters:
      level - Level
      pos - Position of the block
      Returns:
      Optional with the block entity
    • openMenu

      default net.minecraft.world.InteractionResult openMenu(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
      Opens the menu that is specified in the block entity with MenuConstructor. If the block entity implements MenuSyncedBlockEntity then the MenuSyncedBlockEntity.sendInitialMenuDataToClient(FriendlyByteBuf) is called and the data will be send to the client. The container cannot be opened when secondary use is active.
      Parameters:
      level - Level
      pos - The block entities position
      player - The player that opens the block entity
      Returns:
      InteractionResult if the container could be opened
    • openMenu

      default net.minecraft.world.InteractionResult openMenu(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player, boolean canOpenWhenSecondaryUse)
      Opens the menu that is specified in the block entity with MenuConstructor. If the block entity implements MenuSyncedBlockEntity then the MenuSyncedBlockEntity.sendInitialMenuDataToClient(FriendlyByteBuf) is called and the data will be send to the client.
      Parameters:
      level - Level
      pos - The block entities position
      player - The player that opens the block entity
      canOpenWhenSecondaryUse - If the container can be opened when secondary use is active
      Returns:
      InteractionResult if the container could be opened