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.

    • 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