Jump to content

Recommended Posts

Posted

Problem 1 [solved]

 

  Reveal hidden contents

 

 

Problem 2: New problem...I have this coding for my mob spawners

TileEntityMobSpawner ttsnimspawner = (TileEntityMobSpawner)world.getTileEntity(i + 6, j + 11, k + 6);
	ttsnimspawner.func_145881_a().setEntityName("Skeleton");

 

When a second structure spawns in, it seems to error on this code. It works fine when there's one structure, but I flew to a second structure and it errored and crashed. I don't understand why... Also, how would I go about adding loot to the chests I have in my dungeon?

Posted

O...kay...I'm not sure where to even begin with checking for that...Sounds like a great idea, though. Could you link me to a tutorial or explain how to do so? I've tried looking for one, but can't find any.

Posted

Three things:

-You are looking for stained_hardened_clay, i think.

-When generating custom biome specific things, do it in the biome decorating method.

-You don't need to create a new world generator in each iteration of a for loop.

Posted

If I'm interpreting this correctly, couldn't you just reduce its spawn rate by only making it generate X amount of the time? For example, if you wanted it to generate a quarter as much then you could generate a random number between one and four and only have it generate if the number is four? Alternatively, you could make the structure generate a specific block in the dead center of it, and each generation make sure there isn't one of those blocks within X blocks of the new generation (via 3 stacked for loops)

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Posted

Unfortunately, that's what I tried to do. The random number generates a random number between 0.0 and 1.0. It's set to 0.9 (10% of the time, it's about as low as I can set it). It runs about 32 times per chunk, though...it's almost guaranteed to be set at least once. As for checking for coordinates and such, I don't have the slightest idea how to do that. What I would like to do is make it spawn every 300 blocks (like - 0, 300, 600, 900) then run some random code to then tell it "Okay, at these coordinates run a random number to determine which structure to generate there". I have no idea how to do that, though. I've tried some things, but nothing has worked, so I'm not sure what to do.

Posted

Is this beyond what someone is willing to help with? Cause I really can't find any information on doing this...Again, I'd like to do a sort of "Twilight Forest" thing where the structures spawn in specific locations. Like, maybe every 300 blocks or so (so on like 0,0, then 0,300, and 0,-300, and 300,0, etc.)

Posted

You can check if one number (here: current position) is a multiple of another number (here: your desired spacing of 300 blocks) with the modulo operator. Since the coordinates you pass to generateSurface() are already multiplied by 16 this will only work for spacings that are multiples of 16. E.g.:

private void generateSurface(World world, Random random, int x, int z)
  if ((x % 320 == 0) && (z % 320 ==0)) {
    // set chunkX etc.
    new Castle.generate(world, random, chunkX, chunkY, chunkZ);
  }
}

 

 

If you want it to work for spacings that are not a multiple of 16 then checking whether the current chunk contains a desired position becomes a bit more complicated, and to have it work correctly for coordinates <=0 you either need to handle that case extra or use a division that "rounds down".  The code below uses the latter.

 

So, for e.g. x=0, 200, 400, 600, ... and z=0, 100, 200, 300, ...:

 

/**
* 
* @param n
* @param d
* @return n/d rounded towards -infinity
*/
private static int floordiv(int n, int d) {
return n/d - ( ( n % d != 0 ) && ( (n<0) ^ (d<0) ) ? 1 : 0 );
}

private boolean chunkContainsASpawnPosition(int x, int spacing) {
final int chunksize = 16;
int lowerEdge = floordiv(x-1, spacing);     // without the -1 we'd miss cases where x is a multiple of spacing
int upperEdge = floordiv(x+chunksize -1, spacing);
return upperEdge - lowerEdge == 1;
}

private void generateSurface(World world, Random random, int x, int z)
  if (chunkContainsASpawnPosition(x, 200) && chunkContainsASpawnPosition(z, 100)) {
    // set chunkX etc.
    new Castle.generate(world, random, chunkX, chunkY, chunkZ);
  }
}

 

 

The spawning positions aren't exact multiples of the "spacing" variable but rather the position of the chunk which contains the desired position, i.e. here: z=96, 192, 288, 400, 496, ...

