Jump to content

Custom Dungeon spawning right next to each other?


TLHPoE

Recommended Posts

So I'm currently trying to spawn my custom dungeon in separate places, but they 100% of the time, spawn right next to each other and intersect.

 

Segment of code from my IWorldGenerator:

public void generateSurface(World world, Random random, int chunkX, int chunkZ)
{

	for(int i = 0;i < 2;i++)
	{

		int x = chunkZ + random.nextInt(16) - random.nextInt(16);
		int y = random.nextInt(64);
		int z = chunkZ + random.nextInt(16) - random.nextInt(16);

		WorldGenGoldDungeons gen = new WorldGenGoldDungeons();

		if(gen.generate(world, random, x, y, z))
		{

			System.out.println("X: " + x + "Y: " +  y + "Z: " + z);

		}

	}

}

 

And here is my WorldGenerator class:

 

package net.gloriarpg.worldgen;

import java.util.Random;

import net.gloriarpg.helper.BlockHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.DungeonHooks;


public class WorldGenGoldDungeons extends WorldGenerator
{

    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        byte b0 = 3;
        int l = par2Random.nextInt(2) + 2;
        int i1 = par2Random.nextInt(2) + 2;
        int j1 = 0;
        int k1;
        int l1;
        int i2;
        
        int plank = par2Random.nextInt(2);

        for (k1 = par3 - l - 1; k1 <= par3 + l + 1; ++k1)
        {
            for (l1 = par4 - 1; l1 <= par4 + b0 + 1; ++l1)
            {
                for (i2 = par5 - i1 - 1; i2 <= par5 + i1 + 1; ++i2)
                {
                    Material material = par1World.getBlockMaterial(k1, l1, i2);

                    if (l1 == par4 - 1 && !material.isSolid())
                    {
                        return false;
                    }

                    if (l1 == par4 + b0 + 1 && !material.isSolid())
                    {
                        return false;
                    }

                    if ((k1 == par3 - l - 1 || k1 == par3 + l + 1 || i2 == par5 - i1 - 1 || i2 == par5 + i1 + 1) && l1 == par4 && par1World.isAirBlock(k1, l1, i2) && par1World.isAirBlock(k1, l1 + 1, i2))
                    {
                        ++j1;
                    }
                }
            }
        }

        if (j1 >= 1 && j1 <= 5)
        {
            for (k1 = par3 - l - 1; k1 <= par3 + l + 1; ++k1)
            {
                for (l1 = par4 + b0; l1 >= par4 - 1; --l1)
                {
                    for (i2 = par5 - i1 - 1; i2 <= par5 + i1 + 1; ++i2)
                    {
                        if (k1 != par3 - l - 1 && l1 != par4 - 1 && i2 != par5 - i1 - 1 && k1 != par3 + l + 1 && l1 != par4 + b0 + 1 && i2 != par5 + i1 + 1)
                        {
                            par1World.setBlockToAir(k1, l1, i2);
                        }
                        else if (l1 >= 0 && !par1World.getBlockMaterial(k1, l1 - 1, i2).isSolid())
                        {
                            par1World.setBlockToAir(k1, l1, i2);
                        }
                        else if (par1World.getBlockMaterial(k1, l1, i2).isSolid())
                        {
                            if (l1 == par4 - 1 && par2Random.nextInt(4) != 0)
                            {
                                par1World.setBlock(k1, l1, i2, Block.planks.blockID, plank, 2);
                            }
                            else
                            {
                                par1World.setBlock(k1, l1, i2, Block.planks.blockID, 0, 2);
                            }
                        }
                    }
                }
            }

            k1 = 0;

            while (k1 < 2)
            {
                l1 = 0;

                while (true)
                {
                    if (l1 < 3)
                    {
                        label101:
                        {
                            i2 = par3 + par2Random.nextInt(l * 2 + 1) - l;
                            int j2 = par5 + par2Random.nextInt(i1 * 2 + 1) - i1;

                            if (par1World.isAirBlock(i2, par4, j2))
                            {
                                int k2 = 0;

                                if (par1World.getBlockMaterial(i2 - 1, par4, j2).isSolid())
                                {
                                    ++k2;
                                }

                                if (par1World.getBlockMaterial(i2 + 1, par4, j2).isSolid())
                                {
                                    ++k2;
                                }

                                if (par1World.getBlockMaterial(i2, par4, j2 - 1).isSolid())
                                {
                                    ++k2;
                                }

                                if (par1World.getBlockMaterial(i2, par4, j2 + 1).isSolid())
                                {
                                    ++k2;
                                }

                                if (k2 == 1)
                                {
                                    par1World.setBlock(i2, par4, j2, BlockHelper.goldChest.blockID, 0, 2);
                                    TileEntityChest tileentitychest = (TileEntityChest)par1World.getBlockTileEntity(i2, par4, j2);

                                    if (tileentitychest != null)
                                    {
                                        ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
                                        WeightedRandomChestContent.generateChestContents(par2Random, info.getItems(par2Random), tileentitychest, info.getCount(par2Random));
                                    }

                                    break label101;
                                }
                            }

                            ++l1;
                            continue;
                        }
                    }

                    ++k1;
                    break;
                }
            }

            par1World.setBlock(par3, par4, par5, Block.mobSpawner.blockID, 0, 2);
            TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)par1World.getBlockTileEntity(par3, par4, par5);

