Skip to content
Jon R edited this page Jul 7, 2016 · 5 revisions

Blocks are the foundation on which TerraLegion's world is built. For those of you familiar with Minecraft or Terraria, you will know that the world is modifiable through the use of blocks. The player is able to destroy blocks within the world and use them to create resources and build structures. Blocks are able to have many different properties that modify the world around the player. Some examples are blocks that light up the world, blocks that act as liquids like water or lava, blocks that trigger an event to do something else, etc. The ideas are endless and you can implement your own custom blocks to do whatever you'd like.

The Block class shows you the basic structure of a block in the world. You will see a few instance variables that are kept within the block that define different static properties that a block has. It's important to note the use of the word static because when you read about The Block Manager you will learn that there is only ever one instance of a block in the game at anytime for each block type.

The class has three important methods that you should be familiar with:

  1. onBreak(ChunkManager chunkManager, Chunk chunk, int chunkTileX, int chunkTileY)
  2. onDamage(ChunkManager chunkManager, Chunk chunk, int chunkTileX, int chunkTileY, BlockProperties properties, float toolPower)
  3. onPlace(ChunkManager chunkManager, Chunk chunk, int chunkTileX, int chunkTileY)

Each method is called when it's respective event happens. So when a block is broken it will call the onBreak method. When a block is damaged it will call the onDamage method. When a block is placed it will call the onPlace method. You will notice that each method has some code that is run when the events are called. You can modify these methods to add your own events. However, if the event that you're adding is not an event that should happen for every block in the game, you will need to create a new class that extends Block and overrides the methods within there. For example, the LightBlock overrides the onPlace and onDestroy methods of the block and adds its own custom event. In this case light is set or removed depending on which event is called. Because adding and removing light is not something that should happen to every block in the game, it needed to be moved to it's own class.

You will learn more about the instance variables of the Block and how the Block classes are used in the next few sections.

Overview
The World
        Blocks
        Block Types
        Block Manager
        Block Properties
        Walls
        Chunks
        Chunk Generation
        The Chunk Manager
        Lighting
        The Physics Engine
        Entities
        The World
        World I/O

Items
        Items & Item Categories
        Item Types
        Item Stacks
        Item Manager
        Inventories
        Crafting

User Interfaces
        The Screen System
        Interface Components
        The Game HUD

Utilities
        The Thread Manager
        Factories & Caches

Clone this wiki locally