Interface ISemiBlock
- All Superinterfaces:
net.minecraftforge.common.capabilities.ICapabilityProvider
- All Known Implementing Classes:
AbstractLogisticsFrameEntity,AbstractSemiblockEntity,CropSupportEntity,HeatFrameEntity,LogisticsActiveProviderEntity,LogisticsDefaultStorageEntity,LogisticsPassiveProviderEntity,LogisticsRequesterEntity,LogisticsStorageEntity,SpawnerAgitatorEntity,TransferGadgetEntity
public interface ISemiBlock
extends net.minecraftforge.common.capabilities.ICapabilityProvider
Represents a "semiblock" - an attachable gadget which sits on a real block, such as a logistics frame or
crop support.
- Implementation Note:
- While semiblocks are implemented as entities, this is an implementation detail which should not be relied upon any more than strictly necessary.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddTooltip(Consumer<net.minecraft.network.chat.Component> consumer, net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag, boolean extended) Add tooltip information for this semiblock.static ISemiBlockbyTrackingId(net.minecraft.world.level.Level world, int id) Retrieve a semiblock by tracking ID.booleancanCoexist(ISemiBlock otherSemiblock) Check if this semiblock can coexist with the other semiblock, in the same block pos.booleancanPlace(net.minecraft.core.Direction facing) Check if this semiblock can be placed here.net.minecraft.core.BlockPosGet the block position this entity occupies.net.minecraft.world.level.block.entity.BlockEntityGet the block entity at the semiblock's position.default intgetColor()A color in ARGB format.net.minecraft.network.chat.ComponentGet the displayed name for this semiblock.net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>getDrops()Add any dropped items from this semiblock to the given list.net.minecraft.resources.ResourceLocationGet a unique ID for this semiblock, which should match the corresponding item's registry name.intGet the tracking for this semiblock; this should only be used for network sync purposes, and is subject to change on a world reload.net.minecraft.world.level.LevelgetWorld()Get the world this semiblock is in.booleanisValid()Check if this semiblock is still valid, i.e.voidkilledByEntity(net.minecraft.world.entity.Entity entity) Called when an entity has caused this semiblock to be removed; usually, but necessarily, a player wrenching or hitting it.default voidonPlaced(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction facing) Called immediately after the semiblock entity has been added to the world.default booleanonRightClickWithConfigurator(net.minecraft.world.entity.player.Player player, net.minecraft.core.Direction side) Called when a semiblock is right-clicked with a Logistics ConfiguratorvoidreadFromBuf(net.minecraft.network.FriendlyByteBuf payload) Read this semiblock from network buffer for network sync purposes.net.minecraft.nbt.CompoundTagserializeNBT(net.minecraft.nbt.CompoundTag tag) Written to the dropped item (under the "EntityTag" subtag) when the semiblock is broken, to persisted entity data byEntity#writeAdditional(), and displayed by info mods such as TOP or Waila.voidtick()Implement tick logic here.voidwriteToBuf(net.minecraft.network.FriendlyByteBuf payload) Write this semiblock to network buffer for network sync purposes.Methods inherited from interface net.minecraftforge.common.capabilities.ICapabilityProvider
getCapability, getCapability
-
Method Details
-
getSemiblockId
net.minecraft.resources.ResourceLocation getSemiblockId()Get a unique ID for this semiblock, which should match the corresponding item's registry name.- Returns:
- a semiblock ID
-
getDisplayName
net.minecraft.network.chat.Component getDisplayName()Get the displayed name for this semiblock.- Returns:
- the name
-
getWorld
net.minecraft.world.level.Level getWorld()Get the world this semiblock is in.- Returns:
- the world
-
getBlockPos
net.minecraft.core.BlockPos getBlockPos()Get the block position this entity occupies.- Returns:
- the block pos
-
getCachedTileEntity
net.minecraft.world.level.block.entity.BlockEntity getCachedTileEntity()Get the block entity at the semiblock's position. This is cached for performance.- Returns:
- the block entity, or null if there is none
-
serializeNBT
net.minecraft.nbt.CompoundTag serializeNBT(net.minecraft.nbt.CompoundTag tag) Written to the dropped item (under the "EntityTag" subtag) when the semiblock is broken, to persisted entity data byEntity#writeAdditional(), and displayed by info mods such as TOP or Waila. Use this method rather thanwriteAdditional()for fields that either need to be serialized to the dropped item, or displayed on TOP/Waila.- Parameters:
tag- NBT tag to write data to- Implementation Note:
- Data written to itemstacks is automatically applied to newly-spawned entities by
EntityType.updateCustomEntityTag(Level, Player, Entity, CompoundTag)when the semiblock entity is spawned from an item (i.e. placed by a player).
-
tick
void tick()Implement tick logic here. Always be sure to callsuper.tick()in subclass overrides! -
isValid
boolean isValid()Check if this semiblock is still valid, i.e. the underlying entity is still alive.- Returns:
- true if this semiblock is valid, false otherwise
-
getDrops
net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> getDrops()Add any dropped items from this semiblock to the given list. By default, just the semiblock item itself is added, but this can be overridden to drop extra items if needed. -
canPlace
boolean canPlace(net.minecraft.core.Direction facing) Check if this semiblock can be placed here.- Parameters:
facing- the side of the block against which it is placed- Returns:
- true if the semiblock is placeable here, false otherwise
-
onPlaced
default void onPlaced(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction facing) Called immediately after the semiblock entity has been added to the world.- Parameters:
player- player who is placing the semiblockstack- itemstack used to create the entityfacing- the side of the block which was clicked to place the entity
-
onRightClickWithConfigurator
default boolean onRightClickWithConfigurator(net.minecraft.world.entity.player.Player player, net.minecraft.core.Direction side) Called when a semiblock is right-clicked with a Logistics Configurator- Parameters:
player- the playerside- the side of the block being clicked- Returns:
- true if something was done, false if the semiblock doesn't care about being clicked
-
canCoexist
Check if this semiblock can coexist with the other semiblock, in the same block pos. By default this is true if at least one of the semiblocks is aIDirectionalSemiblockand both semiblocks have a different side.- Parameters:
otherSemiblock- the other semiblock- Returns:
- true if they can coexist, false otherwise
-
getTrackingId
int getTrackingId()Get the tracking for this semiblock; this should only be used for network sync purposes, and is subject to change on a world reload.- Returns:
- the underlying entity's ID, or -1 if the entity has not been added to the world
- See Also:
-
killedByEntity
void killedByEntity(net.minecraft.world.entity.Entity entity) Called when an entity has caused this semiblock to be removed; usually, but necessarily, a player wrenching or hitting it.- Parameters:
entity- the killer entity
-
addTooltip
default void addTooltip(Consumer<net.minecraft.network.chat.Component> consumer, net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag, boolean extended) Add tooltip information for this semiblock. This info is used by info mods such as Waila or TOP.- Parameters:
consumer- the component consumerplayer- the player looking at the entity or itemtag- NBT data as saved byserializeNBT(CompoundTag)extended- true if extended data should be shown
-
writeToBuf
void writeToBuf(net.minecraft.network.FriendlyByteBuf payload) Write this semiblock to network buffer for network sync purposes.- Parameters:
payload- the buffer
-
readFromBuf
void readFromBuf(net.minecraft.network.FriendlyByteBuf payload) Read this semiblock from network buffer for network sync purposes.- Parameters:
payload- the buffer
-
getColor
default int getColor()A color in ARGB format. Used for various things: GUI/item/render tinting, as well as TOP colour coding.- Returns:
- a color for this semiblock type
-
byTrackingId
Retrieve a semiblock by tracking ID. This is only intended to be used for network sync purposes and is subject to change on a world reload.- Parameters:
world- the worldid- the tracking ID- Returns:
- a semiblock, or null if ID is not valid
- See Also:
-