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

Hello.

 

I'm creating a dungeon dimension. The layout of the dungeon is generated using a simple loop that stops itself after the max amount of rooms has been reached. However, it only ever generates about 4 rooms and then stops itself???

 

Is there a way to generate the layout without it stopping itself whilst still being able to use the seed of the world to generate the layout? Another class perhaps? Maybe chunkprovider isn't the greatest place to do this...

 

Here is a snip of my code:

 

public ChunkProviderDungeon(World worldIn, long seed)
    {
            this.worldObj = worldIn;
            this.rand = new Random(seed);
            this.roomamount = rand.nextInt(25) + 50;
            generateLayout();
    }

    private static void generateLayout() {
        Point start = new Point(1,0);
        pointlist.add(start);
        roomTry(1,0);
    }
    
    private static void roomTry(int x, int z) {
        int connections = rand.nextInt(3);
        for(int i=0; i < connections; i++){
            int direction = rand.nextInt(3);
            if(direction == 0){
                Point point = new Point(x + 1, z);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x + 1, z);
                }
            }else if(direction == 1){
                Point point = new Point(x - 1, z);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x - 1, z);
                }
            }else if(direction == 2){
                Point point = new Point(x, z + 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z + 1);
                }
            }else if(direction == 3){
                Point point = new Point(x, z - 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z - 1);
                }
            }else{
                Point point = new Point(x, z - 1);
                if(!pointlist.contains(point)){
                    pointlist.add(point);
                    --roomamount;
                }
                System.out.println(roomamount);
                if(roomamount > 0){
                    roomTry(x, z - 1);
                }
            }
        }
    }

    public static List<Point> getPoints(){
        return pointlist;
        
    }

 

 

The list of points is then used to generate the dungeon.

 

When I run the code I get print outs of 56, 55, 54, 53, 52 and then no more. It just stops itself. Any reason why?

 

Thanks in advance.

  • Author

OMG DERP. It was possible for a room to have 0 connections making the entire loop stop. Sometimes I question my intelligence. Can a mod just remove this entire thread ?? Sorry for the pointless post.

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.