Class ExtendedBlockEntity
java.lang.Object
net.minecraft.world.level.block.entity.BlockEntity
net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity
- All Implemented Interfaces:
HandlerProvider, net.minecraft.core.TypedInstance<net.minecraft.world.level.block.entity.BlockEntityType<?>>, net.minecraft.util.debug.DebugValueSource
- Direct Known Subclasses:
ExtendedContainerBlockEntity
public abstract class ExtendedBlockEntity
extends net.minecraft.world.level.block.entity.BlockEntity
implements HandlerProvider
A block entity with
Attachment data, handlers and ticking made simple. Its data saves and syncs on its own
(every block entity's does; this class adds shortcuts), so a typical subclass is only its logic:
public class GeneratorBlockEntity extends ExtendedBlockEntity {
public static final Attachment<Integer> ENERGY = MyMod.ATTACHMENTS.builder("energy", Codec.INT, 0)
.sync(SyncPolicy.ALL).keepOnDrop().build();
public GeneratorBlockEntity(BlockPos pos, BlockState state) {
super(MyBlockEntities.GENERATOR.get(), pos, state);
this.handlers.addSided(MyHandlers.ENERGY, side -> side == Direction.UP ? null : this.storage);
}
@Override
protected void serverTick(ServerLevel level) {
this.update(ENERGY, energy -> Math.min(energy + 1, 1000));
}
}
// In the block: public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level l, BlockState s, BlockEntityType<T> type)
// { return ExtendedBlockEntity.ticker(type, MyBlockEntities.GENERATOR.get()); }
For an inventory, extend ExtendedContainerBlockEntity.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.util.debug.DebugValueSource
net.minecraft.util.debug.DebugValueSource.Registration, net.minecraft.util.debug.DebugValueSource.ValueGetter<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HandlerMapWhatgetHandler(HandlerType, Direction)hands out; add to it in the constructor.Fields inherited from class net.minecraft.world.level.block.entity.BlockEntity
level, remove, worldPosition -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExtendedBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclientTick(net.minecraft.world.level.Level level) Runs every tick on clients, when the block usesticker(BlockEntityType, BlockEntityType).<T> Tget(Attachment<T> attachment) <T> TgetHandler(HandlerType<T> type, @Nullable net.minecraft.core.Direction side) voidTells handler caches at this position to look again, after changing whatgetHandler(HandlerType, Direction)hands out.<T> voidmodify(Attachment<T> attachment, Consumer<T> mutator) protected voidserverTick(net.minecraft.server.level.ServerLevel level) Runs every tick on the server, when the block usesticker(BlockEntityType, BlockEntityType).<T> voidset(Attachment<T> attachment, T value) static <T extends net.minecraft.world.level.block.entity.BlockEntity>
@Nullable net.minecraft.world.level.block.entity.BlockEntityTicker<T> ticker(net.minecraft.world.level.block.entity.BlockEntityType<T> type, net.minecraft.world.level.block.entity.BlockEntityType<? extends ExtendedBlockEntity> expected) The ticker for a block'sgetTicker: ticksexpectedblock entities throughserverTick(ServerLevel)/clientTick(Level), and nothing else.<T> Tupdate(Attachment<T> attachment, UnaryOperator<T> function) Methods inherited from class net.minecraft.world.level.block.entity.BlockEntity
addEntityType, applyComponents, applyComponentsFromItemStack, applyImplicitComponents, clearRemoved, collectComponents, collectImplicitComponents, components, fillCrashReportCategory, getBlockPos, getBlockState, getLevel, getNameForReporting, getPosFromTag, getType, getUpdatePacket, getUpdateTag, hasLevel, isRemoved, isValidBlockState, loadAdditional, loadCustomOnly, loadStatic, loadWithComponents, parseCustomNameSafe, preRemoveSideEffects, problemPath, registerDebugValues, removeComponentsFromTag, saveAdditional, saveCustomOnly, saveCustomOnly, saveWithFullMetadata, saveWithFullMetadata, saveWithId, saveWithoutMetadata, saveWithoutMetadata, setBlockState, setChanged, setChanged, setComponents, setLevel, setRemoved, triggerEvent, typeHolderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.core.TypedInstance
is, is, is, is, is, tags
-
Field Details
-
handlers
WhatgetHandler(HandlerType, Direction)hands out; add to it in the constructor.
-
-
Constructor Details
-
ExtendedBlockEntity
protected ExtendedBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
-
-
Method Details
-
attachments
-
get
-
set
-
update
-
modify
-
getHandler
@Nullable public <T> T getHandler(HandlerType<T> type, @Nullable @Nullable net.minecraft.core.Direction side) - Specified by:
getHandlerin interfaceHandlerProvider- Parameters:
side- the face asked through, ornullfor the holder as a whole (alwaysnullfor most entity lookups)- Returns:
- the handler, or
nullif this holder has none of that type on that side
-
invalidateHandlers
public void invalidateHandlers()Tells handler caches at this position to look again, after changing whatgetHandler(HandlerType, Direction)hands out. -
serverTick
protected void serverTick(net.minecraft.server.level.ServerLevel level) Runs every tick on the server, when the block usesticker(BlockEntityType, BlockEntityType). -
clientTick
protected void clientTick(net.minecraft.world.level.Level level) Runs every tick on clients, when the block usesticker(BlockEntityType, BlockEntityType). -
ticker
@Nullable public static <T extends net.minecraft.world.level.block.entity.BlockEntity> @Nullable net.minecraft.world.level.block.entity.BlockEntityTicker<T> ticker(net.minecraft.world.level.block.entity.BlockEntityType<T> type, net.minecraft.world.level.block.entity.BlockEntityType<? extends ExtendedBlockEntity> expected) The ticker for a block'sgetTicker: ticksexpectedblock entities throughserverTick(ServerLevel)/clientTick(Level), and nothing else.
-