Posted March 17, 20178 yr I need a more efficient way to do something like this: In a forest the ticks per second going down to ca. 6. @SubscribeEvent public void world_tick(WorldTickEvent event) { if(!event.world.isRemote) { WorldServer world = (WorldServer) event.world; if(!world.equals(DimensionManager.getWorld(SolarApocalypse.dimID))) return; int ticks = world.getGameRules().getInt("randomTickSpeed"); int day = WorldProviderSolar.getDataFor(world).day; Chunk[] array = world.getChunkProvider().getLoadedChunks().toArray(new Chunk[world.getChunkProvider().getLoadedChunkCount()]); if(array.length>1) for(int i=0; i < ticks; i++) { Chunk chunk = array[rand.nextInt(array.length)]; for (ExtendedBlockStorage extendedblockstorage : chunk.getBlockStorageArray()) { if(extendedblockstorage != Chunk.NULL_BLOCK_STORAGE && extendedblockstorage.getNeedsRandomTick()) { for (int c = 0; c< ticks; c++) { int x = rand.nextInt(16) + chunk.xPosition*16; int z = rand.nextInt(16) + chunk.zPosition*16; BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)); this.change_block(world, pos, day, true); } } } } } } /* * changes block beneath the BlockPos */ private void change_block(WorldServer world, BlockPos up, int day, boolean surface) { boolean needs_clean_up = false; BlockPos down = up.down(); Block block = world.getBlockState(down).getBlock(); if(block.equals(Blocks.GRASS) || block.equals(Blocks.GRASS_PATH) || block.equals(Blocks.MYCELIUM) || block.equals(Blocks.DIRT)) { world.setBlockState(down, Blocks.DIRT.getStateFromMeta(1), 2); needs_clean_up = true; } else if(surface && block.isFlammable(world, down, EnumFacing.UP) && !world.getBlockState(up).getBlock().equals(Blocks.FIRE)) { world.setBlockState(down, Blocks.FIRE.getDefaultState(), 2); } else if(block.equals(Blocks.DIRT)) { world.setBlockState(down, Blocks.GRAVEL.getDefaultState(), 2); needs_clean_up = true; } else if(block.equals(Blocks.GRAVEL)) { world.setBlockState(down, Blocks.SAND.getDefaultState(), 2); } else if(block.equals(Blocks.SAND)) { needs_clean_up = true; this.change_block(world, down, day, false); } if(surface && needs_clean_up) { world.setBlockState(up, Blocks.AIR.getDefaultState(), 2); } } Edited March 17, 20178 yr by TheDav1311
March 17, 20178 yr Author I didn't find a method to get the ID out of a world Yeah, that was dump That the world dies slowly
March 17, 20178 yr Author Thank you, that solves the problem. And the extended block storage comes from the original code (Random Block Updates in the WorldServer.class), and I didn't remove them..... Edited March 17, 20178 yr by TheDav1311
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.