Interface BlockEntityProvider
- All Known Implementing Classes:
AbstractBannerBlock
,AbstractChestBlock
,AbstractFurnaceBlock
,AbstractSignBlock
,AbstractSkullBlock
,BannerBlock
,BarrelBlock
,BeaconBlock
,BedBlock
,BeehiveBlock
,BellBlock
,BlastFurnaceBlock
,BlockWithEntity
,BrewingStandBlock
,BrushableBlock
,CalibratedSculkSensorBlock
,CampfireBlock
,ChestBlock
,ChiseledBookshelfBlock
,CommandBlock
,ComparatorBlock
,ConduitBlock
,DaylightDetectorBlock
,DecoratedPotBlock
,DispenserBlock
,DropperBlock
,EnchantingTableBlock
,EnderChestBlock
,EndGatewayBlock
,EndPortalBlock
,FurnaceBlock
,HangingSignBlock
,HopperBlock
,JigsawBlock
,JukeboxBlock
,LecternBlock
,PistonExtensionBlock
,PlayerSkullBlock
,SculkCatalystBlock
,SculkSensorBlock
,SculkShriekerBlock
,ShulkerBoxBlock
,SignBlock
,SkullBlock
,SmokerBlock
,SpawnerBlock
,StructureBlock
,TrappedChestBlock
,WallBannerBlock
,WallHangingSignBlock
,WallPiglinHeadBlock
,WallPlayerSkullBlock
,WallSignBlock
,WallSkullBlock
,WallWitherSkullBlock
,WitherSkullBlock
BlockEntity
. If a block has a corresponding block entity,
it must implement this interface. Multiple blocks can share a block entity type.
The createBlockEntity(net.minecraft.util.math.BlockPos, net.minecraft.block.BlockState)
method is responsible for creating an instance
of your block entity; no other code should instantiate it.
See the documentation of BlockEntity
for more information on what a
block entity is. See the documentation of BlockEntityType
for how to create a block entity type.
- See Also:
- Mappings:
Namespace Name official cvj
intermediary net/minecraft/class_2343
named net/minecraft/block/BlockEntityProvider
-
Method Summary
Modifier and TypeMethodDescription@Nullable BlockEntity
createBlockEntity
(BlockPos pos, BlockState state) Returns a new block entity instance.default <T extends BlockEntity>
@Nullable GameEventListenergetGameEventListener
(ServerWorld world, T blockEntity) Returns the game event listener for the block's block entity, ornull
if the block entity does not listen to game events.default <T extends BlockEntity>
@Nullable BlockEntityTicker<T>getTicker
(World world, BlockState state, BlockEntityType<T> type) Returns the "ticker" for the block's block entity, ornull
if the block entity does not need to be ticked.
-
Method Details
-
createBlockEntity
Returns a new block entity instance.For example:
@Override public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new MyBlockEntity(pos, state); }
- Returns:
- a new block entity instance
- Implementation Note:
- While this is marked as nullable, in practice this should never return
null
.PistonExtensionBlock
is the only block in vanilla that returnsnull
inside the implementation. - Mappings:
Namespace Name Mixin selector official a
Lcvj;a(Lgw;Ldfj;)Ldcv;
intermediary method_10123
Lnet/minecraft/class_2343;method_10123(Lnet/minecraft/class_2338;Lnet/minecraft/class_2680;)Lnet/minecraft/class_2586;
named createBlockEntity
Lnet/minecraft/block/BlockEntityProvider;createBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/entity/BlockEntity;
-
getTicker
@Nullable default <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) Returns the "ticker" for the block's block entity, ornull
if the block entity does not need to be ticked.Ticker is a functional interface called every tick to tick the block entity on both the client and the server.
Tickers should validate that the passed
type
is the one this block expects, and returnnull
if it isn't. This is to prevent crashes in rare cases where a mismatch occurs between the position's block and block entity.BlockWithEntity.validateTicker(net.minecraft.block.entity.BlockEntityType<A>, net.minecraft.block.entity.BlockEntityType<E>, net.minecraft.block.entity.BlockEntityTicker<? super E>)
can be used to implement the check.Example:
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { if (type != YourMod.MY_BLOCK_ENTITY_TYPE) return null; // This should be a static method usable as a BlockEntityTicker. return YourBlockEntity::tick; }
- Returns:
- the "ticker" for the block's block entity, or
null
if the block entity does not need to be ticked - Mappings:
Namespace Name Mixin selector official a
Lcvj;a(Lcpv;Ldfj;Ldcx;)Ldcw;
intermediary method_31645
Lnet/minecraft/class_2343;method_31645(Lnet/minecraft/class_1937;Lnet/minecraft/class_2680;Lnet/minecraft/class_2591;)Lnet/minecraft/class_5558;
named getTicker
Lnet/minecraft/block/BlockEntityProvider;getTicker(Lnet/minecraft/world/World;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/entity/BlockEntityType;)Lnet/minecraft/block/entity/BlockEntityTicker;
-
getGameEventListener
@Nullable default <T extends BlockEntity> @Nullable GameEventListener getGameEventListener(ServerWorld world, T blockEntity) Returns the game event listener for the block's block entity, ornull
if the block entity does not listen to game events.Listeners should validate that the passed
blockEntity
is the block entity for this block, and returnnull
if it isn't. This is to prevent crashes in rare cases where a mismatch occurs between the position's block and block entity.- Returns:
- the game event listener for the block's block entity,
or
null
if the block entity does not listen to game events - Mappings:
Namespace Name Mixin selector official a
Lcvj;a(Lakq;Ldcv;)Ldjv;
intermediary method_32896
Lnet/minecraft/class_2343;method_32896(Lnet/minecraft/class_3218;Lnet/minecraft/class_2586;)Lnet/minecraft/class_5714;
named getGameEventListener
Lnet/minecraft/block/BlockEntityProvider;getGameEventListener(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/block/entity/BlockEntity;)Lnet/minecraft/world/event/listener/GameEventListener;
-