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

Hey guys I have only one question.

Since I have never worked with bitwise operators :( I can't figure is out myself.

How would I check if a door is open?

Sincerely, Roberto

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.

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

 

  • Author

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;
    }

 

Guest
This topic is now closed to further replies.

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.