Jump to content

[1.5.2] [Forge] Structure Spawning


CrusoCraruso

Recommended Posts

Hey guys!

 

I have some problems spawning a test structure in the overworld.

 

 

WorldGenerator for the structure

 

 

 

 /*
*** MADE BY MITHION'S .SCHEMATIC TO JAVA CONVERTING TOOL v1.6 ***
*/

package "mypackage";

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class teststructure extends WorldGenerator
{
protected int[] GetValidSpawnBlocks() {
	return new int[] {
	};
}

public boolean LocationIsValidSpawn(World world, int i, int j, int k){
	int distanceToAir = 0;
	int checkID = world.getBlockId(i, j, k);

	while (checkID != 0){
		distanceToAir++;
		checkID = world.getBlockId(i, j + distanceToAir, k);
	}

	if (distanceToAir > 3){
		return false;
	}
	j += distanceToAir - 1;

	int blockID = world.getBlockId(i, j, k);
	int blockIDAbove = world.getBlockId(i, j+1, k);
	int blockIDBelow = world.getBlockId(i, j-1, k);
	for (int x : GetValidSpawnBlocks()){
		if (blockIDAbove != 0){
			return false;
		}
		if (blockID == x){
			return true;
		}else if (blockID == Block.dirt.blockID && blockIDBelow == x){
			return true;
		}
	}
	return false;
}

public teststructure() { }

public boolean generate(World world, Random rand, int i, int j, int k) {
	//check that each corner is one of the valid spawn blocks
	if(!LocationIsValidSpawn(world, i, j, k) || !LocationIsValidSpawn(world, i + 5, j, k) || !LocationIsValidSpawn(world, i + 5, j, k + 5) || !LocationIsValidSpawn(world, i, j, k + 5))
	{
		return false;
	}

	world.setBlock(i + 0, j + 0, k + 0, 1);
	world.setBlock(i + 0, j + 0, k + 5, 1);
	world.setBlock(i + 0, j + 1, k + 0, 1);
	world.setBlock(i + 0, j + 1, k + 5, 1);
	world.setBlock(i + 0, j + 2, k + 0, 1);
	world.setBlock(i + 0, j + 2, k + 1, 1);
	world.setBlock(i + 0, j + 2, k + 2, 1);
	world.setBlock(i + 0, j + 2, k + 3, 1);
	world.setBlock(i + 0, j + 2, k + 4, 1);
	world.setBlock(i + 0, j + 2, k + 5, 1);
	world.setBlock(i + 0, j + 3, k + 1, 1);
	world.setBlock(i + 0, j + 3, k + 2, 1);
	world.setBlock(i + 0, j + 3, k + 3, 1);
	world.setBlock(i + 0, j + 3, k + 4, 1);
	world.setBlock(i + 1, j + 0, k + 0, 1);
	world.setBlock(i + 1, j + 0, k + 5, 1);
	world.setBlock(i + 1, j + 1, k + 0, 1);
	world.setBlock(i + 1, j + 1, k + 5, 1);
	world.setBlock(i + 1, j + 2, k + 0, 1);
	world.setBlock(i + 1, j + 2, k + 1, 1);
	world.setBlock(i + 1, j + 2, k + 2, 1);
	world.setBlock(i + 1, j + 2, k + 3, 1);
	world.setBlock(i + 1, j + 2, k + 4, 1);
	world.setBlock(i + 1, j + 2, k + 5, 1);
	world.setBlock(i + 1, j + 3, k + 1, 1);
	world.setBlock(i + 1, j + 3, k + 2, 1);
	world.setBlock(i + 1, j + 3, k + 3, 1);
	world.setBlock(i + 1, j + 3, k + 4, 1);
	world.setBlock(i + 2, j + 0, k + 0, 1);
	world.setBlock(i + 2, j + 0, k + 5, 1);
	world.setBlock(i + 2, j + 1, k + 0, 1);
	world.setBlock(i + 2, j + 1, k + 5, 1);
	world.setBlock(i + 2, j + 2, k + 0, 1);
	world.setBlock(i + 2, j + 2, k + 1, 1);
	world.setBlock(i + 2, j + 2, k + 2, 1);
	world.setBlock(i + 2, j + 2, k + 3, 1);
	world.setBlock(i + 2, j + 2, k + 4, 1);
	world.setBlock(i + 2, j + 2, k + 5, 1);
	world.setBlock(i + 2, j + 3, k + 0, 1);
	world.setBlock(i + 2, j + 3, k + 1, 1);
	world.setBlock(i + 2, j + 3, k + 2, 1);
	world.setBlock(i + 2, j + 3, k + 3, 1);
	world.setBlock(i + 2, j + 3, k + 4, 1);
	world.setBlock(i + 2, j + 3, k + 5, 1);
	world.setBlock(i + 3, j + 0, k + 0, 1);
	world.setBlock(i + 3, j + 0, k + 5, 1);
	world.setBlock(i + 3, j + 1, k + 0, 1);
	world.setBlock(i + 3, j + 1, k + 5, 1);
	world.setBlock(i + 3, j + 2, k + 0, 1);
	world.setBlock(i + 3, j + 2, k + 1, 1);
	world.setBlock(i + 3, j + 2, k + 2, 1);
	world.setBlock(i + 3, j + 2, k + 3, 1);
	world.setBlock(i + 3, j + 2, k + 4, 1);
	world.setBlock(i + 3, j + 2, k + 5, 1);
	world.setBlock(i + 3, j + 3, k + 0, 1);
	world.setBlock(i + 3, j + 3, k + 1, 1);
	world.setBlock(i + 3, j + 3, k + 2, 1);
	world.setBlock(i + 3, j + 3, k + 3, 1);
	world.setBlock(i + 3, j + 3, k + 4, 1);
	world.setBlock(i + 3, j + 3, k + 5, 1);
	world.setBlock(i + 4, j + 0, k + 0, 1);
	world.setBlock(i + 4, j + 0, k + 5, 1);
	world.setBlock(i + 4, j + 1, k + 0, 1);
	world.setBlock(i + 4, j + 1, k + 5, 1);
	world.setBlock(i + 4, j + 2, k + 0, 1);
	world.setBlock(i + 4, j + 2, k + 1, 1);
	world.setBlock(i + 4, j + 2, k + 2, 1);
	world.setBlock(i + 4, j + 2, k + 3, 1);
	world.setBlock(i + 4, j + 2, k + 4, 1);
	world.setBlock(i + 4, j + 2, k + 5, 1);
	world.setBlock(i + 4, j + 3, k + 1, 1);
	world.setBlock(i + 4, j + 3, k + 2, 1);
	world.setBlock(i + 4, j + 3, k + 3, 1);
	world.setBlock(i + 4, j + 3, k + 4, 1);
	world.setBlock(i + 5, j + 0, k + 0, 1);
	world.setBlock(i + 5, j + 0, k + 5, 1);
	world.setBlock(i + 5, j + 1, k + 0, 1);
	world.setBlock(i + 5, j + 1, k + 5, 1);
	world.setBlock(i + 5, j + 2, k + 0, 1);
	world.setBlock(i + 5, j + 2, k + 1, 1);
	world.setBlock(i + 5, j + 2, k + 2, 1);
	world.setBlock(i + 5, j + 2, k + 3, 1);
	world.setBlock(i + 5, j + 2, k + 4, 1);
	world.setBlock(i + 5, j + 2, k + 5, 1);
	world.setBlock(i + 5, j + 3, k + 1, 1);
	world.setBlock(i + 5, j + 3, k + 2, 1);
	world.setBlock(i + 5, j + 3, k + 3, 1);
	world.setBlock(i + 5, j + 3, k + 4, 1);

	return true;
}
}

 

 

 package "mypackage";

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.IWorldGenerator;