But since you are adding in some random offsets anyway I hope that's ok.

 

Posted

Wow! Thanks a lot! This helps a ton!

 

EDIT: New problem...I have this coding for my mob spawners

TileEntityMobSpawner ttsnimspawner = (TileEntityMobSpawner)world.getTileEntity(i + 6, j + 11, k + 6);
	ttsnimspawner.func_145881_a().setEntityName("Skeleton");

 

When a second structure spawns in, it seems to error on this code. It works fine when there's one structure, but I flew to a second structure and it errored and crashed. I don't understand why... Also, how would I go about adding loot to the chests I have in my dungeon?

Posted

I don't know about the spawners; your code (preceded by "world.setBlock(..., Blocks.mob_spawner)) worked for me.

Maybe you could check whether getTileEntity() returns null, and if so use world.getBlock to see what's in that location.

 

 

For chests:

        world.setBlock(i, j, k, Blocks.chest);
        TileEntityChest chest = (TileEntityChest) world.getTileEntity(i, j, k);
        if (chest == null) {
                System.err.printf("TileEntityChest is null!?!\n");
        } else {
                for (int idx = 0; idx < 4; idx++) {
                        ItemStack stack = new ItemStack(Items.diamond_axe);
                        stack.addEnchantment(Enchantment.efficiency, idx+1);
                        stack.addEnchantment(Enchantment.unbreaking, 10);
                        chest.setInventorySlotContents(idx, stack);
                }
        }

 

 

Posted

Yeap...turns out a jungle biome spawned inside of my structure...so a leaf block replaced the spawner...is there any way to prevent that from happening? I mean, it works now and stuff, but I'd like my dungeons to not be destroyed by the biomes around them.

Posted

The only way of doing this is subscribing to the PopulateChunkEvent.Post event and do your dungeon generation there.

Here's an example:

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffplus/world/EnderStuffWorldGenerator.java#L27-L38

 

Also please note that if you think it is registered with the TERRAIN_GEN_BUS, it isn't, it is with the EVENT_BUS!

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I'm a little confused...so I would need to run my world generation using EVENT_BUS instead if I added that into it? I can see your generation there is doing both the PopulateChunkEvent and the world generation, so that's why it confused me. Cause right now my world generator is just:

GameRegistry.registerWorldGenerator(new CraftyGirlsWorldGeneration(), 1);

Would that mean I have to make it this instead?

MinecraftForge.EVENT_BUS.register(new CraftyGirlsWorldGeneration());

Posted

You can use a higher number in your registerWorldGenerator so your structures generate after trees and such. I think that might help, but only if you destroy foliage and trees that are in your way.

Posted
  On 5/1/2014 at 8:25 PM, SureenInk said:

I'm a little confused...so I would need to run my world generation using EVENT_BUS instead if I added that into it? I can see your generation there is doing both the PopulateChunkEvent and the world generation, so that's why it confused me. Cause right now my world generator is just:

GameRegistry.registerWorldGenerator(new CraftyGirlsWorldGeneration(), 1);

Would that mean I have to make it this instead?

MinecraftForge.EVENT_BUS.register(new CraftyGirlsWorldGeneration());

 

Keep the EVENT_BUS if you are doing a worldgen.

Developer of MechanicalCraft.

 

Sadly not available to public yet :(

Posted
  On 5/1/2014 at 8:25 PM, SureenInk said:

I'm a little confused...so I would need to run my world generation using EVENT_BUS instead if I added that into it? I can see your generation there is doing both the PopulateChunkEvent and the world generation, so that's why it confused me. Cause right now my world generator is just:

GameRegistry.registerWorldGenerator(new CraftyGirlsWorldGeneration(), 1);

Would that mean I have to make it this instead?

MinecraftForge.EVENT_BUS.register(new CraftyGirlsWorldGeneration());

 

You actually do both, if you use the IWorldGenerator and the PopulateChunkEvent.

 

You could also try sequituri's suggestion. Seems easier (if it works) than fiddling with events.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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



×
×
  • Create New...

Important Information

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