Tutorial 11. Tile Entities

Before you read, make sure you have seen the previous tutorial

Code is on github

So, easy stuff is done. We covered the basic. Lets go advanced!
So, what is a tile entity? Tile Entities are blocks which DO stuff. Ores dont do anything, but a furnace does something. Therefor, a furnace is a TE (Tile Entity). Few more examples of TE’s are: Workbenches, Anvils, Hoppers etc.

Let’s start.

First, we create a new basic block.



Nothing fancy so far.
Now, lets bind a Tile Entity to this block.

So, we tell forge that this block DOES have a TE, and we create that new TE.
In the package tileentities, lets create our TE class.

In a bit, we will add a function to this TE.

TE’s need to be registered in a special way. The best way, is to do that in the proxy. So lets create a method registerTileEntities in CommonProxy.

To register this TE, we call GameRegistry.registerTileEntity.
This needs 2 parameters. 1) A Tile Entity class (Class <? extends TileEntity>)
2) A name.

And call this method in your main class.

So. Basically we have a TE now. But for the sake of demonstation, let’s make the TE change the worldtime!

The updateEntity() gets called every tick. (tick = 1/20 sec).
This will make the TE change the worldtime every 5 seconds.
Run the game, and your TE is done!

Back to List
Next tutorial

2 Responses to Tutorial 11. Tile Entities

  1. Maarten says:

    what does worldObj.isRemote mean?

    • 1arthurf says:

      This means if the world is remote as in a client. That is why a lot of minecraft’s code tests for if the world isn’t remote.

      if (!world.isRemote)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">