Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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!

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.

  • Author

Thank you very much  ;D I guess I'll go for the easy route as I know how to do that (not so good with the TileEntity stuff).

No signature for you!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.