public class WorldGeneratorSurface implements IWorldGenerator {

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
switch(world.provider.dimensionId){
//case -1: generateNether(world, random,chunkX*16,chunkZ*16);
case 0 : generateSurface(world, random,chunkX*16,chunkZ*16);
}
}


private void generateSurface(World world, Random random, int BlockX, int BlockZ) {
for(int i =0; i<40;i++){
int Xcoord = BlockX + random.nextInt(16);
int Zcoord = BlockZ + random.nextInt(16);
int Ycoord = random.nextInt(16);

(new WorldGenMinable(Main."someore".blockID, 4)).generate(world, random, Xcoord, Ycoord, Zcoord);

}
}

private void generateSurface1(World world, Random rand, int i, int j)
{
  for(int k = 0; k<1; k++)
  {
int RandPosX = i + rand.nextInt(16);
int RandPosY = rand.nextInt(128);	
int RandPosZ = j + rand.nextInt(16);
(new teststructure()).generate(world, rand, RandPosX, RandPosY, RandPosZ);
  }
}
}

 

 

And in my main file:

 

 GameRegistry.registerWorldGenerator(new WorldGeneratorSurface());

 

 

I get no errors, but I cant find this structure anywhere. Does anybody know what I did wrong?

Link to comment
Share on other sites

