Jump to content

Wool -> Wool Stairs help... [METADATA] (I think)


Recommended Posts

Posted

Hello guys, I've been trying to add some wool stairs to the game (I know it's probably been done before) and I was trying to work out how to have one block (Whit Wool Stairs) and then have each different coloured block as a metadata afterwards (is that the right terminology?). But was having a problem and I don't exactly know what is causing it. I basically copied the wool code and then changed some names and such. When I place them I get this: (Click Spoiler)

 

 

What it looks like in my inventory:

ArFoMa9.png

 

The four different positions when placed:

Exj3oTn.png

 

The four different positions when placed upside-down:

rsBdxYv.png

 

 

What I think is happening is that the metadata for which position the stair is placed in and the metadata for the colour of the wool is getting mixed up. Here is the code for my block:

 

 

package mod.ElementalWorld;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import net.minecraft.src.Block;
import net.minecraft.src.BlockCloth;
import net.minecraft.src.BlockStairs;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;

public class BlockWoolStairs extends BlockStairs
{
        /** The block that is used as model for the stair. */
        private  Block modelBlock;
        public BlockWoolStairs(int par1,Block modelBlockx, int par2)
        {
                super(par1, modelBlockx, par2);
                blockIndexInTexture = par2;
                this.modelBlock = modelBlockx;
                this.setLightOpacity(0);
                this.setCreativeTab(ElementalWorld.elementalWorldDecorationsTab);
        }
        
        @Override
        //this deals with the block texture. 

        
        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
        {
            if (par2 == 0)
            {
                return this.blockIndexInTexture;
            }
            else
            {
                par2 = ~(par2 & 15);
                return 113 + ((par2 &  >> 3) + (par2 & 7) * 16;
            }
        }

        public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
        {
            for (int var4 = 0; var4 < 16; ++var4)
            {
                par3List.add(new ItemStack(par1, 1, var4));
            }
        }
        
      //gets texture file
        public String getTextureFile()
        {
         return "/terrain.png";
        }

        @SideOnly(Side.CLIENT) //Client side only
        public int getBlockTextureFromSide(int i){ //Tells it which texture from the sprite sheet
        return 64 ;
        }
        
    }

 

 

Hopefully one of you can tell me what is wrong and how to change it. Would I just need to rename some of the variables or something??? Do I really have to make each block seperately??? Is there a way to make each block in my inventory change per-colour???

 

Any help would be appreciated

No signature for you!

Posted

Your guess is correct. You only get 4 bits of metadata per block. Wool uses these 4 bits to encode the 16 different colours, and stairs use them to encode the orientation. You can't use them for both at the same time.

 

You have a couple of options:

 

* Use a different block ID for each orientation, leaving the metadata free for the colour. This is probably the simplest solution.

 

* Attach a TileEntity subclass to your block, and store the colour and/or the orientation there. This is more complicated to set up, but it lets you store an unlimited amount of extra information.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.