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

I have structures that spawn in the Nether, albeit incorreclty.

Here is the code I use to determine whether a structure can spawn at a certain position.

 

        //Offsets the structure to even ground level
        protected boolean offsetToEvenGround(World world, StructureBoundingBox structureBB, int yOffset)
        {
            if(hPos >= 0)
            {
                return true;
            }
            else
            {
                int i = 0;
                int j = 0;
                BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();

                for(int k = boundingBox.minZ; k <= boundingBox.maxZ; ++k)
                {
                    for(int l = boundingBox.minX; l <= boundingBox.maxX; ++l)
                    {
                        pos.setPos(l, boundingBox.maxY, k);

                        if(structureBB.isVecInside(pos))
                        {
                            Tuple<BlockPos, Boolean> tuple = getSuitableGroundPos(world, pos);

                            if(!tuple.getSecond())
                            {
                                return false;
                            }

                            i += tuple.getFirst().getY();
                            j++;
                        }
                    }
                }

                if(j == 0)
                {
                    return false;
                }
                else
                {
                    hPos = i / j;
                    boundingBox.offset(0, hPos - boundingBox.minY + yOffset, 0);
                    return true;
                }
            }
        }
        
        //My version on World::getTopSolidOrLiquidBlock
        //Returns this position and whether it is suitable.
        public Tuple<BlockPos, Boolean> getSuitableGroundPos(World world, BlockPos pos)
        {
            boolean isSuitable = false;

            while(!isSuitable && pos.getY() > 32)
            {
                Block block = world.getBlockState(pos).getBlock();
                
                if(world.isAirBlock(pos.up()) && block.isBlockSolid(world, pos, EnumFacing.DOWN) && block != Blocks.NETHER_BRICK && block != Blocks.NETHER_BRICK_FENCE && block != Blocks.NETHER_BRICK_STAIRS)
                {
                    isSuitable = true;
                }

                pos = pos.down();
            }

            return new Tuple<>(pos.up(), isSuitable);
        }
    }

 

It should be getting the average ground level at a certain position based on the size of the structure but, sometimes it places the structure in the air, ground or walls.

This is where you need a debugger. Set breakpoints both inside and outside your loops, then step through a couple iterations looking at the variable values. After convincing yourself that the variables are being assigned in the right places and used in the right tests, remove the outer breakpoints and set one inside the approval branch.

 

Run until the method hits it. Look at the conditions that got you there. If those are sane, then look at how your approved coords are translated/transmitted to the construction method. Somewhere along the way, palm should hit face. You'll see it live in the debugger much more easily than we can in dry code.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.