Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

quonk

Members
  • Joined

  • Last visited

  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.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.