I was trying to do something that I learned in my basic programming class. long story short it didnt work like I planed and just gave the message 0/0/0. not the actual x/y/z coords
long story short it didnt work like I planed and just gave the message 0/0/0. not the actual x/y/z coords
Yep, I know - it was a rhetorical question
The static keyword is NOT the friend you (and every inexperienced programmer, including myself at one point) think it is. I recommend you NEVER use it until such time as you fully understand the ramifications, especially for class fields.
Irrespective of the use of static, no variable is magically linked to another - just because you have a field named 'xCoord' does not mean it will contain the value of a coordinate on the x-axis (which coordinate? belonging to what? etc.). Of course, I'm sure you realize that now.
Anyway, might I suggest you spend some time revisiting the basics? I know it's a drag, but it's really important if you want to become any good at coding, and not just in Java. Probably around 80-90% of the 'basics' that you learn in Java will serve you just as well in any programming language.
I was trying to do something that I learned in my basic programming class. long story short it didnt work like I planed and just gave the message 0/0/0. not the actual x/y/z coords
Okay. That's because I don't think you'd actually initialized the variables to the actual x/y/z coordinates. Your variable names are very difficult to grasp o.o This is why I hate copying from certain sections of vanilla code.
Take a look at this sample of my code:
public boolean generate(World par1World, Random par2Random, int x, int y, int z)
{
Random random = new Random();
int Ycoord1 = 0;
while (!par1World.isAirBlock(x, y+1, z) && y < 63)
{
y = y+1;
}
if (par1World.getBlock(x, y, z) != Blocks.grass && par1World.getBlock(x, y, z) != Blocks.dirt)
{
return false;
}
else
{
this.oldRuin(par1World, x, y, z);
}
return true;
}
I don't have a print statement in here, but if I was going to put one, I believe I would put it before the return true statement, using the x/y/z coordinates that I defined. I think. Don't quote me on it for sure, I'm used to 1.8 which uses a different system and haven't touched this code in ages lol
Okay, never mind what I put before- apparently I misunderstood XD I would heavily suggest using a different method from Vanilla's, or at least going through and replacing those variable names with ones that people can actually understand without their brains starting to sizzle lol
@JayZX535 Sorry mate, but there is no y-coordinate there, and the structure has not yet generated (though it probably will if the method returns true).
It's not at all like #generate - instead, that method is called to check if the structure is allowed to generate at the x/z location, usually in the sense of 'are there any other structures in neighboring chunks?' kind of way. Villages, Strongholds, etc. use it so that they don't generate too close to each other.
@JayZX535 Sorry mate, but there is no y-coordinate there, and the structure has not yet generated (though it probably will if the method returns true).
It's not at all like #generate - instead, that method is called to check if the structure is allowed to generate at the x/z location, usually in the sense of 'are there any other structures in neighboring chunks?' kind of way. Villages, Strongholds, etc. use it so that they don't generate too close to each other.
Ohhh, that makes a lot more sense! Then where the heck is the actual generate method?? O.o Is it even in there or did I just miss it??
This is why there are some portions of Vanilla code that are a royal pain in the rear to work with >.< All those variables with oh-so-specific names... >.<
Ok, so this is just checking where to spawn the structure, it isnt actually spawning it? That might explain why im not receiving any messages in the console.
public static class Start extends ChocolateStructureStart
{
private static final String __OBFID = "CL_00000452";
public Start() {}
public Start(World world, Random rand, int ChunkX, int ChunkZ)
{
super(ChunkX, ChunkZ);
StructureChocolateBridgePieces.Start start = new StructureChocolateBridgePieces.Start(rand, (ChunkX << 4) + 2, (ChunkZ << 4) + 2);
this.components.add(start);
start.buildComponent(start, this.components, rand);
ArrayList arraylist = start.field_74967_d;
while (!arraylist.isEmpty())
{
int k = rand.nextInt(arraylist.size());
ChocolateStructureComponent structurecomponent = (ChocolateStructureComponent)arraylist.remove(k);
structurecomponent.buildComponent(start, this.components, rand);
System.out.println("My Bridge structure generated at " + ChunkX + "/" + ChunkZ + " coordinates");
}
this.updateBoundingBox();
this.setRandomHeight(world, rand, 80, 110);
}
}
Ok, so this is just checking where to spawn the structure, it isnt actually spawning it? That might explain why im not receiving any messages in the console.
I think this is where it actually tells it to build, judging by the name:
You should probably take a look at your buildComponent function. See if there's an x/y/z coordinate there...
To be quite honest, if you're just building a bridge, you probably don't even need to use the village/stronghold/mineshaft system, which is what it looks like you've been using. Unless your bridge has randomization that occurs between structures (i.e. two villages may have different buildings and a different layout, strongholds have different layouts), you could probably get away with something simpler. I'm not sure offhand how 1.7.10 handles dungeons and temples, but you might want to look into those and see if they're simpler than this...
I probably dont. but i just want to use the village spawning system to make the bridge only spawn in mountains.
Ah, I see- but you can easily do that without using the village system! Take a look at my structure gen file (1.7.2 but should still be applicable): StructureGen.java
Under my generateSurface function, I have this if statement:
if (world.getBiomeGenForCoords(blockX, blockZ) == BiomeGenBase.plains)
{
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(5);
if (randomInt == 1)
{
int Xcoord1 = blockX + random.nextInt(16);
int Ycoord1 = random.nextInt(80);
int Zcoord1 = blockZ + random.nextInt(16);
(new OldRuin()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);
}
}
This if statement only generates the structures in the plains biome. You'd have to use the appropriate generation method for your world, but you could easily add in an if statement like that to select the biome without having to use the village generation system.
Of course it's totally up to you I'd just advise that you go with a simpler method, just because simple can be better, but then again, that's just me
I believe this will work now. Im lazy (im sure that will come around and bite me in the ass in the future) so i didnt really change much with my code. I've just guaranteed that the structure spawned while this was set on true (which im assuming lets it spawn in any biome) so now ive set it to false (I think this will either stop the structure from spawning or only allow it to spawn in the mountains).
protected boolean canSpawnStructureAtCoords(int ChunkX, int ChunkZ)
{
if (worldObj.getBiomeGenForCoords(ChunkX, ChunkZ) == BiomeGenChocolateBase.chocolateMountians)
{
int k = ChunkX >> 4;
int l = ChunkZ >> 4;
this.rand.setSeed((long)(k ^ l << 4) ^ this.worldObj.getSeed());
this.rand.nextInt();
return this.rand.nextInt(3) != 0 ? false : (ChunkX != (k << 4) + 4 + this.rand.nextInt(8) ? false : ChunkZ == (l << 4) + 4 + this.rand.nextInt(8));
}
return false;
}
I'm not surprised given your willy-nilly use of the bit-shift operators >> and <<. I assume you just copied that code from vanilla somewhere?
I suggest you look up what those operators do, and also compare your #canSpawnStructureAtCoords implementation with an actual vanilla implementation such as from MapGenVillage.Start.
@sky_01 Actually, rand.nextInt() DOES do something, even without assigning the result to anything - it progresses the RNG to the next value, so the value that would have been returned is now skipped. E.g. if the RNG would have produced the sequence (12, 8, 918, 25, ...), now when you ask for an int you will get 8 instead of 12, because 12 was already 'spent'. I doubt the OP was intentionally using it that way, of course, so your point remains
>> and << are like a proximity. I think its saying that the structure can spawn within 4 chunks of the biome, But it doesnt have to actually be with in the biome to spawn. or atleast thats my guess.
>> and << are like a proximity. I think its saying that the structure can spawn within 4 chunks of the biome, But it doesnt have to actually be with in the biome to spawn. or atleast thats my guess.
That is completely 100% incorrect. Please learn about bit shifting operators. That link is just a starting point - I suggest you take some time reading other articles and actually playing around with the operators, printing the results to the console, in order to learn how they work.
Alright, I'll start learning about it. Although one question, is there any sort of world gen class creator program? like you build a structure and then you export the structure as a class file?
Like Schematics? That's a mod / project of some sort that many people have used to do just that, but I'm not sure if it is still being maintained. Also, the code it outputs is terrible... you're much better off using #fillWithBlocks-like methods, in my opinion, than having a 'class' that contains nothing but 10,000+ lines of #setBlock. In the end, the result is the same, but it's sooo ugly... not to mention you can exceed file size limits with sufficiently large structures.
I'd like to do fillwithblocks but i dont understand structure generation enough yet to properly implement it. ive done the setblock so far.
If you don't want to do fillwithblocks, you could also use for loops to much the same effect.
for (z = 1, z < 5, z++)
{
for (x = 1, x < 5, x++)
{
//Do stuff (setblock, etc.)
}
}
You might want to double check this to make sure it's the right syntax because my brain is really dead and I'm likely to have put some stupid little mistake in there by accident, but this is the gist of it. If you want a y coordinate, you could always add a third for loop with the y coordinate.
There's nothing really to understand - #fillWithBlocks is just a method that calls #setBlock for you using for loops, so that you can create an arbitrarily large cube of the same block using like 10 lines of code (actually 1 line, because you don't have to repeat the method every time). Judicious use of such methods in combination with #setBlock for individual components is what creates a structure.
Take a look at some of the actual StructureComponent implementations - you don't need to get anywhere near that fancy / complicated to make it work, but you can see how they use various methods to drastically reduce the amount of code required to produce complex structures with any facing.
If your structure is not so big / complicated and you don't care about being able to rotate it, then individual #setBlock statements is fine.
I was trying to do something that I learned in my basic programming class. long story short it didnt work like I planed and just gave the message 0/0/0. not the actual x/y/z coords
Yep, I know - it was a rhetorical question
The static keyword is NOT the friend you (and every inexperienced programmer, including myself at one point) think it is. I recommend you NEVER use it until such time as you fully understand the ramifications, especially for class fields.
Irrespective of the use of static, no variable is magically linked to another - just because you have a field named 'xCoord' does not mean it will contain the value of a coordinate on the x-axis (which coordinate? belonging to what? etc.). Of course, I'm sure you realize that now.
Anyway, might I suggest you spend some time revisiting the basics? I know it's a drag, but it's really important if you want to become any good at coding, and not just in Java. Probably around 80-90% of the 'basics' that you learn in Java will serve you just as well in any programming language.
Okay. That's because I don't think you'd actually initialized the variables to the actual x/y/z coordinates. Your variable names are very difficult to grasp o.o This is why I hate copying from certain sections of vanilla code.
Take a look at this sample of my code:
I don't have a print statement in here, but if I was going to put one, I believe I would put it before the return true statement, using the x/y/z coordinates that I defined. I think. Don't quote me on it for sure, I'm used to 1.8 which uses a different system and haven't touched this code in ages lol
Okay, never mind what I put before- apparently I misunderstood XD I would heavily suggest using a different method from Vanilla's, or at least going through and replacing those variable names with ones that people can actually understand without their brains starting to sizzle lol
@JayZX535 Sorry mate, but there is no y-coordinate there, and the structure has not yet generated (though it probably will if the method returns true).
It's not at all like #generate - instead, that method is called to check if the structure is allowed to generate at the x/z location, usually in the sense of 'are there any other structures in neighboring chunks?' kind of way. Villages, Strongholds, etc. use it so that they don't generate too close to each other.
Ohhh, that makes a lot more sense! Then where the heck is the actual generate method?? O.o Is it even in there or did I just miss it??
This is why there are some portions of Vanilla code that are a royal pain in the rear to work with >.< All those variables with oh-so-specific names... >.<
Ok, so this is just checking where to spawn the structure, it isnt actually spawning it? That might explain why im not receiving any messages in the console.
I think this is where it actually tells it to build, judging by the name:
You should probably take a look at your buildComponent function. See if there's an x/y/z coordinate there...
To be quite honest, if you're just building a bridge, you probably don't even need to use the village/stronghold/mineshaft system, which is what it looks like you've been using. Unless your bridge has randomization that occurs between structures (i.e. two villages may have different buildings and a different layout, strongholds have different layouts), you could probably get away with something simpler. I'm not sure offhand how 1.7.10 handles dungeons and temples, but you might want to look into those and see if they're simpler than this...
I probably dont. but i just want to use the village spawning system to make the bridge only spawn in mountains.
Ah, I see- but you can easily do that without using the village system! Take a look at my structure gen file (1.7.2 but should still be applicable):
StructureGen.java
Under my generateSurface function, I have this if statement:
This if statement only generates the structures in the plains biome. You'd have to use the appropriate generation method for your world, but you could easily add in an if statement like that to select the biome without having to use the village generation system.
Of course it's totally up to you I'd just advise that you go with a simpler method, just because simple can be better, but then again, that's just me
I believe this will work now. Im lazy (im sure that will come around and bite me in the ass in the future) so i didnt really change much with my code. I've just guaranteed that the structure spawned while this was set on true (which im assuming lets it spawn in any biome) so now ive set it to false (I think this will either stop the structure from spawning or only allow it to spawn in the mountains).
What is this line doing?
I'll tell you -- it's doing nothing. You need to set the result of a function to some variable if you want to use it.
The rest of your code seems unnecessarily complicated. I'm guessing you copied it from vanilla? This line:
Could probably be replaced with return true; or even return this.rand.nextBoolean();
turns out that it spawns in almost any biome. not just mountains...
I'm not surprised given your willy-nilly use of the bit-shift operators >> and <<. I assume you just copied that code from vanilla somewhere?
I suggest you look up what those operators do, and also compare your #canSpawnStructureAtCoords implementation with an actual vanilla implementation such as from MapGenVillage.Start.
@sky_01 Actually, rand.nextInt() DOES do something, even without assigning the result to anything - it progresses the RNG to the next value, so the value that would have been returned is now skipped. E.g. if the RNG would have produced the sequence (12, 8, 918, 25, ...), now when you ask for an int you will get 8 instead of 12, because 12 was already 'spent'. I doubt the OP was intentionally using it that way, of course, so your point remains
>> and << are like a proximity. I think its saying that the structure can spawn within 4 chunks of the biome, But it doesnt have to actually be with in the biome to spawn. or atleast thats my guess.
That is completely 100% incorrect. Please learn about bit shifting operators. That link is just a starting point - I suggest you take some time reading other articles and actually playing around with the operators, printing the results to the console, in order to learn how they work.
Alright, I'll start learning about it. Although one question, is there any sort of world gen class creator program? like you build a structure and then you export the structure as a class file?
Like Schematics? That's a mod / project of some sort that many people have used to do just that, but I'm not sure if it is still being maintained. Also, the code it outputs is terrible... you're much better off using #fillWithBlocks-like methods, in my opinion, than having a 'class' that contains nothing but 10,000+ lines of #setBlock. In the end, the result is the same, but it's sooo ugly... not to mention you can exceed file size limits with sufficiently large structures.
I'd like to do fillwithblocks but i dont understand structure generation enough yet to properly implement it. ive done the setblock so far.
If you don't want to do fillwithblocks, you could also use for loops to much the same effect.
for (z = 1, z < 5, z++)
{
for (x = 1, x < 5, x++)
{
//Do stuff (setblock, etc.)
}
}
You might want to double check this to make sure it's the right syntax because my brain is really dead and I'm likely to have put some stupid little mistake in there by accident, but this is the gist of it. If you want a y coordinate, you could always add a third for loop with the y coordinate.
There's nothing really to understand - #fillWithBlocks is just a method that calls #setBlock for you using for loops, so that you can create an arbitrarily large cube of the same block using like 10 lines of code (actually 1 line, because you don't have to repeat the method every time). Judicious use of such methods in combination with #setBlock for individual components is what creates a structure.
Take a look at some of the actual StructureComponent implementations - you don't need to get anywhere near that fancy / complicated to make it work, but you can see how they use various methods to drastically reduce the amount of code required to produce complex structures with any facing.
If your structure is not so big / complicated and you don't care about being able to rotate it, then individual #setBlock statements is fine.