Class HandlerType<T>
java.lang.Object
net.ixdarklord.coolcatcore.api.handler.HandlerType<T>
- Type Parameters:
T- the handler's type
A kind of handler blocks, entities and items can hand out: something other code works with without knowing the
holder (an inventory, an energy buffer, a fluid tank...).
public static final HandlerType<EnergyStorage> ENERGY = HandlerType.create(id("energy"), EnergyStorage.class);
// Offer it: implement HandlerProvider (ExtendedBlockEntity does, through its HandlerMap), or register a provider,
// also for blocks, entities and items from other mods.
ENERGY.registerBlockEntity(MY_GENERATOR.get(), (generator, side) -> generator.energy());
// Use it:
EnergyStorage storage = ENERGY.find(level, pos, Direction.UP);
BlockHandlerCache<EnergyStorage> cache = ENERGY.createCache(level, pos, Direction.UP); // for repeated lookups
Lookups ask, in order: the holder itself (HandlerProvider, ItemHandlerProvider), the providers
registered for its block, block entity type, entity type or item, then the fallbacks. The first non-null wins.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandlerType.BlockEntityProvider<BE extends net.minecraft.world.level.block.entity.BlockEntity,T> static interfacestatic interfaceHandlerType.EntityProvider<E extends net.minecraft.world.entity.Entity,T> static interface -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable HandlerType<?> byId(net.minecraft.resources.ResourceLocation id) static <T> HandlerType<T> Creates a handler type; each id may be used once.createCache(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side) A cache for looking up the same position repeatedly (a pipe's neighbour).createCache(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side, Runnable onInvalidate) LikecreateCache(Level, BlockPos, Direction), runningonInvalidatewhen it's invalidated.find(net.minecraft.world.entity.Entity entity) find(net.minecraft.world.entity.Entity entity, @Nullable net.minecraft.core.Direction side) The entity's handler, through a face for entities that tell them apart (a minecart's hopper side).find(net.minecraft.world.item.ItemStack stack) find(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side) The handler of the block at a position, through a face (nullfor the block as a whole).find(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, @Nullable net.minecraft.core.Direction side) net.minecraft.resources.ResourceLocationid()static voidinvalidate(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Tells every cache at a position (of any handler type, CoolCatLib's and the loader's) to look again: call it when a block starts or stops handing out a handler, or hands out a different one.registerBlock(HandlerType.BlockProvider<T> provider, net.minecraft.world.level.block.Block... blocks) <BE extends net.minecraft.world.level.block.entity.BlockEntity>
HandlerType<T> registerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<BE> type, HandlerType.BlockEntityProvider<? super BE, T> provider) registerBlockFallback(HandlerType.BlockProvider<T> provider) Asked for every block the registered providers had nothing for.<E extends net.minecraft.world.entity.Entity>
HandlerType<T> registerEntity(net.minecraft.world.entity.EntityType<E> type, HandlerType.EntityProvider<? super E, T> provider) registerEntityFallback(HandlerType.EntityProvider<net.minecraft.world.entity.Entity, T> provider) registerItem(HandlerType.ItemProvider<T> provider, net.minecraft.world.level.ItemLike... items) registerItemFallback(HandlerType.ItemProvider<T> provider) toString()
-
Method Details
-
create
public static <T> HandlerType<T> create(net.minecraft.resources.ResourceLocation id, Class<T> handlerClass) Creates a handler type; each id may be used once. -
byId
-
id
public net.minecraft.resources.ResourceLocation id() -
handlerClass
-
registerBlock
public HandlerType<T> registerBlock(HandlerType.BlockProvider<T> provider, net.minecraft.world.level.block.Block... blocks) -
registerBlockEntity
public <BE extends net.minecraft.world.level.block.entity.BlockEntity> HandlerType<T> registerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<BE> type, HandlerType.BlockEntityProvider<? super BE, T> provider) -
registerBlockFallback
Asked for every block the registered providers had nothing for. -
registerEntity
public <E extends net.minecraft.world.entity.Entity> HandlerType<T> registerEntity(net.minecraft.world.entity.EntityType<E> type, HandlerType.EntityProvider<? super E, T> provider) -
registerEntityFallback
public HandlerType<T> registerEntityFallback(HandlerType.EntityProvider<net.minecraft.world.entity.Entity, T> provider) -
registerItem
public HandlerType<T> registerItem(HandlerType.ItemProvider<T> provider, net.minecraft.world.level.ItemLike... items) -
registerItemFallback
-
find
@Nullable public T find(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side) The handler of the block at a position, through a face (nullfor the block as a whole). -
find
@Nullable public T find(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, @Nullable @Nullable net.minecraft.core.Direction side) -
find
-
find
@Nullable public T find(net.minecraft.world.entity.Entity entity, @Nullable @Nullable net.minecraft.core.Direction side) The entity's handler, through a face for entities that tell them apart (a minecart's hopper side). -
find
-
createCache
public BlockHandlerCache<T> createCache(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side) A cache for looking up the same position repeatedly (a pipe's neighbour). It notices on its own when the block or block entity there changes; holders that change what they hand out callinvalidate(net.minecraft.world.level.Level, net.minecraft.core.BlockPos). -
createCache
public BlockHandlerCache<T> createCache(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side, Runnable onInvalidate) LikecreateCache(Level, BlockPos, Direction), runningonInvalidatewhen it's invalidated. -
invalidate
public static void invalidate(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Tells every cache at a position (of any handler type, CoolCatLib's and the loader's) to look again: call it when a block starts or stops handing out a handler, or hands out a different one. -
toString
-