Jump to content

quonk

Members
  • Posts

    2
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

quonk's Achievements

Tree Puncher

Tree Puncher (2/8)

2

Reputation

  1. 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); } }
  2. 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.
×
×
  • Create New...

Important Information

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