Class PhantomBlock
-
- All Implemented Interfaces:
-
io.github.pylonmc.pylon.core.block.base.PylonBreakHandler
public final class PhantomBlock extends PylonBlock implements PylonBreakHandler
Phantom blocks are used where a block failed to load, or where a block errors and is unloaded.
The intention behind phantom blocks is to make BlockStorage act consistently even if the block is not loaded - i.e., if a block is broken, its block storage data should also be deleted. Additionally, phantom blocks allow us to persist data from blocks that have failed to load. In such cases, the data should not be deleted to avoid cases where an addon fails to load and all of its blocks get deleted when their chunk is loaded.
This is slightly hacky, but also by far the simplest way to accomplish this; a more 'clean' solution likely involves a lot more boilerplate and overhead, this is nice and intuitive and unlikely to clash with any changes in the future.
-
-
Constructor Summary
Constructors Constructor Description PhantomBlock(PersistentDataContainer pdc, NamespacedKey erroredBlockKey, Block block)
-
Method Summary
Modifier and Type Method Description final PersistentDataContainergetPdc()final NamespacedKeygetErroredBlockKey()BooleangetDisableBlockTextureEntity()Set this to trueif your block should not have a blockTextureEntity for custom models/textures.voidsetDisableBlockTextureEntity(Boolean value)Set this to trueif your block should not have a blockTextureEntity for custom models/textures.final BlockgetBlock()final PylonBlockSchemagetSchema()All the data needed to create or load the block. final NamespacedKeygetKey()final TranslatableComponentgetNameTranslationKey()final TranslatableComponentgetLoreTranslationKey()final TranslatableComponentgetDefaultWailaTranslationKey()final WrapperEntitygetBlockTextureEntity()A packet based ItemDisplay sent to players with customBlockTexturesenabled.final PylonItemSchemagetDefaultItem()voidpostBreak(BlockBreakContext context)WailaDisplaygetWaila(Player player)WAILA is the text that shows up when looking at a block to tell you what the block is. ItemStackgetDropItem(BlockBreakContext context)Returns the item that the block should drop. ItemStackgetPickItem()Returns the item that should be given when the block is middle clicked. -
Methods inherited from class io.github.pylonmc.pylon.core.block.PylonBlock
getBlockTextureItem, getSettings, write, writeDebugInfo -
Methods inherited from class io.github.pylonmc.pylon.core.block.base.PylonBreakHandler
onBreak, preBreak -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
PhantomBlock
PhantomBlock(PersistentDataContainer pdc, NamespacedKey erroredBlockKey, Block block)
-
-
Method Detail
-
getPdc
final PersistentDataContainer getPdc()
-
getErroredBlockKey
final NamespacedKey getErroredBlockKey()
-
getDisableBlockTextureEntity
Boolean getDisableBlockTextureEntity()
Set this to
trueif your block should not have a blockTextureEntity for custom models/textures.For example, if your block is comprised fully of ItemDisplays, then you may have no need for a texture entity as your existing entities could already support custom models/textures.
-
setDisableBlockTextureEntity
void setDisableBlockTextureEntity(Boolean value)
Set this to
trueif your block should not have a blockTextureEntity for custom models/textures.For example, if your block is comprised fully of ItemDisplays, then you may have no need for a texture entity as your existing entities could already support custom models/textures.
-
getSchema
final PylonBlockSchema getSchema()
All the data needed to create or load the block.
-
getKey
final NamespacedKey getKey()
-
getNameTranslationKey
final TranslatableComponent getNameTranslationKey()
-
getLoreTranslationKey
final TranslatableComponent getLoreTranslationKey()
-
getDefaultWailaTranslationKey
final TranslatableComponent getDefaultWailaTranslationKey()
-
getBlockTextureEntity
final WrapperEntity getBlockTextureEntity()
A packet based ItemDisplay sent to players with
customBlockTexturesenabled.Being lazily initialized, if you do not access the entity directly it will only be created when a player with
customBlockTexturescomes within range for the first time. This is to avoid unnecessary entity creation, memory usage, and entity update overhead when no players can actually see it.Upon initialization the entity is set up by setupBlockTexture (which can be overridden), and modifications afterward can be done using updateBlockTexture.
For example, if you have a block that faces different directions, you can override setupBlockTexture and rotate the entity based on the block's facing direction.
Or let's say you have a furnace block that changes texture based on whether it's lit or not, you can use updateBlockTexture to change the entity's item to reflect the lit/unlit state.
-
getDefaultItem
final PylonItemSchema getDefaultItem()
-
postBreak
void postBreak(BlockBreakContext context)
-
getWaila
WailaDisplay getWaila(Player player)
WAILA is the text that shows up when looking at a block to tell you what the block is.
This will only be called for the player if the player has WAILA enabled.
- Returns:
the WAILA configuration, or null if WAILA should not be shown for this block.
-
getDropItem
ItemStack getDropItem(BlockBreakContext context)
Returns the item that the block should drop.
By default, returns the item with the same key as the block only if BlockBreakContext.normallyDrops is true, and null otherwise.
- Returns:
the item the block should drop, or null if none
-
getPickItem
ItemStack getPickItem()
Returns the item that should be given when the block is middle clicked.
By default, returns the item with the same key as the block only if BlockBreakContext.normallyDrops is true, and null otherwise.
- Returns:
the item the block should give when middle clicked, or null if none
-
-
-
-