But you're using a different method for generating your structure as you are your ore. You are calling generateStructure() for your ore in the case: 0 check, but from the code above it seems you're not calling generateStructure1() with your structure anywhere.

 

You need to call it from somewhere, be it the case statement of the end of the ore generating method.

Link to comment
Share on other sites

changed it now to this:

 

package "";

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.IWorldGenerator;


public class WorldGeneratorSurface implements IWorldGenerator {

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
switch(world.provider.dimensionId){
//case -1: generateNether(world, random,chunkX*16,chunkZ*16);
case 0 : generateSurface(world, random,chunkX*16,chunkZ*16);
}
}


private void generateSurface(World world, Random random, int BlockX, int BlockZ) {
for(int i =0; i<40;i++){
int Xcoord = BlockX + random.nextInt(16);
int Zcoord = BlockZ + random.nextInt(16);
int Ycoord = random.nextInt(16);

(new WorldGenMinable(Main."".blockID, 4)).generate(world, random, Xcoord, Ycoord, Zcoord);

for(int k = 0; k<1; k++)
{
int Xcoord1 = BlockX + random.nextInt(16);
int Ycoord1 = random.nextInt(60);
int Zcoord1 = BlockZ + random.nextInt(16);

(new teststructure()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);

}
}
}}

 

still cant find it. Do you notice something else wrong?

Link to comment
Share on other sites

ok guys I got it now. I post the code so maybe I can help someone.

 

WorldGenerator:

 

 package "package";

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.IWorldGenerator;


public class WorldGeneratorSurface implements IWorldGenerator {

public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.dimensionId)
{
  //case -1: generateNether(world, random, chunkX*16, chunkZ*16);
  case 0: generateSurface(world, random, chunkX*16, chunkZ*16);
}

}

private void generateSurface(World world, Random rand, int l, int j)
{

for(int i =0; i<40; i++){
int Xcoord = l + rand.nextInt(16);
int Zcoord = j + rand.nextInt(16);
int Ycoord = rand.nextInt(16);

(new WorldGenMinable(Main.someore.blockID, 4)).generate(world, rand, Xcoord, Ycoord, Zcoord);

  for(int k = 0; k < 1; k++)
  {
int RandPosX = l + rand.nextInt(16);
int RandPosY = rand.nextInt(128);	
int RandPosZ = j + rand.nextInt(16);
(new teststructure()).generate(world, rand, RandPosX, RandPosY, RandPosZ);



}}}}

 

teststructure:

 

