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, CrafterBlock, 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, TrialSpawnerBlock, VaultBlock, WallBannerBlock, WallHangingSignBlock, WallPiglinHeadBlock, WallPlayerSkullBlock, WallSignBlock, WallSkullBlock, WallWitherSkullBlock, WitherSkullBlock

public interface BlockEntityProvider
A block with a 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
named net/minecraft/block/BlockEntityProvider
intermediary net/minecraft/class_2343
official dia
  • Method Details

    • createBlockEntity

      @Nullable @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state)
      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 returns null inside the implementation.
      Mappings:
      Namespace Name Mixin selector
      named createBlockEntity Lnet/minecraft/block/BlockEntityProvider;createBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/entity/BlockEntity;
      intermediary method_10123 Lnet/minecraft/class_2343;method_10123(Lnet/minecraft/class_2338;Lnet/minecraft/class_2680;)Lnet/minecraft/class_2586;
      official a Ldia;a(Lja;Ldsl;)Ldpq;
    • 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, or null 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 return null 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
      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;
      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;
      official a Ldia;a(Ldcg;Ldsl;Ldps;)Ldpr;
    • getGameEventListener

      @Nullable default <T extends BlockEntity> @Nullable GameEventListener getGameEventListener(ServerWorld world, T blockEntity)
      Returns the game event listener for the block's block entity, or null 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 return null 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
      named getGameEventListener Lnet/minecraft/block/BlockEntityProvider;getGameEventListener(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/block/entity/BlockEntity;)Lnet/minecraft/world/event/listener/GameEventListener;
      intermediary method_32896 Lnet/minecraft/class_2343;method_32896(Lnet/minecraft/class_3218;Lnet/minecraft/class_2586;)Lnet/minecraft/class_5714;
      official a Ldia;a(Laqm;Ldpq;)Ldxj;