Class ExtendedContainerBlockEntity
java.lang.Object
net.minecraft.world.level.block.entity.BlockEntity
net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity
net.ixdarklord.coolcatcore.api.block.ExtendedContainerBlockEntity
- All Implemented Interfaces:
HandlerProvider,net.minecraft.world.Clearable,net.minecraft.world.Container,net.minecraft.world.WorldlyContainer
public abstract class ExtendedContainerBlockEntity
extends ExtendedBlockEntity
implements net.minecraft.world.WorldlyContainer
A
ExtendedBlockEntity with an inventory. The inventory is a container attachment, so it
saves and syncs like the rest of the data; the block entity itself is a WorldlyContainer, so hoppers,
comparators, menus, and other mods' pipes (on both loaders) use it through the layout's faces and roles.
public static final Attachment<SlotContainer> INVENTORY = MyMod.ATTACHMENTS.container("crusher_inventory", CRUSHER_LAYOUT).build();
public CrusherBlockEntity(BlockPos pos, BlockState state) {
super(MyBlockEntities.CRUSHER.get(), pos, state, INVENTORY);
}
The contents spill when the block is broken, unless the layout keeps them;
on 1.20.1 the block does that from its onRemove, with onBlockRemoved(net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.Level, net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState).
Add .sync(SyncPolicy.ALL) to the attachment when clients need the contents without a menu open (to render them).-
Field Summary
Fields inherited from class net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity
handlersFields inherited from class net.minecraft.world.level.block.entity.BlockEntity
level, remove, worldPositionFields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_LIMIT, LARGE_MAX_STACK_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExtendedContainerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, Attachment<SlotContainer> containerAttachment) -
Method Summary
Modifier and TypeMethodDescriptionbooleancanPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) booleancanPlaceItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side) booleancanTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack) booleancanTakeItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side) voidintThe comparator signal of the contents, for the block'sgetAnalogOutputSignal.int<T> TgetHandler(HandlerType<T> type, @Nullable net.minecraft.core.Direction side) net.minecraft.world.item.ItemStackgetItem(int slot) intintgetMaxStackSize(net.minecraft.world.item.ItemStack stack) The most of the item a slot holds, before per-slot limits.int[]getSlotsForFace(net.minecraft.core.Direction side) booleanisEmpty()voidload(net.minecraft.nbt.CompoundTag tag) static voidonBlockRemoved(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState newState) For the block'sonRemove, before callingsuper.onRemove: when the block is replaced by another, spills the contents of itsExtendedContainerBlockEntity(unless the layoutkeeps them) and updates comparators.net.minecraft.world.item.ItemStackremoveItem(int slot, int count) net.minecraft.world.item.ItemStackremoveItemNoUpdate(int slot) protected voidsaveAdditional(net.minecraft.nbt.CompoundTag tag) voidvoidsetItem(int slot, net.minecraft.world.item.ItemStack stack) booleanstillValid(net.minecraft.world.entity.player.Player player) Methods inherited from class net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity
attachments, clientTick, get, invalidateHandlers, modify, serverTick, set, ticker, updateMethods inherited from class net.minecraft.world.level.block.entity.BlockEntity
addEntityType, clearRemoved, fillCrashReportCategory, getBlockPos, getBlockState, getLevel, getPosFromTag, getType, getUpdatePacket, getUpdateTag, hasLevel, isRemoved, loadStatic, onlyOpCanSetNbt, saveToItem, saveWithFullMetadata, saveWithId, saveWithoutMetadata, setBlockState, setChanged, setLevel, setRemoved, triggerEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.world.Container
countItem, hasAnyMatching, hasAnyOf, startOpen, stopOpen
-
Constructor Details
-
ExtendedContainerBlockEntity
protected ExtendedContainerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, Attachment<SlotContainer> containerAttachment)
-
-
Method Details
-
getContainer
-
getContainerAttachment
-
getLayout
-
getComparatorSignal
public int getComparatorSignal()The comparator signal of the contents, for the block'sgetAnalogOutputSignal. -
getHandler
@Nullable public <T> T getHandler(HandlerType<T> type, @Nullable @Nullable net.minecraft.core.Direction side) - Specified by:
getHandlerin interfaceHandlerProvider- Overrides:
getHandlerin classExtendedBlockEntityside- 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
-
setChanged
public void setChanged()- Specified by:
setChangedin interfacenet.minecraft.world.Container- Overrides:
setChangedin classnet.minecraft.world.level.block.entity.BlockEntity
-
onBlockRemoved
public static void onBlockRemoved(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState newState) For the block'sonRemove, before callingsuper.onRemove: when the block is replaced by another, spills the contents of itsExtendedContainerBlockEntity(unless the layoutkeeps them) and updates comparators.public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { ExtendedContainerBlockEntity.onBlockRemoved(state, level, pos, newState); super.onRemove(state, level, pos, newState, movedByPiston); } -
saveAdditional
protected void saveAdditional(net.minecraft.nbt.CompoundTag tag) - Overrides:
saveAdditionalin classnet.minecraft.world.level.block.entity.BlockEntity
-
load
public void load(net.minecraft.nbt.CompoundTag tag) - Overrides:
loadin classnet.minecraft.world.level.block.entity.BlockEntity
-
getSlotsForFace
public int[] getSlotsForFace(net.minecraft.core.Direction side) - Specified by:
getSlotsForFacein interfacenet.minecraft.world.WorldlyContainer
-
canPlaceItemThroughFace
public boolean canPlaceItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction side) - Specified by:
canPlaceItemThroughFacein interfacenet.minecraft.world.WorldlyContainer
-
canTakeItemThroughFace
public boolean canTakeItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side) - Specified by:
canTakeItemThroughFacein interfacenet.minecraft.world.WorldlyContainer
-
getContainerSize
public int getContainerSize()- Specified by:
getContainerSizein interfacenet.minecraft.world.Container
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfacenet.minecraft.world.Container
-
getItem
public net.minecraft.world.item.ItemStack getItem(int slot) - Specified by:
getItemin interfacenet.minecraft.world.Container
-
removeItem
public net.minecraft.world.item.ItemStack removeItem(int slot, int count) - Specified by:
removeItemin interfacenet.minecraft.world.Container
-
removeItemNoUpdate
public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot) - Specified by:
removeItemNoUpdatein interfacenet.minecraft.world.Container
-
setItem
public void setItem(int slot, net.minecraft.world.item.ItemStack stack) - Specified by:
setItemin interfacenet.minecraft.world.Container
-
getMaxStackSize
public int getMaxStackSize()- Specified by:
getMaxStackSizein interfacenet.minecraft.world.Container
-
getMaxStackSize
public int getMaxStackSize(net.minecraft.world.item.ItemStack stack) The most of the item a slot holds, before per-slot limits. -
stillValid
public boolean stillValid(net.minecraft.world.entity.player.Player player) - Specified by:
stillValidin interfacenet.minecraft.world.Container
-
canPlaceItem
public boolean canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) - Specified by:
canPlaceItemin interfacenet.minecraft.world.Container
-
canTakeItem
public boolean canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack) - Specified by:
canTakeItemin interfacenet.minecraft.world.Container
-
clearContent
public void clearContent()- Specified by:
clearContentin interfacenet.minecraft.world.Clearable
-