Interface BlockEntityProvider
- All Known Implementing Classes:
AbstractBannerBlock,AbstractChestBlock,AbstractFurnaceBlock,AbstractSignBlock,AbstractSkullBlock,BannerBlock,BarrelBlock,BeaconBlock,BedBlock,BeehiveBlock,BellBlock,BlastFurnaceBlock,BlockWithEntity,BrewingStandBlock,CampfireBlock,ChestBlock,ChiseledBookshelfBlock,CommandBlock,ComparatorBlock,ConduitBlock,DaylightDetectorBlock,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 cqmintermediary net/minecraft/class_2343named net/minecraft/block/BlockEntityProvider
-
Method Summary
Modifier and TypeMethodDescriptioncreateBlockEntity(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, ornullif 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, ornullif 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.PistonExtensionBlockis the only block in vanilla that returnsnullinside the implementation. - Mappings:
Namespace Name Mixin selector official aLcqm;a(Lgp;Ldab;)Lcxt;intermediary method_10123Lnet/minecraft/class_2343;method_10123(Lnet/minecraft/class_2338;Lnet/minecraft/class_2680;)Lnet/minecraft/class_2586;named createBlockEntityLnet/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, ornullif 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
typeis the one this block expects, and returnnullif it isn't. This is to prevent crashes in rare cases where a mismatch occurs between the position's block and block entity.BlockWithEntity.checkType(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
nullif the block entity does not need to be ticked - Mappings:
Namespace Name Mixin selector official aLcqm;a(Lcle;Ldab;Lcxv;)Lcxu;intermediary method_31645Lnet/minecraft/class_2343;method_31645(Lnet/minecraft/class_1937;Lnet/minecraft/class_2680;Lnet/minecraft/class_2591;)Lnet/minecraft/class_5558;named getTickerLnet/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, ornullif the block entity does not listen to game events.Listeners should validate that the passed
blockEntityis the block entity for this block, and returnnullif 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
nullif the block entity does not listen to game events - Mappings:
Namespace Name Mixin selector official aLcqm;a(Laid;Lcxt;)Ldem;intermediary method_32896Lnet/minecraft/class_2343;method_32896(Lnet/minecraft/class_3218;Lnet/minecraft/class_2586;)Lnet/minecraft/class_5714;named getGameEventListenerLnet/minecraft/block/BlockEntityProvider;getGameEventListener(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/block/entity/BlockEntity;)Lnet/minecraft/world/event/listener/GameEventListener;
-