Package net.neoforged.neoforge.event
Class BlockEntityTypeAddBlocksEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.BlockEntityTypeAddBlocksEvent
- All Implemented Interfaces:
IModBusEvent
public class BlockEntityTypeAddBlocksEvent
extends net.neoforged.bus.api.Event
implements IModBusEvent
Allows injecting new blocks into a block entity's
BlockEntityType.validBlocks field in a safe manner.
The class of the newly injected block should share the highest common class that all existing blocks in the targeted validBlocks has.
Please use this event instead of manipulating BlockEntityType directly.
Example: If the valid blocks list has StandingSignBlock entry and WallSignBlock entry, the common class is SignBlock,
the given block must be a SignBlock or have SignBlock as a parent class in its hierarchy. Example:
public static void onBlockEntityValidBlocks(BlockEntityTypeAddBlocksEvent event) {
event.modify(BlockEntityType.SIGN, MODDED_SIGN_BLOCK.get());
}
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddValidBlock(Block block, @Nullable Class<?> baseClass, Set<Block> currentValidBlocks) private static Class<?> findClosestCommonSuper(Class<?> superClass, Class<?> childClass) private @Nullable Class<?> getCommonSuperClassForExistingValidBlocks(Set<Block> validBlocks) voidmodify(BiPredicate<ResourceKey<BlockEntityType<?>>, BlockEntityType<?>> blockEntityTypeToMatch, Block... blocksToAdd) Will add the given blocks to the matchingBlockEntityType's set of valid blocks.voidmodify(ResourceKey<BlockEntityType<?>> blockEntityTypeKey, Block... blocksToAdd) Will add the given blocks to theBlockEntityType's set of valid blocks.voidmodify(BlockEntityType<?> blockEntityType, Block... blocksToAdd) Will add the given blocks to the providedBlockEntityType's set of valid blocks.
-
Field Details
-
memoizedCommonSuperClass
-
-
Constructor Details
-
BlockEntityTypeAddBlocksEvent
public BlockEntityTypeAddBlocksEvent()
-
-
Method Details
-
modify
Will add the given blocks to the providedBlockEntityType's set of valid blocks. -
modify
Will add the given blocks to theBlockEntityType's set of valid blocks. -
modify
public void modify(BiPredicate<ResourceKey<BlockEntityType<?>>, BlockEntityType<?>> blockEntityTypeToMatch, Block... blocksToAdd) Will add the given blocks to the matchingBlockEntityType's set of valid blocks. -
addValidBlock
-
getCommonSuperClassForExistingValidBlocks
-
findClosestCommonSuper
-