Jump to content

One little question


Nicba1010

Recommended Posts

Um. What?

 

The things don't relate to each other at all. Bit wise operator are just like normal operators.  AND, OR, XOR, etc.

 

I think what you mean is using bit wise operators in conjunction with metadata.

 

Block metadata is one byte (0 to 15, or 0000 to 1111). You'd need two bits of data to save the orientation of the door, and one bit of data to save whether the door is open or not.

 

 

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

Hi

 

Some background

http://www.leepoint.net/notes-java/data/expressions/bitops.html

 

This code from vanilla might help you figure it out too

 

    public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int wx, int wy, int wz, int side)
    {
        if (side != 1 && side != 0)
        {
            int metadata = this.getFullMetadata(par1IBlockAccess, wx, wy, wz);
            int doorFacingDirection = metadata & 3;
            boolean doorIsOpen = (metadata & 4) != 0;
            boolean flipLeftRight = false;
            boolean topHalf = (metadata &  != 0;

            if (doorIsOpen)
            {
                if (doorFacingDirection == 0 && side == 2)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 1 && side == 5)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 2 && side == 3)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 3 && side == 4)
                {
                    flipLeftRight = !flipLeftRight;
                }
            }
            else
            {
                if (doorFacingDirection == 0 && side == 5)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 1 && side == 3)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 2 && side == 4)
                {
                    flipLeftRight = !flipLeftRight;
                }
                else if (doorFacingDirection == 3 && side == 2)
                {
                    flipLeftRight = !flipLeftRight;
                }

                if ((metadata & 16) != 0)
                {
                    flipLeftRight = !flipLeftRight;
                }
            }

            return topHalf ? this.upperIcon[flipLeftRight ? 1 : 0] : this.lowerIcon[flipLeftRight ? 1 : 0];
        }
        else
        {
            return this.lowerIcon[0];
        }
    }

 

-TGG

 

Link to comment
Share on other sites

Thx shield and grey.

Yes shield that is what I meant :)

TGG thx for that piece, it was easy to figure out once I had an example.

Just so others can see:

 

    private boolean isDoorOpen(World world, int x, int y, int z) {
        int metadata = world.getBlockMetadata(x, y, z);
        return (metadata & 4) != 0;
    }

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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