package""package;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class teststructure extends WorldGenerator {

public teststructure()
{

}

public boolean generate(World world, Random rand, int x, int y, int z)
{
if(world.getBlockId(x, y, z)!= Block.sand.blockID || world.getBlockId(x, y + 1, z)!= 0)
   {
   return false;
   }

world.setBlock(x, y + 1, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 1, z, Main.someblock.blockID);
world.setBlock(x, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 2, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 3, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 3, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 3, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 3, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 4, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 4, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 4, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 4, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 5, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 5, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 5, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 5, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 6, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 6, z, Main.someblock.blockID);
world.setBlock(x, y + 7, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 7, z, Main.someblock.blockID);
world.setBlock(x, y + 6, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 6, z, Main.someblock.blockID);
world.setBlock(x, y + 3, z, Main.someblock.blockID);

return true;
   }  
}

 

Code: "k < 1" 1 is the rarity. I placed 1 so I could find it fast when it spawns. With 1 you have min 1 of your structure per chunk.

          "if(world.getBlockId(x, y, z)!= Block.sand.blockID || world.getBlockId(x, y + 1, z)!= 0)" Block.sand.blockID is on what block it spawns. In this case sand

Link to comment
Share on other sites

Why don't you use for loops for the block placement???

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

for(int x1 = -2; x1 < 2; x1++)
{
    world.setBlock(x-x1,y,z, BLOCK_OF_YOUR_CHOISE.blockID)
}

That code will spawn a straigt line of five blocks of your choise.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ASIABET adalah pilihan terbaik bagi Anda yang mencari slot gacor hari ini dengan server Rusia dan jackpot menggiurkan. Berikut adalah beberapa alasan mengapa Anda harus memilih ASIABET: Slot Gacor Hari Ini Kami menyajikan koleksi slot gacor terbaik yang diperbarui setiap hari. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan setiap kali Anda memutar gulungan. Server Rusia yang Handal Kami menggunakan server Rusia yang handal dan stabil untuk memastikan kelancaran dan keadilan dalam setiap putaran permainan. Anda dapat bermain dengan nyaman tanpa khawatir tentang gangguan atau lag. Jackpot Menggiurkan Nikmati kesempatan untuk memenangkan jackpot menggiurkan yang dapat mengubah hidup Anda secara instan. Dengan hadiah-hadiah besar yang ditawarkan, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.
    • Sonic77 adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot yang unggul dengan akun pro Swiss terbaik. Berikut adalah beberapa alasan mengapa Anda harus memilih Sonic77: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik dari provider terkemuka. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan. Akun Pro Swiss Berkualitas Kami menawarkan akun pro Swiss yang berkualitas dan terpercaya. Dengan akun ini, Anda dapat menikmati berbagai keuntungan eksklusif dan fasilitas premium yang tidak tersedia untuk akun reguler.
    • SV388 SITUS RESMI SABUNG AYAM 2024   Temukan situs resmi untuk sabung ayam terpercaya di tahun 2024 dengan SV388! Dengan layanan terbaik dan pengalaman bertaruh yang tak tertandingi, SV388 adalah tempat terbaik untuk pecinta sabung ayam. Daftar sekarang untuk mengakses arena sabung ayam yang menarik dan nikmati kesempatan besar untuk meraih kemenangan. Jelajahi sensasi taruhan yang tak terlupakan di tahun ini dengan SV388! [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]   JURAGANSLOT88 SITUS JUDI SLOT ONLINE TERPERCAYA 2024 Jelajahi pengalaman judi slot online terpercaya di tahun 2024 dengan JuraganSlot88! Sebagai salah satu situs terkemuka, JuraganSlot88 menawarkan berbagai pilihan permainan slot yang menarik dengan layanan terbaik dan keamanan yang terjamin. Daftar sekarang untuk mengakses sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan JuraganSlot88 [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
    • Slot Bank MEGA atau Daftar slot Bank MEGA bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
  • Topics

×
×
  • Create New...

Important Information

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