Class PylonBlock
-
public class PylonBlockRepresents a Pylon block in the world.
All custom Pylon blocks extend this class. Every instance of this class is wrapping a real block in the world, and is stored in BlockStorage. All new block types must be registered using register.
An implementation of PylonBlock must have two constructors: one that takes a Block and a BlockCreateContext, and one that takes a Block and a PersistentDataContainer. The first constructor is known as the "create constructor", and is used when the block is created in the world. The second constructor is known as the "load constructor", and is used to reconstruct the block when the chunk containing the block is loaded.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classPylonBlock.Companion
-
Field Summary
Fields Modifier and Type Field Description public final static PylonBlock.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description PylonBlock(Block block, BlockCreateContext context)This constructor is called when a new block is created in the world. PylonBlock(Block block, PersistentDataContainer pdc)This constructor is called when the block is loaded.
-
Method Summary
Modifier and Type Method Description final BlockgetBlock()final PylonBlockSchemagetSchema()All the data needed to create or load the block. final NamespacedKeygetKey()final TranslatableComponentgetNameTranslationKey()final TranslatableComponentgetLoreTranslationKey()final TranslatableComponentgetDefaultWailaTranslationKey()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 WrapperEntitygetBlockTextureEntity()A packet based ItemDisplay sent to players with customBlockTexturesenabled.final PylonItemSchemagetDefaultItem()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. ItemStackgetBlockTextureItem()Returns the item that should be used to display the block's texture. voidwriteDebugInfo(PersistentDataContainer pdc)Called when debug info is requested for the block by someone using the DebugWaxedWeatheredCutCopperStairs. voidwrite(PersistentDataContainer pdc)Called when the block is saved. final ConfiggetSettings()Returns settings associated with the block. final static voidregister(NamespacedKey key, Material material, Class<out PylonBlock> blockClass)Registers a new block type with Pylon. final static PylonBlockgetPylonBlock(Block $self)final static BooleanisVanillaBlock(Block $self)final static PylonBlockgetPylonBlock(Block $self)final static BooleanisVanillaBlock(Block $self)-
-
Constructor Detail
-
PylonBlock
PylonBlock(Block block, BlockCreateContext context)
This constructor is called when a new block is created in the world.
-
PylonBlock
PylonBlock(Block block, PersistentDataContainer pdc)
This constructor is called when the block is loaded. For example, if the server restarts, we need to create a new PylonBlock instance, and we'll do it with this constructor.
You should only load data in this constructor. If you need to do any extra logic on load for whatever reason, it's recommended to do it in postLoad to make sure all data associated with your block that you don't directly control (such as inventories, associated entities, fluid tank data, etc) has been loaded.
-
-
Method Detail
-
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()
-
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.
-
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()
-
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
-
getBlockTextureItem
ItemStack getBlockTextureItem()
Returns the item that should be used to display the block's texture.
By default, returns the item with the same key as the block.
- Returns:
the item that should be used to display the block's texture
-
writeDebugInfo
void writeDebugInfo(PersistentDataContainer pdc)
Called when debug info is requested for the block by someone using the DebugWaxedWeatheredCutCopperStairs. If there is any transient data that can be useful for debugging, you're encouraged to serialize it here.
Defaults to a normal write call.
-
write
void write(PersistentDataContainer pdc)
Called when the block is saved.
Put any logic to save the data in the block here.
Do not assume that when this is called, the block is being unloaded. This may be called for other reasons, such as when a player right clicks with DebugWaxedWeatheredCutCopperStairs. Instead, implement io.github.pylonmc.pylon.core.block.base.PylonUnloadBlock and use io.github.pylonmc.pylon.core.block.base.PylonUnloadBlock.onUnload.
-
getSettings
final Config getSettings()
Returns settings associated with the block.
Shorthand for
Settings.get(getKey())
-
register
final static void register(NamespacedKey key, Material material, Class<out PylonBlock> blockClass)
Registers a new block type with Pylon.
- Parameters:
key- A unique key that identifies this type of blockmaterial- The material to use as the block.blockClass- The class extending PylonBlock that represents a block of this type in the world.
-
getPylonBlock
final static PylonBlock getPylonBlock(Block $self)
-
isVanillaBlock
final static Boolean isVanillaBlock(Block $self)
-
getPylonBlock
final static PylonBlock getPylonBlock(Block $self)
-
isVanillaBlock
final static Boolean isVanillaBlock(Block $self)
-
-
-
-