Tutorial 17. Meta Blocks

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


Code is on github

Let’s talk about meta blocks.
What are meta blocks? Meta blocks are 2 blocks, which share the same ID.
In other words, 2 blocks which look/act almost the same.
Think abour RedstoneLamps, Wool, (items: Dye’s)

For this tutorial, i will use tutorial 3 and 16 as bases.
Therefor, make sure you’ve watched them.


Basically, there are only 2 things you have to take care of.
Textures, and making sure the meta’s are added to ‘the list’.

This makes sure that your meta’s get added.
The i < 2 is the number of meta’s the block has (mine has 2 therefor).
Not a really fancy bit of code, but required.

We had the old way of returning the texture:

We can make this meta sensitive

 

So 1 meta block will have a different order of textures.
Ofcoure you guys would wanna add whole new textures.

Now, to add a little bit of functionality, we will make this block change meta, and therefor the texture.

So, let’s do that by a redstone signal. For a change of signal, the best thing to do, is check onNeighborBlockChange. Firstly, check if the world is remote, and then check if world.isBlockIndirectlyGettingPowered. If that’s true, and the meta is not the meta that we want when lit, set the block to our meta.
If the block is not powered, and the state is “on”, change back to ‘off’

 

Back to List

Next tutorial


One Response to Tutorial 17. Meta Blocks

  1. Maarten says:

    How do you not show all the different meta-blocks in the creative tab?

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="">