Class PylonBlock


  • 
    public class PylonBlock
    
                        

    Represents 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.

    • 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

      • getDisableBlockTextureEntity

         Boolean getDisableBlockTextureEntity()

        Set this to true if 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 true if 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 customBlockTextures enabled.

        Being lazily initialized, if you do not access the entity directly it will only be created when a player with customBlockTextures comes 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.

      • 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.

      • 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.

      • 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 block
        material - The material to use as the block.
        blockClass - The class extending PylonBlock that represents a block of this type in the world.