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 TypeMethodDescriptionnet.minecraft.world.level.block.entity.BlockEntityType<?>
blockEntityType
(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) Returns theBlockEntityType
that is used for creating theBlockEntity
whennewBlockEntity(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 theBlockEntity
at that give position if theBlockEntityType
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 newBlockEntity
for the giveBlockPos
andBlockState
.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 withMenuConstructor
.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 withMenuConstructor
.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 theBlockEntityType
that is used for creating theBlockEntity
whennewBlockEntity(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 blockstate
- 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 newBlockEntity
for the giveBlockPos
andBlockState
.
The default implementation creates a newBlockEntity
by using theblockEntityType(BlockPos, BlockState)
method and invokeBlockEntityType.create(BlockPos, BlockState)
Can return null if no block entity should be created for that position or state.- Specified by:
newBlockEntity
in interfacenet.minecraft.world.level.block.EntityBlock
- Parameters:
pos
- Position of the blockstate
- 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 theBlockEntity
at that give position if theBlockEntityType
is correct. Otherwise returns an empty optional.- Type Parameters:
T
- Block entity- Parameters:
level
- Levelpos
- 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 withMenuConstructor
. If the block entity implementsMenuSyncedBlockEntity
then theMenuSyncedBlockEntity.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
- Levelpos
- The block entities positionplayer
- 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 withMenuConstructor
. If the block entity implementsMenuSyncedBlockEntity
then theMenuSyncedBlockEntity.sendInitialMenuDataToClient(FriendlyByteBuf)
is called and the data will be send to the client.- Parameters:
level
- Levelpos
- The block entities positionplayer
- The player that opens the block entitycanOpenWhenSecondaryUse
- If the container can be opened when secondary use is active- Returns:
InteractionResult
if the container could be opened
-