Class BlockWithEntity

All Implemented Interfaces:
BlockEntityProvider, ItemConvertible, ToggleableFeature
Direct Known Subclasses:
AbstractBannerBlock, AbstractChestBlock, AbstractFurnaceBlock, AbstractSignBlock, AbstractSkullBlock, BarrelBlock, BeaconBlock, BeehiveBlock, BellBlock, BrewingStandBlock, BrushableBlock, CampfireBlock, ChiseledBookshelfBlock, CommandBlock, ConduitBlock, CrafterBlock, DaylightDetectorBlock, DecoratedPotBlock, DispenserBlock, EnchantingTableBlock, EndGatewayBlock, EndPortalBlock, HopperBlock, JukeboxBlock, LecternBlock, PistonExtensionBlock, SculkCatalystBlock, SculkSensorBlock, SculkShriekerBlock, ShulkerBoxBlock, SpawnerBlock, StructureBlock, TrialSpawnerBlock

public abstract class BlockWithEntity extends Block implements BlockEntityProvider
A convenience class for a block with a BlockEntity. While blocks with block entity only have to implement BlockEntityProvider and do not have to subclass this, it overrides several methods to delegate its logic to the block entity. However, it is generally easier to just implement BlockEntityProvider.

Subclasses must override getRenderType(net.minecraft.block.BlockState) to render the block entity. By default, all block entities are rendered invisible, which is not intended in most, if not all, cases.

See Also:
Mappings:
Namespace Name
official cwc
intermediary net/minecraft/class_2237
named net/minecraft/block/BlockWithEntity
  • Constructor Details

    • BlockWithEntity

      protected BlockWithEntity(AbstractBlock.Settings settings)
      Mappings:
      Namespace Name Mixin selector
      official <init> Ldjg;<init>(Ldjg$d;)V
      intermediary <init> Lnet/minecraft/class_4970;<init>(Lnet/minecraft/class_4970$class_2251;)V
      named <init> Lnet/minecraft/block/AbstractBlock;<init>(Lnet/minecraft/block/AbstractBlock$Settings;)V
  • Method Details

    • getCodec

      protected abstract com.mojang.serialization.MapCodec<? extends BlockWithEntity> getCodec()
      Overrides:
      getCodec in class Block
      Mappings:
      Namespace Name Mixin selector
      official a Ldjg;a()Lcom/mojang/serialization/MapCodec;
      intermediary method_53969 Lnet/minecraft/class_4970;method_53969()Lcom/mojang/serialization/MapCodec;
      named getCodec Lnet/minecraft/block/AbstractBlock;getCodec()Lcom/mojang/serialization/MapCodec;
    • getRenderType

      public BlockRenderType getRenderType(BlockState state)
      Returns the block's render type (invisible, animated, model).
      Overrides:
      getRenderType in class AbstractBlock
      Returns:
      the block's render type (invisible, animated, model)
      Mappings:
      Namespace Name Mixin selector
      official b_ Ldjg;b_(Ldjh;)Ldcv;
      intermediary method_9604 Lnet/minecraft/class_4970;method_9604(Lnet/minecraft/class_2680;)Lnet/minecraft/class_2464;
      named getRenderType Lnet/minecraft/block/AbstractBlock;getRenderType(Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockRenderType;
    • onSyncedBlockEvent

      public boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data)
      Handles the block event, which is an event specific to a block with an integer ID and data.
      Overrides:
      onSyncedBlockEvent in class AbstractBlock
      Returns:
      whether the event was handled successfully
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Ldjg;a(Ldjh;Lctp;Lhx;II)Z
      intermediary method_9592 Lnet/minecraft/class_4970;method_9592(Lnet/minecraft/class_2680;Lnet/minecraft/class_1937;Lnet/minecraft/class_2338;II)Z
      named onSyncedBlockEvent Lnet/minecraft/block/AbstractBlock;onSyncedBlockEvent(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;II)Z
    • createScreenHandlerFactory

      @Nullable public @Nullable NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos)
      Returns the screen handler factory or null if screen handler cannot be created.

      This method should be overridden for blocks with screen handlers, such as anvils. The created screen handler is usually passed to PlayerEntity.openHandledScreen(net.minecraft.screen.NamedScreenHandlerFactory). See AnvilBlock.createScreenHandlerFactory(net.minecraft.block.BlockState, net.minecraft.world.World, net.minecraft.util.math.BlockPos) for basic usage. BlockWithEntity delegates this logic to the block entity implementing NamedScreenHandlerFactory. For example, any BlockWithEntity whose block entity extends LockableContainerBlockEntity needs to override LockableContainerBlockEntity.createScreenHandler(int, net.minecraft.entity.player.PlayerInventory) instead of this method.

      This method is called on both the logical client and logical server, so take caution when overriding this method. The logical side can be checked using World.isClient.

      Overrides:
      createScreenHandlerFactory in class AbstractBlock
      Returns:
      the screen handler factory or null if screen handler cannot be created
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official b Ldjg;b(Ldjh;Lctp;Lhx;)Lbke;
      intermediary method_17454 Lnet/minecraft/class_4970;method_17454(Lnet/minecraft/class_2680;Lnet/minecraft/class_1937;Lnet/minecraft/class_2338;)Lnet/minecraft/class_3908;
      named createScreenHandlerFactory Lnet/minecraft/block/AbstractBlock;createScreenHandlerFactory(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/screen/NamedScreenHandlerFactory;
    • validateTicker

      @Nullable protected static <E extends BlockEntity, A extends BlockEntity> @Nullable BlockEntityTicker<A> validateTicker(BlockEntityType<A> givenType, BlockEntityType<E> expectedType, BlockEntityTicker<? super E> ticker)
      Returns the ticker if the given type and expected type are the same, or null if they are different.
      Returns:
      the ticker if the given type and expected type are the same, or null if they are different
      Mappings:
      Namespace Name Mixin selector
      official a Lcwc;a(Ldgx;Ldgx;Ldgw;)Ldgw;
      intermediary method_31618 Lnet/minecraft/class_2237;method_31618(Lnet/minecraft/class_2591;Lnet/minecraft/class_2591;Lnet/minecraft/class_5558;)Lnet/minecraft/class_5558;
      named validateTicker Lnet/minecraft/block/BlockWithEntity;validateTicker(Lnet/minecraft/block/entity/BlockEntityType;Lnet/minecraft/block/entity/BlockEntityType;Lnet/minecraft/block/entity/BlockEntityTicker;)Lnet/minecraft/block/entity/BlockEntityTicker;