            if (tileentitymobspawner != null)
            {
                tileentitymobspawner.getSpawnerLogic().setMobID(this.pickMobSpawner(par2Random));
            }
            else
            {
                System.err.println("Failed to fetch mob spawner entity at (" + par3 + ", " + par4 + ", " + par5 + ")");
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    
    private String pickMobSpawner(Random par1Random)
    {
    	
        return DungeonHooks.getRandomDungeonMob(par1Random);
        
    }

}

 

Kain

Link to comment
Share on other sites

How do you set your random in your IWorldGenerator?

 

Also it does not appear you check to see whether or not you should be generating in a given chunk.  You're telling it to generate and passing a random, but not figuring out if you should.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Here's the whole IWorldGenerator:

 

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	switch(world.provider.dimensionId)
	{

	case(0):
	{

		this.generateSurface(world, random, chunkX, chunkZ);
		break;

	}

	}

}

public void generateSurface(World world, Random random, int chunkX, int chunkZ)
{

	for(int i = 0;i < 2;i++)
	{

		int x = chunkZ + random.nextInt(16) - random.nextInt(16);
		int y = random.nextInt(64);
		int z = chunkZ + random.nextInt(16) - random.nextInt(16);

		WorldGenGoldDungeons gen = new WorldGenGoldDungeons();

		if(gen.generate(world, random, x, y, z))
		{

			System.out.println("X: " + x + "Y: " +  y + "Z: " + z);

		}

	}

}

 

 

I'll go fix that.

Kain

Link to comment
Share on other sites

WorldGenGoldDungeons gen = new WorldGenGoldDungeons();

 

You should move this to a class-level variable, rather than creating a new one every time a chunk is generated.

 

Also, you may be interested in this:

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/worldgen/PlaceTraps.java

 

I use math to determine where things spawn, rather than randoms.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Turning the Tables: My Journey to Reclaim Stolen Bitcoins with Expert Help. When my Bitcoin wallet was hacked and my entire cryptocurrency portfolio was stolen, I felt utterly devastated and hopeless. Having worked hard to build up my digital assets, the sudden loss was gut-wrenching. It felt like my financial future had been ripped away in an instant, leaving me overwhelmed by a sense of betrayal and despair. In my search for help, I discovered TECH CYBER FORCE Recovery, a renowned cybersecurity firm specializing in cryptocurrency recovery. I was met with professionalism and empathy from my first contact with them. The team demonstrated a steadfast commitment to helping me retrieve my stolen Bitcoins. They understood the emotional toll of my situation and approached my case with genuine concern. TECH CYBER FORCE Recovery swung into action immediately, leveraging its extensive expertise in blockchain forensics and hacker tracking techniques. Their process was meticulous. They analyzed my transaction history, followed the digital trail left by the hackers, and worked diligently to pinpoint the location of the stolen funds. I was impressed by their technical prowess; they employed advanced cryptographic methods and strategic negotiations with the perpetrators, all while keeping me informed about their progress. The recovery process was complex and fraught with challenges. However, the tenacity displayed by the team was truly awe-inspiring. They navigated cryptocurrency crime's murky and ever-evolving landscape with skill and determination. After a series of strategic moves, they managed to recover the majority of my Bitcoins successfully.  
    • I removed giacomos_hud, oculus, (dont know what you mean with iris), enhanced_boss_bars, epicfight and essential.  Server still doesnt want to boot. new logs after removing: https://pastebin.com/LuM2PFtN I dont quite understand the "server side" and "client side" difference..
    • There are client side only mods in your server files   Remove giacomos_hud, oculus, iris, enhanced_boss_bars and epicfight You can keep these mods in your client Maybe also remove essentials
    • Here is my Log with java 17: https://pastebin.com/RPdWSjwq
    • Been working on creating a server for this mod, but i keep getting this error over and over again.  I have tried updating/changing the Forge launcher, Removing/replacing the ops.json and whitelist.json folders, and removing certain mods. Crash report log: https://pastebin.com/Bu046cVq Debug.log https://pastebin.com/7hKm40ke Latest.log https://pastebin.com/nCRLUH3b any help would be great thanks!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.