One little question

Recommended Posts

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

Share on other sites

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.

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

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

Share on other sites

Hi

Some background

```    public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int wx, int wy, int wz, int side)
{
if (side != 1 && side != 0)
{
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

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) {
return (metadata & 4) != 0;
}
```

Share on other sites

This topic is now closed to further replies.

• Posts

• I think I just solved it, I took a break and did some C++ in Unreal - and it kind of dawned upon me that I'm doing this wrong (duh) and should essentially treat BlockState like a struct, where you don't directly manipulate properties. Maybe I'm overthinking it and this isn't really the case, but this works; if (!level.getBlockState(pos).getValue(COLOR_SET)) { BlockState newState = state.setValue(LANTERNCOLOR, this.getBlockColor()); newState = newState.setValue(COLOR_SET, true); level.setBlock(pos, newState, 2); } Just looking at that and it's a bit of a facepalm, makes sense. Edit: This may be solved, but I'm still open to suggestions if there's a better way of doing this. Alternatively how to dynamically change the color of a particle so I don't have to create one particle for every color.
• EntityViewRenderEvent does not seem to exist in 1.20.1
• oh but isn't minecraft forge the launcher not the api
• I created my own modpack just for mainly entities right now and im having issues with only a handful of the mobs. is there a way someone could help go over my work and check whats wrong? its a file

• Who's Online (See full list)

×

• Activity

×
• Create New...