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

Hi.

 

I have a WorldGenerator that generates a chest, however, I can't seem to set the direction it is pointing.  I've tried this to set a random direction:

 

this.setBlockAndNotifyAdequately(world, x, y, z, Blocks.chest, random.nextInt(5) + 2);

 

But the chest is always pointing South.

 

Any ideas?  I'm sure it's a pretty simple fix, I'm just missing it.

once you set the block you have to set the block metadata after using world.setBlockMetadataWithNotify(). I'm not sure if this works with chests but it should work

The proud(ish) developer of Ancients

world.setBlock(x, y, z, Blocks.chest,  random.nextInt(5)+2, 2)

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

  • Author

world.setBlock(x, y, z, Blocks.chest,  random.nextInt(5)+2, 2)

 

Thanks, that did the trick.

 

The metadata for chests are 2-5. Your method generates values between 2 and 6. Also: what does that method do?

 

Thanks for catching that.  The method comes from WorldGenerator:

 

protected void setBlockAndNotifyAdequately(World p_150516_1_, int p_150516_2_, int p_150516_3_, int p_150516_4_, Block p_150516_5_, int p_150516_6_)
    {
        if (this.doBlockNotify)
        {
            p_150516_1_.setBlock(p_150516_2_, p_150516_3_, p_150516_4_, p_150516_5_, p_150516_6_, 3);
        }
        else
        {
            p_150516_1_.setBlock(p_150516_2_, p_150516_3_, p_150516_4_, p_150516_5_, p_150516_6_, 2);
        }
    }

 

It seems to place the block and either use flag 3 or 2 depending on the doBlockNotify, which is false by default.  So in essence it *should* have done exactly as Eternaldoom suggested, but it didn't seem to be working for me.

 

The problem is that chests automatically set their own metadata once placed in the world, so the value you use in the initial setBlock is actually ignored - to get around the problem, you just have to set the metadata after the block is placed, as memcallen mentioned earlier.

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.